Thanks to visit codestin.com
Credit goes to github.com

Skip to content

metatxn/Knoww

Repository files navigation

Knoww

A Next.js prediction markets platform to Know your Odds, powered by Polymarket.

🎯 Features

  • βœ… Wallet Connection - Reown AppKit with multi-wallet support (MetaMask, WalletConnect, etc.)
  • βœ… Real-time Market Data - Live prediction markets from Polymarket Gamma API
  • βœ… Dynamic Home Page - Trending, Breaking, and New events with instant switching
  • βœ… Category Browse - Explore by Politics, Sports, Finance, Crypto, and more
  • βœ… Event Details - View grouped markets with volume and liquidity stats
  • βœ… Market Trading - Individual market pages with price charts
  • βœ… Responsive Design - Beautiful UI with Shadcn components and Framer Motion
  • βœ… Type Safe - Full TypeScript support with Zod validation
  • βœ… Optimized Performance - TanStack Query caching and parallel data fetching
  • βœ… Cloudflare Workers - Edge deployment for global performance

πŸš€ Quick Start

Prerequisites

1. Install Dependencies

pnpm install

2. Configure Environment Variables

Create a .env.local file:

# Reown AppKit
NEXT_PUBLIC_REOWN_PROJECT_ID=your_project_id_here

# Optional: Polymarket Builder API (for order attribution - future feature)
# POLY_BUILDER_API_KEY=your_builder_api_key
# POLY_BUILDER_SECRET=your_builder_secret
# POLY_BUILDER_PASSPHRASE=your_builder_passphrase

Get your Reown Project ID:

  1. Go to https://cloud.reown.com/
  2. Create a new project
  3. Copy your Project ID

3. Run Development Server

pnpm dev

Open http://localhost:8000 in your browser.

4. Build for Production

pnpm build

πŸ“± User Flow

Home Page (Default: Trending)

  1. User lands on home page
  2. Sees Trending events by default (highest volume markets)
  3. Can switch to Breaking (last 7 days) or New (today's events)
  4. Can browse All Categories (Politics, Sports, Finance, etc.)

Browse by Category

  1. Click a category from navbar or home page
  2. View all markets in that category (e.g., Sports)
  3. Markets fetched using tag-based filtering

View Event Detail

  1. Click any event card
  2. See event details, stats, and all related markets
  3. Click a market to view trading interface

Market Detail

  1. View market question and description
  2. See price chart with historical data
  3. View outcome prices and volume
  4. Trading interface (coming soon)

πŸ—οΈ Architecture

Frontend Stack

  • Next.js 15 - App Router with React Server Components
  • Reown AppKit - Wallet connection and authentication
  • Wagmi - React hooks for Ethereum
  • Viem - Low-level Ethereum interface
  • TanStack Query - Data fetching, caching, and state management
  • Shadcn UI - Beautiful, accessible components
  • Framer Motion - Smooth animations and transitions
  • Tailwind CSS v4 - Utility-first styling
  • BiomeJS - Fast linter and formatter

Data Flow

User β†’ Reown AppKit β†’ Wagmi β†’ Knoww API Routes β†’ Polymarket Gamma API

Key APIs

  1. Trending Events - /api/events/trending

    • Fetches high-volume events
    • Sorted by volume descending
  2. New Events - /api/events/new

    • Fetches events created today
    • Dynamic date calculation
  3. Breaking Events - /api/events/breaking

    • Fetches recent high-volume events (last 7 days)
    • Ideal for breaking news markets
  4. Category Markets - /api/markets/by-tag

    • 2-step process: Slug β†’ Tag ID β†’ Markets
    • Efficient filtering by category
  5. Event Detail - /api/events/[id]

    • Full event data with all markets
  6. Market Detail - /api/markets/[id]

    • Individual market trading data

πŸ“‚ Project Structure

knoww/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/              # Next.js API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ events/       # Event endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ markets/      # Market endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ tags/         # Category endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ orders/       # Order management (future)
β”‚   β”‚   β”‚   └── wallet/       # Wallet queries (future)
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ events/
β”‚   β”‚   β”‚   β”œβ”€β”€ [tag]/        # Category page
β”‚   β”‚   β”‚   └── detail/[id]/  # Event detail
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ markets/[slug]/   # Market detail
β”‚   β”‚   β”œβ”€β”€ page.tsx          # Home page
β”‚   β”‚   └── layout.tsx        # Root layout
β”‚   β”‚
β”‚   β”œβ”€β”€ hooks/                # TanStack Query hooks
β”‚   β”‚   β”œβ”€β”€ use-trending-events.ts
β”‚   β”‚   β”œβ”€β”€ use-new-events.ts
β”‚   β”‚   β”œβ”€β”€ use-breaking-events.ts
β”‚   β”‚   β”œβ”€β”€ use-tags.ts
β”‚   β”‚   β”œβ”€β”€ use-tag-details.ts
β”‚   β”‚   β”œβ”€β”€ use-markets-by-tag.ts
β”‚   β”‚   β”œβ”€β”€ use-event-detail.ts
β”‚   β”‚   β”œβ”€β”€ use-market-by-id.ts
β”‚   β”‚   └── use-market-detail.ts
β”‚   β”‚
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ navbar.tsx        # Main navigation
β”‚   β”‚   β”œβ”€β”€ market-price-chart.tsx
β”‚   β”‚   └── ui/               # Shadcn components
β”‚   β”‚
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ constants.ts      # API endpoints
β”‚   β”‚   └── polymarket.ts     # Utilities
β”‚   β”‚
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── index.tsx         # Reown AppKit config
β”‚   β”‚
β”‚   └── context/
β”‚       └── index.tsx         # Providers (AppKit, TanStack Query)
β”‚
β”œβ”€β”€ public/
β”œβ”€β”€ FLOW_DIAGRAM.md           # Visual architecture guide
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ package.json
β”œβ”€β”€ next.config.ts            # Next.js config (Turbopack dev, Webpack prod)
β”œβ”€β”€ tsconfig.json
└── biome.json                # Linter config

🎨 UI/UX Features

Home Page

  • Dynamic Views: Trending (default), Breaking, New, All Categories
  • Instant Switching: Pre-fetched data for zero-delay transitions
  • Event Cards: Images, volume, market count, hover animations
  • Responsive Grid: 1-3 columns based on screen size

Navigation

  • Navbar: Category links, wallet connection, account dropdown
  • Smart Back Buttons: Use browser history (router.back())
  • Breadcrumbs: Clear navigation hierarchy

Loading States

  • Skeleton Loaders: Match actual content layout
  • Staggered Animations: Cards fade in with 50ms delays
  • Progress Indicators: Loading spinners for async operations

Animations

  • Framer Motion: Smooth page transitions
  • Hover Effects: Cards lift and scale on hover
  • Fade Ins: Content appears with opacity transitions

πŸ” Security & Privacy

Non-Custodial

  • No Private Keys - Users control their own wallets
  • Client-Side Signing - All transactions signed in browser
  • Reown AppKit - Secure wallet connection protocol

Environment Variables

  • NEXT_PUBLIC_* - Exposed to browser (safe for client-side)
  • Server-only vars - Never exposed to client

πŸš€ Deployment

Cloudflare Workers

  1. Install Wrangler CLI
pnpm install -g wrangler
  1. Login to Cloudflare
wrangler login
  1. Configure wrangler.toml
name = "knoww"
compatibility_date = "2024-01-01"
pages_build_output_dir = ".vercel/output/static"

[env.production]
vars = { ENVIRONMENT = "production" }
  1. Deploy
pnpm run deploy

Environment Variables in Production

Set in Cloudflare Workers dashboard:

  • NEXT_PUBLIC_REOWN_PROJECT_ID
  • POLY_BUILDER_API_KEY (optional, for future trading)
  • POLY_BUILDER_SECRET (optional)
  • POLY_BUILDER_PASSPHRASE (optional)

πŸ“Š Performance Optimizations

  1. Parallel Data Fetching - All event types load simultaneously
  2. TanStack Query Caching - 1-minute stale time, prevents redundant calls
  3. Direct ID Fetching - Market pages use IDs for 1 API call vs 2
  4. Server-Side Caching - 60-second cache on API routes
  5. Code Splitting - Automatic by Next.js App Router
  6. Edge Deployment - Cloudflare Workers for global performance

πŸ› οΈ Development

Available Scripts

pnpm dev          # Start dev server (Turbopack)
pnpm build        # Build for production
pnpm start        # Start production server
pnpm lint         # Run BiomeJS linter
pnpm format       # Format code with BiomeJS
pnpm type-check   # Check TypeScript types

Code Style

  • BiomeJS - Fast linter and formatter
  • TypeScript - Strict mode enabled
  • Tailwind CSS - Utility-first styling
  • Component Structure - Server components by default, client only when needed

Adding New Components

# Add Shadcn component
pnpm dlx shadcn@latest add button

πŸ“š Documentation

πŸ”„ Data Hierarchy

Tags (Categories)
    ↓
Events (Grouped Questions)
    ↓
Markets (Individual Tradeable Questions)

Example:

Tag: "Sports" (slug: sports, id: 1)
    ↓
Event: "Super Bowl Champion 2026" (id: 23656)
    ↓
Market: "Will the Buffalo Bills win Super Bowl 2026?" (id: 540208)

🎯 Roadmap

Current Features

  • βœ… Wallet connection via Reown AppKit
  • βœ… Browse markets by category
  • βœ… View event details
  • βœ… View market details with charts
  • βœ… Trending, Breaking, New event feeds

Coming Soon

  • πŸ”„ Trading Interface - Buy/Sell orders with wallet integration
  • πŸ”„ Order Management - View and cancel open orders
  • πŸ”„ Portfolio View - Track positions and P&L
  • πŸ”„ Real-time Updates - WebSocket integration
  • πŸ”„ Search & Filters - Find specific markets
  • πŸ”„ Notifications - Market alerts and updates

🀝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run pnpm lint and fix any errors
  5. Submit a pull request

πŸ“„ License

MIT

πŸ™ Acknowledgments


Built with ❀️ by the Soclly team

About

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published