# tjcsl/othello-tourney architecture

> Architecture diagram of the GitHub repository tjcsl/othello-tourney, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tjcsl/othello-tourney
- Repository: https://github.com/tjcsl/othello-tourney

## Overview

##### Client-Side Layer
- Web Browser Interface
- Static Assets (CSS/JS/Images)
- WebSocket Connections for Real-time Gaming

##### Web Server Layer
- Django Application Server
- ASGI Server (for WebSocket support)
- URL Routing System

##### Authentication Layer
- Ion OAuth Integration
- Custom User Management System

##### Core Application Components
- Games Module
- Tournaments Module
- Authentication Module
- Error Handling Module

##### Background Processing
- Celery Worker
- Task Queue System
- Tournament Management Tasks
- Game Processing Tasks

##### Security Layer
- Sandboxing System (for running AI submissions)
- Code Validation
- Submission Management

##### Data Storage
- PostgreSQL Database
- Redis (for Celery and Channels)
- File Storage (for submissions)

##### Component Relationships
- How the Games module interfaces with the Moderator
- Tournament management flow
- Demonstrate authentication flow with Ion OAuth
- How Celery workers interact with the main application

##### Game Flow
- Client -> WebSocket -> Game Consumer -> Moderator -> Sandbox -> AI Submission

##### Tournament Flow
- Tournament Manager -> Celery Tasks -> Game Scheduler -> Game Execution -> Results Processing

##### Authentication Flow
- Client -> Django -> Ion OAuth -> User Management

Additional Notes:
- Annotations for critical components
- Scaling points (where the system can be horizontally scaled)
- Monitoring and logging points
- Security boundaries and sandboxed environments

Remember to include version information and any relevant deployment-specific configurations in a separate notes section.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]:::client
        StaticAssets["Static Assets"]:::client
        WebSocket["WebSocket Client"]:::client
    end

    subgraph "Web Server"
        ASGI["ASGI Server"]:::server
        URLRouter["URL Router"]:::server
        WSRouter["WebSocket Router"]:::server
    end

    subgraph "Authentication"
        OAuth["Ion OAuth"]:::auth
        UserMgmt["User Management"]:::auth
        AuthViews["Auth Views"]:::auth
    end

    subgraph "Core Application"
        GameModule["Games Module"]:::core
        TournamentModule["Tournament Module"]:::core
        GameConsumer["Game Consumer"]:::core
        TournamentPairing["Tournament Pairing"]:::core
    end

    subgraph "Background Processing"
        CeleryWorker["Celery Worker"]:::worker
        TournamentTasks["Tournament Tasks"]:::worker
        GameTasks["Game Tasks"]:::worker
    end

    subgraph "Security"
        Sandbox["Sandbox System"]:::security
        Moderator["Moderator"]:::security
        CodeValidation["Code Validation"]:::security
    end

    subgraph "Storage"
        PostgreSQL[(PostgreSQL)]:::storage
        Redis[(Redis)]:::storage
        FileStorage["Submission Storage"]:::storage
    end

    subgraph "Error Handling"
        ErrorViews["Error Views"]:::error
        ErrorTemplates["Error Templates"]:::error
    end

    subgraph "Email System"
        EmailNotif["Email Notifications"]:::email
        EmailTemplates["Email Templates"]:::email
    end

    %% Connections
    Browser --> StaticAssets
    Browser --> WebSocket
    Browser --> ASGI
    ASGI --> WSRouter
    ASGI --> URLRouter
    URLRouter --> AuthViews
    WSRouter --> GameConsumer
    AuthViews --> OAuth
    OAuth --> UserMgmt
    GameConsumer --> Moderator
    Moderator --> Sandbox
    GameModule --> GameConsumer
    TournamentModule --> TournamentPairing
    TournamentModule --> CeleryWorker
    CeleryWorker --> TournamentTasks
    CeleryWorker --> GameTasks
    Sandbox --> FileStorage
    GameModule --> PostgreSQL
    TournamentModule --> PostgreSQL
    CeleryWorker --> Redis
    ErrorViews --> ErrorTemplates
    TournamentModule --> EmailNotif
    EmailNotif --> EmailTemplates

    %% Click Events
    click StaticAssets "https://github.com/tjcsl/othello-tourney/tree/master/othello/static/"
    click WebSocket "https://github.com/tjcsl/othello-tourney/blob/master/othello/static/js/games/play/socket.js"
    click ASGI "https://github.com/tjcsl/othello-tourney/blob/master/othello/asgi.py"
    click URLRouter "https://github.com/tjcsl/othello-tourney/blob/master/othello/urls.py"
    click WSRouter "https://github.com/tjcsl/othello-tourney/blob/master/othello/routing.py"
    click OAuth "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/auth/oauth.py"
    click UserMgmt "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/auth/models.py"
    click AuthViews "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/auth/views.py"
    click GameModule "https://github.com/tjcsl/othello-tourney/tree/master/othello/apps/games/"
    click TournamentModule "https://github.com/tjcsl/othello-tourney/tree/master/othello/apps/tournaments/"
    click GameConsumer "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/games/consumers.py"
    click TournamentPairing "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/tournaments/pairings.py"
    click CeleryWorker "https://github.com/tjcsl/othello-tourney/blob/master/othello/celery.py"
    click TournamentTasks "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/tournaments/tasks.py"
    click GameTasks "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/games/tasks.py"
    click Sandbox "https://github.com/tjcsl/othello-tourney/tree/master/othello/sandboxing/"
    click Moderator "https://github.com/tjcsl/othello-tourney/tree/master/othello/moderator/"
    click FileStorage "https://github.com/tjcsl/othello-tourney/tree/master/othello/submissions/"
    click ErrorViews "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/errors/views.py"
    click ErrorTemplates "https://github.com/tjcsl/othello-tourney/tree/master/othello/templates/error/"
    click EmailNotif "https://github.com/tjcsl/othello-tourney/blob/master/othello/apps/tournaments/emails.py"
    click EmailTemplates "https://github.com/tjcsl/othello-tourney/tree/master/othello/templates/emails/"

    %% Styling
    classDef client fill:#2374ab
    classDef server fill:#48a9a6
    classDef auth fill:#e4cc37
    classDef core fill:#28965a
    classDef worker fill:#da7422
    classDef security fill:#c64756
    classDef storage fill:#9c528b
    classDef error fill:#ff6b6b
    classDef email fill:#4ecdc4
```
