# egamijun/code-world architecture

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

- Interactive diagram: https://gitdiagram.com/egamijun/code-world
- Repository: https://github.com/egamijun/code-world

## Overview

BANG BANG is a browser-based Three.js open-world FPS, with account, profile, and leaderboard services alongside local gameplay and real-time PvP synchronization. A player selects a mode and map in the web client, then enters the Three.js world; authenticated users can also use API-backed accounts and review stats. The README documents the game’s modes, vehicles, weapons, enemy AI, mobile controls, and WebSocket features, but the gameplay implementation is a very large unsampled file, so those internals are represented as one world component. Arrows cite visible calls or documented relationships; the exact real-time wiring is not shown in the excerpts.

Main entry points: [`packages/db/src/client.ts`](https://github.com/egamijun/code-world/blob/main/packages/db/src/client.ts) (Database client), [`apps/api/src/index.ts`](https://github.com/egamijun/code-world/blob/main/apps/api/src/index.ts) (API service), [`apps/api/src/lib/auth.ts`](https://github.com/egamijun/code-world/blob/main/apps/api/src/lib/auth.ts) (Session and password auth), [`apps/api/src/routes/auth.ts`](https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/auth.ts) (Authentication routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Game client"]
  node_webapp["Web app shell<br/>[layout.tsx]"]
  node_worldsetup["Mode and map selection<br/>[WorldClient.tsx]"]
  node_world["FPS world<br/>[ThreeWorld.tsx]"]
  node_login["Login and signup<br/>[page.tsx]"]
  node_signup["Signup page<br/>[page.tsx]"]
  node_profileui["Player profile<br/>[page.tsx]"]
  node_leaderboardui["Leaderboard view<br/>[page.tsx]"]
  node_i18n["Localization<br/>[index.tsx]"]
  node_authclient["Auth client<br/>[auth-client.ts]"]
end

subgraph group_api["Account and services"]
  node_apiapp["API service<br/>[index.ts]"]
  node_authroutes["Authentication routes<br/>[auth.ts]"]
  node_authlib["Session and password auth<br/>[auth.ts]"]
  node_profileroutes["Profile and match stats<br/>[profile.ts]"]
  node_leaderboardroutes["Leaderboard API<br/>[leaderboard.ts]"]
  node_health["Health route<br/>[health.ts]"]
end

subgraph group_data["Persistence"]
  node_dbclient["Database client<br/>[client.ts]"]
  node_users[("Users and matches<br/>[users.ts]")]
  node_sessions[("Sessions<br/>[sessions.ts]")]
end

subgraph group_runtime["Shared and worker runtime"]
  node_types["User validation types<br/>[user.ts]"]
  node_executor["Execution worker<br/>[codeExecution.ts]"]
  node_queue["Execution queue<br/>[index.ts]"]
end

node_player(("Player"))

node_player -->|"opens"| node_webapp
node_webapp -->|"routes to"| node_worldsetup
node_worldsetup -->|"loads"| node_world
node_player -.->|"authenticates"| node_login
node_login -.->|"submits credentials"| node_authclient
node_signup -.->|"submits credentials"| node_authclient
node_authclient -->|"requests auth API"| node_authroutes
node_apiapp -->|"mounts"| node_authroutes
node_apiapp -->|"mounts"| node_profileroutes
node_apiapp -->|"mounts"| node_leaderboardroutes
node_apiapp -->|"mounts"| node_health
node_authroutes -->|"uses auth helpers"| node_authlib
node_authlib -->|"queries"| node_dbclient
node_authroutes -->|"queries users"| node_dbclient
node_profileroutes -->|"reads and writes"| node_dbclient
node_leaderboardroutes -->|"queries rankings"| node_dbclient
node_dbclient -->|"loads schema"| node_users
node_authlib -.->|"stores sessions"| node_sessions
node_authlib -.->|"looks up users"| node_users
node_profileui -.->|"loads profile"| node_profileroutes
node_leaderboardui -.->|"loads rankings"| node_leaderboardroutes
node_webapp -->|"provides translations"| node_i18n
node_worldsetup -->|"uses translations"| node_i18n
node_profileui -->|"logs out"| node_authclient
node_executor -->|"uses queue name"| node_queue

click node_webapp "https://github.com/egamijun/code-world/blob/main/apps/web/src/app/layout.tsx"
click node_worldsetup "https://github.com/egamijun/code-world/blob/main/apps/web/src/app/world/WorldClient.tsx"
click node_world "https://github.com/egamijun/code-world/blob/main/apps/web/src/app/world/ThreeWorld.tsx"
click node_login "https://github.com/egamijun/code-world/blob/main/apps/web/src/app/login/page.tsx"
click node_signup "https://github.com/egamijun/code-world/blob/main/apps/web/src/app/signup/page.tsx"
click node_profileui "https://github.com/egamijun/code-world/blob/main/apps/web/src/app/profile/page.tsx"
click node_leaderboardui "https://github.com/egamijun/code-world/blob/main/apps/web/src/app/leaderboard/page.tsx"
click node_i18n "https://github.com/egamijun/code-world/blob/main/apps/web/src/i18n/index.tsx"
click node_authclient "https://github.com/egamijun/code-world/blob/main/apps/web/src/lib/auth-client.ts"
click node_apiapp "https://github.com/egamijun/code-world/blob/main/apps/api/src/index.ts"
click node_authroutes "https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/auth.ts"
click node_authlib "https://github.com/egamijun/code-world/blob/main/apps/api/src/lib/auth.ts"
click node_profileroutes "https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/profile.ts"
click node_leaderboardroutes "https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/leaderboard.ts"
click node_health "https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/health.ts"
click node_dbclient "https://github.com/egamijun/code-world/blob/main/packages/db/src/client.ts"
click node_users "https://github.com/egamijun/code-world/blob/main/packages/db/src/schema/users.ts"
click node_sessions "https://github.com/egamijun/code-world/blob/main/packages/db/src/schema/sessions.ts"
click node_types "https://github.com/egamijun/code-world/blob/main/packages/types/src/schemas/user.ts"
click node_executor "https://github.com/egamijun/code-world/blob/main/apps/executor/src/workers/codeExecution.ts"
click node_queue "https://github.com/egamijun/code-world/blob/main/apps/executor/src/queues/index.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_webapp,node_worldsetup,node_world,node_login,node_signup,node_profileui,node_leaderboardui,node_i18n,node_authclient toneBlue
class node_apiapp,node_authroutes,node_authlib,node_profileroutes,node_leaderboardroutes,node_health toneAmber
class node_dbclient,node_users,node_sessions toneMint
class node_types,node_executor,node_queue toneRose
class node_player toneIndigo
```

## Components

### Game client

- [Web app shell](https://github.com/egamijun/code-world/blob/main/apps/web/src/app/layout.tsx): `apps/web/src/app/layout.tsx`
- [Mode and map selection](https://github.com/egamijun/code-world/blob/main/apps/web/src/app/world/WorldClient.tsx): `apps/web/src/app/world/WorldClient.tsx`
- [FPS world](https://github.com/egamijun/code-world/blob/main/apps/web/src/app/world/ThreeWorld.tsx): `apps/web/src/app/world/ThreeWorld.tsx`
- [Login and signup](https://github.com/egamijun/code-world/blob/main/apps/web/src/app/login/page.tsx): `apps/web/src/app/login/page.tsx`
- [Signup page](https://github.com/egamijun/code-world/blob/main/apps/web/src/app/signup/page.tsx): `apps/web/src/app/signup/page.tsx`
- [Player profile](https://github.com/egamijun/code-world/blob/main/apps/web/src/app/profile/page.tsx): `apps/web/src/app/profile/page.tsx`
- [Leaderboard view](https://github.com/egamijun/code-world/blob/main/apps/web/src/app/leaderboard/page.tsx): `apps/web/src/app/leaderboard/page.tsx`
- [Localization](https://github.com/egamijun/code-world/blob/main/apps/web/src/i18n/index.tsx): `apps/web/src/i18n/index.tsx`
- [Auth client](https://github.com/egamijun/code-world/blob/main/apps/web/src/lib/auth-client.ts): `apps/web/src/lib/auth-client.ts`

### Account and services

- [API service](https://github.com/egamijun/code-world/blob/main/apps/api/src/index.ts): `apps/api/src/index.ts`
- [Authentication routes](https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/auth.ts): `apps/api/src/routes/auth.ts`
- [Session and password auth](https://github.com/egamijun/code-world/blob/main/apps/api/src/lib/auth.ts): `apps/api/src/lib/auth.ts`
- [Profile and match stats](https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/profile.ts): `apps/api/src/routes/profile.ts`
- [Leaderboard API](https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/leaderboard.ts): `apps/api/src/routes/leaderboard.ts`
- [Health route](https://github.com/egamijun/code-world/blob/main/apps/api/src/routes/health.ts): `apps/api/src/routes/health.ts`

### Persistence

- [Database client](https://github.com/egamijun/code-world/blob/main/packages/db/src/client.ts): `packages/db/src/client.ts`
- [Users and matches](https://github.com/egamijun/code-world/blob/main/packages/db/src/schema/users.ts): `packages/db/src/schema/users.ts`
- [Sessions](https://github.com/egamijun/code-world/blob/main/packages/db/src/schema/sessions.ts): `packages/db/src/schema/sessions.ts`

### Shared and worker runtime

- [User validation types](https://github.com/egamijun/code-world/blob/main/packages/types/src/schemas/user.ts): `packages/types/src/schemas/user.ts`
- [Execution worker](https://github.com/egamijun/code-world/blob/main/apps/executor/src/workers/codeExecution.ts): `apps/executor/src/workers/codeExecution.ts`
- [Execution queue](https://github.com/egamijun/code-world/blob/main/apps/executor/src/queues/index.ts): `apps/executor/src/queues/index.ts`

### Other components

- **Player**

## Connections

- Player → Web app shell: opens (evidence: `README.md`)
- Web app shell → Mode and map selection: routes to
- Mode and map selection → FPS world: loads (evidence: `apps/web/src/app/world/WorldClient.tsx`)
- Player → Login and signup: authenticates
- Login and signup → Auth client: submits credentials (evidence: `apps/web/src/app/login/page.tsx`)
- Signup page → Auth client: submits credentials (evidence: `apps/web/src/app/signup/page.tsx`)
- Auth client → Authentication routes: requests auth API (evidence: `apps/web/src/lib/auth-client.ts`)
- API service → Authentication routes: mounts (evidence: `apps/api/src/index.ts`)
- API service → Profile and match stats: mounts (evidence: `apps/api/src/index.ts`)
- API service → Leaderboard API: mounts (evidence: `apps/api/src/index.ts`)
- API service → Health route: mounts (evidence: `apps/api/src/index.ts`)
- Authentication routes → Session and password auth: uses auth helpers (evidence: `apps/api/src/routes/auth.ts`)
- Session and password auth → Database client: queries (evidence: `apps/api/src/lib/auth.ts`)
- Authentication routes → Database client: queries users (evidence: `apps/api/src/routes/auth.ts`)
- Profile and match stats → Database client: reads and writes (evidence: `apps/api/src/routes/profile.ts`)
- Leaderboard API → Database client: queries rankings (evidence: `apps/api/src/routes/leaderboard.ts`)
- Database client → Users and matches: loads schema (evidence: `packages/db/src/client.ts`)
- Session and password auth → Sessions: stores sessions
- Session and password auth → Users and matches: looks up users
- Player profile → Profile and match stats: loads profile
- Leaderboard view → Leaderboard API: loads rankings
- Web app shell → Localization: provides translations (evidence: `apps/web/src/app/layout.tsx`)
- Mode and map selection → Localization: uses translations (evidence: `apps/web/src/app/world/WorldClient.tsx`)
- Player profile → Auth client: logs out (evidence: `apps/web/src/app/profile/page.tsx`)
- Execution worker → Execution queue: uses queue name (evidence: `apps/executor/src/workers/codeExecution.ts`)
