How adityaxjain/typearena works
Project Type & Purpose
• Full-stack, React/Next.js application with real-time multiplayer features.
• Frontend pages and marketing content live under src/app, while API endpoints live under src/app/api.
• Real-time game interactions use Socket.io (via an Express server) and persistent data is stored via your DB config and models.
Main Components
A. Client (Browser)
– Next.js React app
– Pages: marketing (/about, /contact, etc.), auth (/login,/signup), gameplay (/lobby, /playground, /status), profile/leaderboard
– Socket.io client (for real-time game events)
B. Next.js Server
– Renders pages (SSR/SSG)
– Hosts static assets (public/, CSS, fonts)
– API Routes (src/app/api/*/route.ts): login, signup, logout, profile, leaderboard, store-result
– Utilities in src/lib (token parsing, ratelimit, etc.)
C. Real-Time Engine
– Express + Socket.io server (could be co-hosted or separate)
– Event handling: room creation/join, text dispatch, progress updates, live scoreboard broadcasts
– Uses src/data for sample paragraphs or patterns
D. Database
– Connection & config in src/dbconfig/dbconfig.ts
– Models in src/models (e.g. user.model.ts)
– Stores user credentials, game results
E. State Management (Client-side)
– Zustand or custom store in src/store/useStore.ts
F. Deployment & Hosting
– Vercel for Next.js (frontend + serverless API)
– Separate Node server host (for Socket.io/Express) or integrated in Vercel Edge Functions
– Environment via .env (see .env.example)
Relationships & Data Flows
1. HTTP Requests
– Browser → Next.js API Routes (signup/login/profile) → DB
– Browser → Next.js SSR for initial page load
2. WebSocket (Socket.io)
– Browser ↔ Socket.io Server (join room, realtime typing events, scoreboard)
– Socket.io Server ↔ DB (persist match results via HTTP or direct DB writes)
3. State Updates
– Socket events update client store (useStore.ts), which drives UI components in src/components/*
Architectural Patterns & Principles
• Separation of Concerns:
– UI (React components under src/components) versus logic (API routes, Socket.io handlers) versus data (models + DB).
• Modular Folder Structure:
– /app splits auth, marketing, dynamic pages.
– /components splits custom vs. UI primitives.
• Stateless API + JWT:
– getDataFromToken.ts decodes tokens; API routes are stateless.
• Real-time Microservice:
– Decouple game-loop/socket layer from SSR/API layer for scalability.
• Clear, concise labels (component name + folder reference)
• Brief notes on major libraries/frameworks per component