# graple254/yoooo architecture

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

- Interactive diagram: https://gitdiagram.com/graple254/yoooo
- Repository: https://github.com/graple254/yoooo

## Overview

#### Purpose and Entry Points
Chichi is a Django-based real-time multiplayer board-game platform with random matchmaking and LiveKit-backed video/audio. HTTP entry points are configured in `chichi/urls.py` and served through WSGI/ASGI adapters in `chichi/wsgi.py` and `chichi/asgi.py`. The Django management entry point is `manage.py`.

#### Application Composition
Two Django apps separate identity from gameplay:
- `authentication/` owns user-facing authentication, terms/policy acceptance, and admin email records through `authentication/models.py`, `authentication/views.py`, and `authentication/urls.py`.
- `core/` owns game/session state, matchmaking-facing views, site state, activity tracking, and real-time connections via `core/views.py`, `core/models/match_session.py`, and `core/models/game_models.py`.

The project-level configuration, installed services, and URL composition live in `chichi/settings.py` and `chichi/urls.py`.

#### Match and Game State
Persistent domain state is modeled in Django ORM migrations and model modules:
- Match/session lifecycle: `core/models/match_session.py`
- Game types and results: `core/models/game_models.py`
- Site availability, beta state, and operational error records: `core/models/site_state.py`

This establishes a boundary between server-authoritative account/session/result data and browser-side game interaction. Administrative management of games, sessions, activity, and site state is organized in `core/admin/game_admin.py`, `core/admin/session_admin.py`, and `core/admin/site_state.py`.

#### Real-Time Interaction Layer
ASGI/WebSocket-oriented behavior is concentrated in `core/routing.py`, `core/consumers.py`, and `core/presence_consumer.py`. Presence tracking is separated into `core/presence.py`, indicating distinct real-time flows for match/game communication versus online-user state.

The expected control flow is: browser loads a Django-rendered page, establishes real-time connections to core consumers, participates in matching/session updates, and synchronizes game interaction with its opponent. Video/audio is delegated to the external LiveKit service rather than implemented by the Django server.

#### Browser Client and Game Implementations
Templates provide the rendered application shell and connection pages in `core/templates/files/base.html`, `core/templates/files/index.html`, and `core/templates/files/connect.html`. Browser JavaScript contains the interactive game rules/UI and match client behavior:
- Match coordination client: `core/static/files/match_client.js`
- Individual games: `core/static/files/games/chess.js`, `core/static/files/games/checkers.js`, `core/static/files/games/connect4.js`
- Presence UI: `core/static/files/presence_widget.js`

This makes the browser a material gameplay runtime, while Django persists and coordinates sessions.

#### Operational Services and Deployment
Production is designed around Django ASGI served by Daphne, with Nginx as the front proxy: `daphne/daphne.service`, `nginx/nginx.conf`, and `scripts/daphne.sh`. Deployment automation is represented by `deploy.sh`, `scripts/start_app.sh`, and `.github/workflows/deploy.yaml`.

The runtime requires Python 3.10+, Django dependencies from `requirements.txt`, and a reachable LiveKit server or LiveKit Cloud credentials. `UserData.sh` and setup scripts indicate instance-level provisioning is part of the deployment model.

#### Supporting Operational Flows
Middleware and context enrichment are centralized in `core/middleware.py` and `core/context_processors.py`. Activity/location tracking and periodic traffic snapshots are represented by `core/models/activity_location_tracking.py` and `core/management/commands/snapshot_traffic.py`. Email delivery is encapsulated in `core/email.py`, with email templates under `core/templates/emails/`.

Main entry points: [`core/views.py`](https://github.com/graple254/yoooo/blob/main/core/views.py) (Gameplay HTTP views), [`core/routing.py`](https://github.com/graple254/yoooo/blob/main/core/routing.py) (WebSocket router), [`chichi/urls.py`](https://github.com/graple254/yoooo/blob/main/chichi/urls.py) (HTTP URL router), [`authentication/views.py`](https://github.com/graple254/yoooo/blob/main/authentication/views.py) (Authentication app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_django["Django application"]
  node_manage["Management entry<br/>Django CLI<br/>[manage.py]"]
  node_settings["Project settings<br/>Django config<br/>[settings.py]"]
  node_urls["HTTP URL router<br/>Django routing<br/>[urls.py]"]
  node_auth["Authentication app<br/>identity module<br/>[views.py]"]
  node_auth_models[("Identity records<br/>Django ORM<br/>[models.py]")]
  node_core_views["Gameplay HTTP views<br/>Django views<br/>[views.py]"]
  node_game_state[("Match and game state<br/>Django ORM<br/>[match_session.py]")]
  node_site_state[("Site operations state<br/>Django ORM<br/>[site_state.py]")]
  node_middleware["Request enrichment<br/>middleware<br/>[middleware.py]"]
  node_activity["Traffic snapshots<br/>management command"]
  node_email["Email delivery<br/>application service<br/>[email.py]"]
end

subgraph group_realtime["Real-time and browser"]
  node_templates["Rendered application shell<br/>Django templates<br/>[base.html]"]
  node_ws_routing["WebSocket router<br/>Channels routing<br/>[routing.py]"]
  node_match_consumers["Match consumers<br/>WebSocket consumers<br/>[consumers.py]"]
  node_presence["Presence service<br/>WebSocket presence<br/>[presence.py]"]
  node_browser{{"Game browser client<br/>JavaScript runtime<br/>[match_client.js]"}}
  node_presence_ui["Presence widget<br/>browser UI<br/>[presence_widget.js]"]
end

subgraph group_operations["Deployment and external services"]
  node_livekit{{"LiveKit<br/>external media service"}}
  node_asgi["ASGI application<br/>Django ASGI<br/>[asgi.py]"]
  node_daphne["Daphne service<br/>ASGI server<br/>[daphne.service]"]
  node_nginx["Nginx proxy<br/>reverse proxy<br/>[nginx.conf]"]
  node_deployment["Deployment automation<br/>CI/CD scripts<br/>[deploy.yaml]"]
end

node_manage -->|"loads"| node_settings
node_settings -->|"configures"| node_urls
node_urls -->|"routes to"| node_auth
node_urls -->|"routes to"| node_core_views
node_middleware -->|"enriches requests"| node_core_views
node_auth -->|"reads and writes"| node_auth_models
node_auth -->|"sends via"| node_email
node_core_views -->|"renders"| node_templates
node_core_views -->|"reads and writes"| node_game_state
node_core_views -->|"checks"| node_site_state
node_templates -->|"loads"| node_browser
node_templates -->|"loads"| node_presence_ui
node_browser -->|"opens WebSockets"| node_ws_routing
node_presence_ui -->|"opens presence socket"| node_ws_routing
node_ws_routing -->|"dispatches match traffic"| node_match_consumers
node_ws_routing -->|"dispatches presence traffic"| node_presence
node_match_consumers -->|"coordinates state"| node_game_state
node_presence -.->|"supplies activity data"| node_activity
node_browser -->|"uses video and audio"| node_livekit
node_nginx -->|"proxies traffic"| node_daphne
node_daphne -->|"serves"| node_asgi
node_asgi -->|"serves HTTP"| node_urls
node_asgi -->|"serves WebSockets"| node_ws_routing
node_deployment -->|"deploys and starts"| node_daphne

click node_manage "https://github.com/graple254/yoooo/blob/main/manage.py"
click node_settings "https://github.com/graple254/yoooo/blob/main/chichi/settings.py"
click node_urls "https://github.com/graple254/yoooo/blob/main/chichi/urls.py"
click node_auth "https://github.com/graple254/yoooo/blob/main/authentication/views.py"
click node_auth_models "https://github.com/graple254/yoooo/blob/main/authentication/models.py"
click node_core_views "https://github.com/graple254/yoooo/blob/main/core/views.py"
click node_game_state "https://github.com/graple254/yoooo/blob/main/core/models/match_session.py"
click node_site_state "https://github.com/graple254/yoooo/blob/main/core/models/site_state.py"
click node_middleware "https://github.com/graple254/yoooo/blob/main/core/middleware.py"
click node_templates "https://github.com/graple254/yoooo/blob/main/core/templates/files/base.html"
click node_ws_routing "https://github.com/graple254/yoooo/blob/main/core/routing.py"
click node_match_consumers "https://github.com/graple254/yoooo/blob/main/core/consumers.py"
click node_presence "https://github.com/graple254/yoooo/blob/main/core/presence.py"
click node_browser "https://github.com/graple254/yoooo/blob/main/core/static/files/match_client.js"
click node_presence_ui "https://github.com/graple254/yoooo/blob/main/core/static/files/presence_widget.js"
click node_asgi "https://github.com/graple254/yoooo/blob/main/chichi/asgi.py"
click node_daphne "https://github.com/graple254/yoooo/blob/main/daphne/daphne.service"
click node_nginx "https://github.com/graple254/yoooo/blob/main/nginx/nginx.conf"
click node_deployment "https://github.com/graple254/yoooo/blob/main/.github/workflows/deploy.yaml"
click node_activity "https://github.com/graple254/yoooo/blob/main/core/management/commands/snapshot_traffic.py"
click node_email "https://github.com/graple254/yoooo/blob/main/core/email.py"

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_manage,node_settings,node_urls,node_auth,node_auth_models,node_core_views,node_game_state,node_site_state,node_middleware,node_activity,node_email toneBlue
class node_templates,node_ws_routing,node_match_consumers,node_presence,node_browser,node_presence_ui toneAmber
class node_livekit,node_asgi,node_daphne,node_nginx,node_deployment toneMint
```

## Components

### Django application

HTTP, identity, and authoritative game state.

- [Management entry](https://github.com/graple254/yoooo/blob/main/manage.py): Django CLI · `manage.py`
- [Project settings](https://github.com/graple254/yoooo/blob/main/chichi/settings.py): Django config · Composes installed services and project configuration. · `chichi/settings.py`
- [HTTP URL router](https://github.com/graple254/yoooo/blob/main/chichi/urls.py): Django routing · Composes project and app HTTP routes. · `chichi/urls.py`
- [Authentication app](https://github.com/graple254/yoooo/blob/main/authentication/views.py): identity module · Owns login flows, policy acceptance, and email records. · `authentication/views.py`
- [Identity records](https://github.com/graple254/yoooo/blob/main/authentication/models.py): Django ORM · `authentication/models.py`
- [Gameplay HTTP views](https://github.com/graple254/yoooo/blob/main/core/views.py): Django views · Serves matchmaking-facing pages and site interactions. · `core/views.py`
- [Match and game state](https://github.com/graple254/yoooo/blob/main/core/models/match_session.py): Django ORM · Server-authoritative sessions, game results, and game types. · `core/models/match_session.py`
- [Site operations state](https://github.com/graple254/yoooo/blob/main/core/models/site_state.py): Django ORM · Tracks availability, beta status, and operational errors. · `core/models/site_state.py`
- [Request enrichment](https://github.com/graple254/yoooo/blob/main/core/middleware.py): middleware · Central middleware and template context enrichment. · `core/middleware.py`
- [Traffic snapshots](https://github.com/graple254/yoooo/blob/main/core/management/commands/snapshot_traffic.py): management command · Captures periodic activity and location traffic state. · `core/management/commands/snapshot_traffic.py`
- [Email delivery](https://github.com/graple254/yoooo/blob/main/core/email.py): application service · `core/email.py`

### Real-time and browser

WebSocket coordination and client-side gameplay.

- [Rendered application shell](https://github.com/graple254/yoooo/blob/main/core/templates/files/base.html): Django templates · `core/templates/files/base.html`
- [WebSocket router](https://github.com/graple254/yoooo/blob/main/core/routing.py): Channels routing · `core/routing.py`
- [Match consumers](https://github.com/graple254/yoooo/blob/main/core/consumers.py): WebSocket consumers · Coordinates matching, session updates, and game interaction. · `core/consumers.py`
- [Presence service](https://github.com/graple254/yoooo/blob/main/core/presence.py): WebSocket presence · Maintains online-user state separately from matches. · `core/presence.py`
- [Game browser client](https://github.com/graple254/yoooo/blob/main/core/static/files/match_client.js): JavaScript runtime · Runs match coordination and client-side game rules/UI. · `core/static/files/match_client.js`
- [Presence widget](https://github.com/graple254/yoooo/blob/main/core/static/files/presence_widget.js): browser UI · `core/static/files/presence_widget.js`

### Deployment and external services

Production serving, automation, and media.

- **LiveKit**: external media service · Provides video and audio outside Django.
- [ASGI application](https://github.com/graple254/yoooo/blob/main/chichi/asgi.py): Django ASGI · Hosts HTTP and WebSocket application traffic. · `chichi/asgi.py`
- [Daphne service](https://github.com/graple254/yoooo/blob/main/daphne/daphne.service): ASGI server · `daphne/daphne.service`
- [Nginx proxy](https://github.com/graple254/yoooo/blob/main/nginx/nginx.conf): reverse proxy · `nginx/nginx.conf`
- [Deployment automation](https://github.com/graple254/yoooo/blob/main/.github/workflows/deploy.yaml): CI/CD scripts · Starts and deploys the production application. · `.github/workflows/deploy.yaml`

## Connections

- Management entry → Project settings: loads
- Project settings → HTTP URL router: configures
- HTTP URL router → Authentication app: routes to
- HTTP URL router → Gameplay HTTP views: routes to
- Request enrichment → Gameplay HTTP views: enriches requests
- Authentication app → Identity records: reads and writes
- Authentication app → Email delivery: sends via
- Gameplay HTTP views → Rendered application shell: renders
- Gameplay HTTP views → Match and game state: reads and writes
- Gameplay HTTP views → Site operations state: checks
- Rendered application shell → Game browser client: loads
- Rendered application shell → Presence widget: loads
- Game browser client → WebSocket router: opens WebSockets
- Presence widget → WebSocket router: opens presence socket
- WebSocket router → Match consumers: dispatches match traffic
- WebSocket router → Presence service: dispatches presence traffic
- Match consumers → Match and game state: coordinates state
- Presence service → Traffic snapshots: supplies activity data
- Game browser client → LiveKit: uses video and audio
- Nginx proxy → Daphne service: proxies traffic
- Daphne service → ASGI application: serves
- ASGI application → HTTP URL router: serves HTTP
- ASGI application → WebSocket router: serves WebSockets
- Deployment automation → Daphne service: deploys and starts
