Architecture
PolyMarks follows a modular, feature-based architecture for scalability and maintainability.
Project Structure
polymarks/
βββ app/ # Next.js App Router pages
β βββ layout.tsx # Root layout
β βββ page.tsx # Homepage (3D landing)
β βββ markets/ # Markets dashboard
β βββ whales/ # Whale tracker
β βββ outliers/ # Smart money signals
β βββ market/[slug]/ # Individual market pages
β βββ api/ # API routes (proxies)
β βββ markets/ # Polymarket markets proxy
β βββ trades/ # Polymarket trades proxy
βββ core/ # Shared utilities
β βββ api/ # API clients
β βββ config/ # Environment config
β βββ types/ # TypeScript types
βββ features/ # Feature modules
β βββ markets/ # Market listing & filtering
β βββ whales/ # Whale tracking
β βββ outliers/ # Smart money detection
β βββ referral/ # Polymarket referral URLs
β βββ market-whale-sentiment/ # Market sentiment
βββ components/ # Shared UI components
βββ hooks/ # Custom React hooksDesign Principles
1. Feature Modules
Each feature is self-contained with:
Types
Business logic
Components
README documentation
Example: features/whales/
whales/
βββ README.md # Feature documentation
βββ components/
β βββ WhaleTradeCard.tsx
β βββ index.ts
βββ lib/ # Business logic (if needed)
βββ index.ts # Public API2. Core Module
Shared utilities used across features:
API clients (Polymarket, Helius)
TypeScript types
Environment configuration
3. API Routes as Proxies
Next.js API routes proxy external APIs to:
Avoid CORS issues
Hide API keys (server-side only)
Add caching/rate limiting
Example: /api/markets β gamma-api.polymarket.com/markets
4. Client vs Server Components
Server Components: Data fetching, initial render
Client Components: Interactivity, real-time updates
Data Flow
User Request
β
Next.js Page (Server Component)
β
API Route (/api/markets)
β
External API (Polymarket)
β
Transform Data (core/api clients)
β
Feature Module (features/markets)
β
UI Component
β
UserState Management
Server State: React Server Components +
fetchwith cachingClient State: React
useState+useEffectReal-Time: Polling with
setInterval
No external state library needed (keeping it simple).
Performance Optimizations
Next.js Caching:
next: { revalidate: 60 }for markets (1 min cache)next: { revalidate: 30 }for trades (30 sec cache)
Incremental Static Regeneration (ISR):
Markets dashboard pre-rendered
Revalidates in background
API Rate Limiting:
Removed market-specific whale fetching from grid
Only fetch on detail pages
Prevents 429/500 errors
Lazy Loading:
Three.js components lazy loaded
Heavy dependencies code-split
Last updated