# sutanu01/codearena architecture

> Architecture diagram of the GitHub repository sutanu01/codearena, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sutanu01/codearena
- Repository: https://github.com/sutanu01/codearena

## Overview

##### Project type and purpose
- Code Arena is a real-time full-stack web application for competitive programming battles.
- Frontend: Next.js (React + TypeScript + Tailwind), state via Redux Toolkit, real-time socket events.
- Backend: Node.js + Express + TypeScript, MongoDB via Mongoose, Socket.IO, scheduled jobs for daily puzzles.
- External integrations: Clerk for auth, Codeforces API for rating sync.

##### File structure
- Top-level: `client/` (Next.js app) and `server/` (Express API + Socket.IO).
- Frontend folders:
- `app/` (Next.js 13 routing & layouts)
- `components/` (UI + custom components)
- `redux/` (store, reducers)
- `hooks/` (data fetching & utilities)
- `socket/` (Socket.IO client wrapper)
- Backend folders:
- `controllers/`, `routes/` (HTTP REST endpoints)
- `models/` (Mongoose schemas)
- `utils/` (DB connection, matchmaking logic, cron jobs)
- `socket.ts` (Socket.IO server integration)
- Config files: `next.config.mjs`, `tailwind.config.ts`, `tsconfig.json`, `.env*`.

##### README for additional insights
- Features: 1v1 rated matches, custom rooms, daily puzzles, leaderboard.
- Tech stack confirms MongoDB, Socket.IO, Clerk, Redux.
- Deployment on Vercel (frontend) and Render (backend).

##### Detail
- Break frontend into “Pages”, “Components”, “Redux Store”, “Socket Client”.
- Break backend into “Express Routes”, “Controllers”, “Socket Server”, “Cron Jobs”, “DB Utils”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser
    Browser["User's Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend (Next.js)" 
        direction TB
        NextFrontend["App Router & Pages"]:::frontend
        UIComp["React UI Components & Theme Provider"]:::frontend
        ReduxStore["Redux Store & State Slices"]:::frontend
        SocketClient["Socket.IO Client Wrapper & Events"]:::frontend
        DataHooks["Data Fetching Hooks & Utilities"]:::frontend
        UtilsLib["Utility Functions & Cache Keys"]:::frontend
        Styles["Tailwind & Global Styles"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express & Socket.IO)"
        direction TB
        AppEntry["Express App Entry Point"]:::backend
        Routes["HTTP API Routes"]:::backend
        Controllers["Express Controllers"]:::backend
        SocketServer["Socket.IO Server Integration"]:::backend
        CronJobs["Cron Job Scheduler for Daily Puzzles"]:::backend
        DBUtil["Database Connection Utility"]:::backend
        Matchmaking["Matchmaking & Room Logic"]:::backend
        UtilsMisc["Miscellaneous Server Utilities"]:::backend
        Models["Mongoose Models (Schemas)"]:::database
        Constants["Server Constants & Event Definitions"]:::backend
        Types["Global Types & TypeScript Definitions"]:::backend
    end

    %% Database
    MongoDB["MongoDB Atlas"]:::database

    %% External Services
    Clerk["Clerk Auth Service"]:::external
    CodeforcesAPI["Codeforces API"]:::external

    %% Connections
    Browser -->|"HTTP/SSR, User Interaction"| NextFrontend
    Browser -->|"WebSocket"| SocketClient

    NextFrontend -->|"uses components"| UIComp
    NextFrontend -->|"dispatched actions"| ReduxStore
    UIComp -->|"+theme"| Styles
    ReduxStore -->|"+hooks"| DataHooks
    DataHooks -->|"+utils"| UtilsLib
    SocketClient -->|"ws events"| AppEntry

    NextFrontend -->|"REST calls"| Routes
    NextFrontend -->|"WebSocket events"| SocketServer

    Routes -->|"controller calls"| Controllers
    Controllers -->|"service logic"| Matchmaking
    Controllers -->|"service logic"| UtilsMisc
    Controllers -->|"DB queries"| DBUtil

    SocketServer -->|"match events"| Matchmaking
    SocketServer -->|"room events"| UtilsMisc
    CronJobs -->|"daily puzzles insert"| DBUtil

    DBUtil -->|"reads/writes"| MongoDB
    Matchmaking -->|"reads/writes"| MongoDB
    UtilsMisc -->|"reads/writes"| MongoDB
    Controllers -->|"reads/writes"| MongoDB

    Controllers -->|"verify token"| Clerk
    Controllers -->|"fetch profile"| CodeforcesAPI

    %% Click Events
    click NextFrontend "https://github.com/sutanu01/codearena/tree/main/client/app"
    click UIComp "https://github.com/sutanu01/codearena/tree/main/client/components"
    click ReduxStore "https://github.com/sutanu01/codearena/tree/main/client/redux"
    click SocketClient "https://github.com/sutanu01/codearena/tree/main/client/socket"
    click DataHooks "https://github.com/sutanu01/codearena/tree/main/client/hooks"
    click UtilsLib "https://github.com/sutanu01/codearena/tree/main/client/lib"
    click Styles "https://github.com/sutanu01/codearena/blob/main/client/tailwind.config.ts"
    click Routes "https://github.com/sutanu01/codearena/tree/main/server/src/routes"
    click Controllers "https://github.com/sutanu01/codearena/tree/main/server/src/controllers"
    click SocketServer "https://github.com/sutanu01/codearena/blob/main/server/src/socket.ts"
    click CronJobs "https://github.com/sutanu01/codearena/blob/main/server/src/utils/cron-jobs.ts"
    click DBUtil "https://github.com/sutanu01/codearena/blob/main/server/src/utils/db.ts"
    click Matchmaking "https://github.com/sutanu01/codearena/blob/main/server/src/utils/matchmaking.ts"
    click UtilsMisc "https://github.com/sutanu01/codearena/blob/main/server/src/utils/utility.ts"
    click Models "https://github.com/sutanu01/codearena/tree/main/server/src/models"
    click Constants "https://github.com/sutanu01/codearena/blob/main/server/src/constants/configs.ts"
    click Types "https://github.com/sutanu01/codearena/tree/main/server/src/types"
    click AppEntry "https://github.com/sutanu01/codearena/blob/main/server/src/index.ts"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064
    classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef database fill:#F3E5F5,stroke:#4A148C,color:#4A148C
    classDef external fill:#FFF3E0,stroke:#E65100,color:#E65100
```
