# pm3949/hectoclash architecture

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

- Interactive diagram: https://gitdiagram.com/pm3949/hectoclash
- Repository: https://github.com/pm3949/hectoclash

## Overview

##### Project type and purpose
- From the file tree and minimal README, we see this is a full-stack, real-time coding/competition platform named “HectoClash.”
- The frontend is a React single-page application (SPA) that provides user signup/login, problem solving (single/multiplayer & training), a live match spectator mode, leaderboards, and user profiles.
- The backend is a Node.js/Express server exposing RESTful endpoints for users, matches, and training, plus a WebSocket interface for real-time match communication and spectator updates. It persists data in a database (configured in backend/config/database.js) and uses MVC organization (models, controllers, routes).

##### File structure
- Top-level folders:
- backend/ – Express API, REST routes, authentication middleware, socket server, database config, utility modules (problem generator & solver).
- frontend/ – React SPA scaffolded by Create React App, organized into Pages, components, Redux slices, custom hooks, context for socket, and Tailwind config.
- Key patterns:
- Backend follows an MVC-ish pattern: models/ (schema definitions), controllers/ (business logic), routes/ (HTTP endpoints), plus socket.
- Frontend uses Redux for global state (user, matches, opponents), React Context for socket connection, and React Router pages.
- Deployment/config:
- .env in backend for secret keys/DB URL, package.json scripts for both front and back.

##### README for additional insights
- No explicit architecture section present. We’ll infer from code and directory names.

##### Elements
– Backend layers in another (e.g., green)
- Authentication flow: show JWT issued by backend, stored in frontend, sent on API calls, guarded by isAuthenticated middleware.

##### Detailed breakdown
- Frontend Side:
[Browser]
→ [React Router / Pages]
→ [Redux Store] ←→ [Components]
→ [Socket Context]
- Backend Side:
[Express API]
→ [Routes] → [Controllers] → [Models] → [Database]
↘︎ [Utils (generateProblem, solver)]
- Real-Time:
[Client Socket Context] ↔ [backend/socket/socket.js] ↔ [Controllers/Models]
- Data Persistence:
[Models] → [Config/Database] → [Database]

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        Browser["Browser"]:::frontend
        App["React SPA"]:::frontend
        subgraph "Pages (React Router)" 
            direction TB
            Home["Home Page"]:::frontend
            SignIn["Login Page"]:::frontend
            SignUp["Signup Page"]:::frontend
            Compete["Compete Pages"]:::frontend
            Spectator["Spectator Mode"]:::frontend
            Leaderboard["Leaderboard"]:::frontend
            Profile["Profile"]:::frontend
        end
        subgraph "State Management (Redux)" 
            direction TB
            Store["Redux Store"]:::frontend
            UserSlice["User Slice"]:::frontend
            MatchSlice["Match Slice"]:::frontend
            OpponentSlice["Opponent Slice"]:::frontend
        end
        subgraph "Socket & HTTP Clients" 
            direction TB
            SocketContext["Socket Context"]:::frontend
            SocketClient["WebSocket Client"]:::frontend
            MatchHook["Match Data Hook"]:::frontend
        end
        Tailwind["Tailwind Config"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Node.js/Express)" 
        direction TB
        Server["Express Server"]:::backend
        AuthMiddleware["Auth Middleware"]:::backend
        subgraph "API Routes" 
            direction TB
            UserRoutes["User Routes"]:::backend
            MatchRoutes["Match Routes"]:::backend
            TrainingRoutes["Training Routes"]:::backend
        end
        subgraph "Controllers" 
            direction TB
            UserCtrl["User Controllers"]:::backend
            MatchCtrl["Match Controllers"]:::backend
            TrainingCtrl["Training Controllers"]:::backend
        end
        subgraph "Models" 
            direction TB
            UserModel["User Model"]:::backend
            MatchModel["Match Model"]:::backend
            TrainingModel["Training Model"]:::backend
        end
        subgraph "Socket Server" 
            direction TB
            SocketServer["WebSocket Server"]:::backend
        end
        subgraph "Database" 
            direction TB
            DBConfig["DB Config"]:::backend
            Database[(Database)]:::db
        end
        subgraph "Utilities" 
            direction TB
            Generator["Problem Generator"]:::util
            Solver["Solution Solver"]:::util
        end
    end

    %% Connections Frontend to Backend
    Browser -->|load SPA| App
    App -->|uses Pages| Home
    App --> SignIn
    App --> SignUp
    App --> Compete
    App --> Spectator
    App --> Leaderboard
    App --> Profile
    App --> Store
    Store --> UserSlice
    Store --> MatchSlice
    Store --> OpponentSlice
    App --> SocketContext
    App --> SocketClient
    App --> MatchHook
    App --> Tailwind

    %% REST Flow
    App -->|HTTP REST| Server
    Server --> UserRoutes
    Server --> MatchRoutes
    Server --> TrainingRoutes
    UserRoutes --> AuthMiddleware
    UserRoutes --> UserCtrl
    MatchRoutes --> AuthMiddleware
    MatchRoutes --> MatchCtrl
    TrainingRoutes --> AuthMiddleware
    TrainingRoutes --> TrainingCtrl
    UserCtrl --> UserModel
    MatchCtrl --> MatchModel
    TrainingCtrl --> TrainingModel
    UserCtrl --> Generator
    MatchCtrl --> Solver

    %% WebSocket Flow
    SocketClient ---|WebSocket| SocketServer
    SocketServer --> MatchCtrl
    SocketServer --> UserCtrl

    %% Data Persistence
    UserModel --> DBConfig
    MatchModel --> DBConfig
    TrainingModel --> DBConfig
    DBConfig --> Database

    %% Click Events
    click App "https://github.com/pm3949/hectoclash/blob/main/frontend/src/App.jsx"
    click Browser "https://github.com/pm3949/hectoclash/blob/main/frontend/src/index.js"
    click Home "https://github.com/pm3949/hectoclash/blob/main/frontend/src/Pages/home/Home.jsx"
    click SignIn "https://github.com/pm3949/hectoclash/blob/main/frontend/src/Pages/login/signIn.jsx"
    click SignUp "https://github.com/pm3949/hectoclash/blob/main/frontend/src/Pages/signup/signUp.jsx"
    click Compete "https://github.com/pm3949/hectoclash/tree/main/frontend/src/Pages/compete/"
    click Spectator "https://github.com/pm3949/hectoclash/blob/main/frontend/src/Pages/Spectetor/LiveMatch.jsx"
    click Spectator "https://github.com/pm3949/hectoclash/blob/main/frontend/src/Pages/Spectetor/sepectetormode.jsx"
    click Leaderboard "https://github.com/pm3949/hectoclash/blob/main/frontend/src/Pages/Leaderboard/leaderboard.jsx"
    click Profile "https://github.com/pm3949/hectoclash/blob/main/frontend/src/Pages/Profile/profile.jsx"
    click Store "https://github.com/pm3949/hectoclash/blob/main/frontend/src/redux/store.js"
    click UserSlice "https://github.com/pm3949/hectoclash/blob/main/frontend/src/redux/userSlice.js"
    click MatchSlice "https://github.com/pm3949/hectoclash/blob/main/frontend/src/redux/matchSlice.js"
    click OpponentSlice "https://github.com/pm3949/hectoclash/blob/main/frontend/src/redux/opponenetSlice.js"
    click SocketContext "https://github.com/pm3949/hectoclash/blob/main/frontend/src/context/soxketContext.js"
    click SocketClient "https://github.com/pm3949/hectoclash/blob/main/frontend/src/socket/socket.js"
    click MatchHook "https://github.com/pm3949/hectoclash/blob/main/frontend/src/hooks/getMatch.js"
    click Tailwind "https://github.com/pm3949/hectoclash/blob/main/frontend/tailwind.config.js"
    click Server "https://github.com/pm3949/hectoclash/blob/main/backend/index.js"
    click UserRoutes "https://github.com/pm3949/hectoclash/blob/main/backend/routes/userRoutes.js"
    click MatchRoutes "https://github.com/pm3949/hectoclash/blob/main/backend/routes/matchRoutes.js"
    click TrainingRoutes "https://github.com/pm3949/hectoclash/blob/main/backend/routes/tarinigRoutes.js"
    click UserCtrl "https://github.com/pm3949/hectoclash/blob/main/backend/controllers/userControllers.js"
    click MatchCtrl "https://github.com/pm3949/hectoclash/blob/main/backend/controllers/matchControllers.js"
    click TrainingCtrl "https://github.com/pm3949/hectoclash/blob/main/backend/controllers/trainigControllers.js"
    click UserModel "https://github.com/pm3949/hectoclash/blob/main/backend/models/userModel.js"
    click MatchModel "https://github.com/pm3949/hectoclash/blob/main/backend/models/matchModel.js"
    click TrainingModel "https://github.com/pm3949/hectoclash/blob/main/backend/models/trainigModel.js"
    click AuthMiddleware "https://github.com/pm3949/hectoclash/blob/main/backend/middleware/isAuthenticated.js"
    click SocketServer "https://github.com/pm3949/hectoclash/blob/main/backend/socket/socket.js"
    click DBConfig "https://github.com/pm3949/hectoclash/blob/main/backend/config/database.js"
    click Generator "https://github.com/pm3949/hectoclash/blob/main/backend/utils/generateProblem.js"
    click Solver "https://github.com/pm3949/hectoclash/blob/main/backend/utils/solver.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#1E75FF,color:#000
    classDef backend fill:#DFF7D8,stroke:#1EAD00,color:#000
    classDef db fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef util fill:#F0F0F0,stroke:#A0A0A0,color:#000
```
