# softwaredeveloper111/ai-battle-arena architecture

> Architecture diagram of the GitHub repository softwaredeveloper111/ai-battle-arena, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/softwaredeveloper111/ai-battle-arena
- Repository: https://github.com/softwaredeveloper111/ai-battle-arena

## Overview

AI Battle Arena is a web application for account-based AI coding battles: users authenticate, submit a problem, receive competing model solutions and judging, and manage saved battle sessions. The client initializes authentication and routes users to the dashboard; the server exposes auth and battle APIs, while battle execution streams updates over sockets. The tree and excerpts support these main paths, but unsampled client dashboard and server routing details limit some connections; optional or unverified links are marked dashed.

Main entry points: [`server/src/controllers/battle.controller.ts`](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/controllers/battle.controller.ts) (Battle operations), [`server/server.ts`](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/server.ts) (HTTP server entry), [`client/src/features/dashboard/hooks/useBattle.js`](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/hooks/useBattle.js) (Battle workflow), [`client/src/app/App.jsx`](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/app/App.jsx) (App bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["App bootstrap<br/>[App.jsx]"]
  node_router["Route access<br/>[AppRouter.jsx]"]
  node_authpages["Auth pages<br/>[LoginPage.jsx]"]
  node_dashboard["Battle dashboard<br/>[Dashboard.jsx]"]
end

subgraph group_auth["Identity and email"]
  node_authhook["Auth workflow<br/>[useAuth.js]"]
  node_authstate["Auth state<br/>[auth.store.js]"]
  node_authclient["Auth API client<br/>[auth.api.js]"]
  node_authroutes["Auth routes<br/>[auth.route.ts]"]
  node_authcontroller["Auth operations<br/>[auth.controller.ts]"]
  node_users[("User records<br/>[user.model.ts]")]
  node_emailqueue["Email jobs<br/>[email.queue.ts]"]
  node_emailworker["Email worker<br/>[email.worker.ts]"]
  node_emailservice["Email delivery<br/>[email.service.ts]"]
end

subgraph group_battle["Battle workflow"]
  node_battlehook["Battle workflow<br/>[useBattle.js]"]
  node_battleclient["Battle API client<br/>[battle.api.js]"]
  node_battlestore["Battle state<br/>[battle.store.js]"]
  node_socketclient["Socket client<br/>[client.socket.js]"]
  node_battleroutes["Battle routes<br/>[battle.route.ts]"]
  node_battlecontroller["Battle operations"]
  node_battlegraph["AI battle graph<br/>[graph.ai.ts]"]
  node_titlegen["Chat title generation"]
  node_sessions[("Chat sessions")]
  node_messages[("Battle messages")]
  node_socketserver["Socket server<br/>[server.socket.ts]"]
end

subgraph group_server["API runtime"]
  node_server["HTTP server entry<br/>[server.ts]"]
  node_apiapp["Express API<br/>[app.ts]"]
  node_db[("MongoDB connection<br/>[db.ts]")]
  node_cache[("Redis cache<br/>[cache.ts]")]
  node_config["Runtime configuration<br/>[config.ts]"]
end

node_visitor(("Visitor / user"))
node_emailprovider["Resend"]
node_models["AI model providers"]

node_visitor -.->|"opens"| node_app
node_app -->|"initializes auth"| node_authhook
node_app -->|"renders"| node_router
node_router -->|"routes to"| node_authpages
node_router -->|"routes to"| node_dashboard
node_authhook -->|"updates"| node_authstate
node_authhook -->|"requests"| node_authclient
node_dashboard -.->|"uses"| node_battlehook
node_battlehook -->|"updates"| node_battlestore
node_battlehook -->|"requests"| node_battleclient
node_battlehook -->|"uses"| node_socketclient
node_visitor -.->|"sends requests"| node_server
node_server -->|"serves"| node_apiapp
node_server -->|"connects"| node_db
node_server -->|"loads"| node_cache
node_server -->|"initializes"| node_socketserver
node_server -->|"starts"| node_emailworker
node_apiapp -->|"mounts"| node_authroutes
node_apiapp -->|"mounts"| node_battleroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authcontroller -->|"reads and writes"| node_users
node_authcontroller -->|"queues mail"| node_emailqueue
node_emailworker -->|"sends through"| node_emailservice
node_emailservice -->|"delivers via"| node_emailprovider
node_battleroutes -->|"dispatches"| node_battlecontroller
node_battlecontroller -->|"streams solutions"| node_battlegraph
node_battlecontroller -->|"generates title"| node_titlegen
node_battlecontroller -->|"reads and writes"| node_sessions
node_battlecontroller -->|"reads and writes"| node_messages
node_battlecontroller -->|"emits updates"| node_socketserver
node_battlegraph -.->|"uses providers"| node_models
node_emailqueue -.->|"consumes jobs"| node_emailworker
node_authclient -.->|"calls API"| node_authroutes
node_battleclient -.->|"calls API"| node_battleroutes
node_socketclient -.->|"receives streams"| node_socketserver

click node_app "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/app/App.jsx"
click node_router "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/app/router/AppRouter.jsx"
click node_authpages "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/pages/LoginPage.jsx"
click node_dashboard "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/pages/Dashboard.jsx"
click node_authhook "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/hooks/useAuth.js"
click node_authstate "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/store/auth.store.js"
click node_authclient "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/services/auth.api.js"
click node_battlehook "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/hooks/useBattle.js"
click node_battleclient "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/services/battle.api.js"
click node_battlestore "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/store/battle.store.js"
click node_socketclient "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/services/sockets/client.socket.js"
click node_server "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/server.ts"
click node_apiapp "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/app.ts"
click node_authroutes "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/routes/auth.route.ts"
click node_authcontroller "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/controllers/auth.controller.ts"
click node_users "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/models/user.model.ts"
click node_emailqueue "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/queues/email.queue.ts"
click node_emailworker "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/workers/email.worker.ts"
click node_emailservice "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/services/email.service.ts"
click node_battleroutes "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/routes/battle.route.ts"
click node_battlecontroller "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/controllers/battle.controller.ts"
click node_battlegraph "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/ai/battle/graph.ai.ts"
click node_titlegen "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/ai/chatTitleGenerate.ts"
click node_sessions "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/models/chatSession.model.ts"
click node_messages "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/models/battleMessage.model.ts"
click node_socketserver "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/socket/server.socket.ts"
click node_models "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/ai/battle/llmModel.provider.ts"
click node_db "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/config/db.ts"
click node_cache "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/config/cache.ts"
click node_config "https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/config/config.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_router,node_authpages,node_dashboard,node_visitor toneBlue
class node_authhook,node_authstate,node_authclient,node_authroutes,node_authcontroller,node_users,node_emailqueue,node_emailworker,node_emailservice toneAmber
class node_battlehook,node_battleclient,node_battlestore,node_socketclient,node_battleroutes,node_battlecontroller,node_battlegraph,node_titlegen,node_sessions,node_messages,node_socketserver toneMint
class node_server,node_apiapp,node_db,node_cache,node_config toneRose
class node_emailprovider,node_models toneIndigo
```

## Components

### Web client

- [App bootstrap](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/app/App.jsx): `client/src/app/App.jsx`
- [Route access](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/app/router/AppRouter.jsx): `client/src/app/router/AppRouter.jsx`
- [Auth pages](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/pages/LoginPage.jsx): `client/src/features/auth/pages/LoginPage.jsx`
- [Battle dashboard](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/pages/Dashboard.jsx): `client/src/features/dashboard/pages/Dashboard.jsx`

### Identity and email

- [Auth workflow](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/hooks/useAuth.js): `client/src/features/auth/hooks/useAuth.js`
- [Auth state](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/store/auth.store.js): `client/src/features/auth/store/auth.store.js`
- [Auth API client](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/auth/services/auth.api.js): `client/src/features/auth/services/auth.api.js`
- [Auth routes](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/routes/auth.route.ts): `server/src/routes/auth.route.ts`
- [Auth operations](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/controllers/auth.controller.ts): `server/src/controllers/auth.controller.ts`
- [User records](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/models/user.model.ts): `server/src/models/user.model.ts`
- [Email jobs](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/queues/email.queue.ts): `server/src/queues/email.queue.ts`
- [Email worker](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/workers/email.worker.ts): `server/src/workers/email.worker.ts`
- [Email delivery](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/services/email.service.ts): `server/src/services/email.service.ts`

### Battle workflow

- [Battle workflow](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/hooks/useBattle.js): `client/src/features/dashboard/hooks/useBattle.js`
- [Battle API client](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/services/battle.api.js): `client/src/features/dashboard/services/battle.api.js`
- [Battle state](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/features/dashboard/store/battle.store.js): `client/src/features/dashboard/store/battle.store.js`
- [Socket client](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/client/src/services/sockets/client.socket.js): `client/src/services/sockets/client.socket.js`
- [Battle routes](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/routes/battle.route.ts): `server/src/routes/battle.route.ts`
- [Battle operations](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/controllers/battle.controller.ts): `server/src/controllers/battle.controller.ts`
- [AI battle graph](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/ai/battle/graph.ai.ts): `server/src/ai/battle/graph.ai.ts`
- [Chat title generation](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/ai/chatTitleGenerate.ts): `server/src/ai/chatTitleGenerate.ts`
- [Chat sessions](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/models/chatSession.model.ts): `server/src/models/chatSession.model.ts`
- [Battle messages](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/models/battleMessage.model.ts): `server/src/models/battleMessage.model.ts`
- [Socket server](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/socket/server.socket.ts): `server/src/socket/server.socket.ts`

### API runtime

- [HTTP server entry](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/server.ts): `server/server.ts`
- [Express API](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/app.ts): `server/src/app.ts`
- [MongoDB connection](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/config/db.ts): `server/src/config/db.ts`
- [Redis cache](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/config/cache.ts): `server/src/config/cache.ts`
- [Runtime configuration](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/config/config.ts): `server/src/config/config.ts`

### Other components

- **Visitor / user**
- **Resend**
- [AI model providers](https://github.com/softwaredeveloper111/ai-battle-arena/blob/main/server/src/ai/battle/llmModel.provider.ts): `server/src/ai/battle/llmModel.provider.ts`

## Connections

- Visitor / user → App bootstrap: opens
- App bootstrap → Auth workflow: initializes auth (evidence: `client/src/app/App.jsx`)
- App bootstrap → Route access: renders (evidence: `client/src/app/App.jsx`)
- Route access → Auth pages: routes to (evidence: `client/src/app/router/AppRouter.jsx`)
- Route access → Battle dashboard: routes to (evidence: `client/src/app/router/AppRouter.jsx`)
- Auth workflow → Auth state: updates (evidence: `client/src/features/auth/hooks/useAuth.js`)
- Auth workflow → Auth API client: requests (evidence: `client/src/features/auth/hooks/useAuth.js`)
- Battle dashboard → Battle workflow: uses
- Battle workflow → Battle state: updates (evidence: `client/src/features/dashboard/hooks/useBattle.js`)
- Battle workflow → Battle API client: requests (evidence: `client/src/features/dashboard/hooks/useBattle.js`)
- Battle workflow → Socket client: uses (evidence: `client/src/features/dashboard/hooks/useBattle.js`)
- Visitor / user → HTTP server entry: sends requests
- HTTP server entry → Express API: serves (evidence: `server/server.ts`)
- HTTP server entry → MongoDB connection: connects (evidence: `server/server.ts`)
- HTTP server entry → Redis cache: loads (evidence: `server/server.ts`)
- HTTP server entry → Socket server: initializes (evidence: `server/server.ts`)
- HTTP server entry → Email worker: starts (evidence: `server/server.ts`)
- Express API → Auth routes: mounts (evidence: `server/src/app.ts`)
- Express API → Battle routes: mounts (evidence: `server/src/app.ts`)
- Auth routes → Auth operations: dispatches (evidence: `server/src/routes/auth.route.ts`)
- Auth operations → User records: reads and writes (evidence: `server/src/controllers/auth.controller.ts`)
- Auth operations → Email jobs: queues mail (evidence: `server/src/controllers/auth.controller.ts`)
- Email worker → Email delivery: sends through (evidence: `server/src/workers/email.worker.ts`)
- Email delivery → Resend: delivers via (evidence: `server/src/services/email.service.ts`)
- Battle routes → Battle operations: dispatches
- Battle operations → AI battle graph: streams solutions (evidence: `server/src/controllers/battle.controller.ts`)
- Battle operations → Chat title generation: generates title (evidence: `server/src/controllers/battle.controller.ts`)
- Battle operations → Chat sessions: reads and writes (evidence: `server/src/controllers/battle.controller.ts`)
- Battle operations → Battle messages: reads and writes (evidence: `server/src/controllers/battle.controller.ts`)
- Battle operations → Socket server: emits updates (evidence: `server/src/controllers/battle.controller.ts`)
- AI battle graph → AI model providers: uses providers
- Email jobs → Email worker: consumes jobs
- Auth API client → Auth routes: calls API
- Battle API client → Battle routes: calls API
- Socket client → Socket server: receives streams
