# zultimapg3d/toro-webserver architecture

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

- Interactive diagram: https://gitdiagram.com/zultimapg3d/toro-webserver
- Repository: https://github.com/zultimapg3d/toro-webserver

## Overview

##### Main Components
- Deno Web Server – The core of the system is built in Deno and starts from entry points like main.ts and server.ts.
- API Route Modules – Routes are split into several groups:
- “bexide” (handling account login, masterData, friend operations, presents, purchases, user data, etc.)
- “line” (handling authentication, logging, and coin synchronization)
- “neptune” (for login services like guest login, policy agreements, and version information)
- “assetbundleRouter” and others for serving asset bundles.
- Database & Migrations – Files like db.ts and the migrations directory indicate persistent data storage and SQL-based schema management.
- Protocol Communication – The protobuf folder contains .proto files and generated TypeScript files that define the structure of data for communication between the server and clients.
- Static and Asset Management – The assets and player_data directories hold game asset bundles and persistent player data.
- Configuration and Infrastructure – Files like config.json, config.ts, and Docker-related files (Dockerfile, .dockerignore) provide setup, runtime configurations, and containerization support.

##### Relationships and Interactions
- Clients (game or restoration modifications) connect to the server over HTTP (with endpoints defined in the various “routes” directories).
- Requests are routed to the proper module (e.g., bexide for account, friend, and purchase-related requests, line for logging and coin modifications, neptune for login operations) where business logic is applied.
- The server uses protocol buffers for nicely structured data exchange where applicable (indicated by the protobuf folder).
- For persistent data, the server interacts with the database using utilities in db.ts and the SQL scripts in “migrations.”
- The assets are served statically and are partitioned by platform (Android assets, etc.), ensuring game clients get the correct asset bundles.

##### Architectural Patterns and Design Principles
- Modular API Design – Each “routes” sub-directory encapsulates a separate aspect of the game API reflecting clear separation of concerns.
- Layered Architecture – You have an entry layer (HTTP server), a routing/business logic layer, a data access layer (database and player_data persistence), and an external asset management layer.
- Protocol Buffers for Data Contracts – This abstraction improves maintainability and ensures consistency in data structures across components.
- Containerization – Docker support encapsulates the environment, making deployment more consistent.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client (Game/Restoration)"):::client

    subgraph "Docker Container"
        DenWeb("Deno Web Server"):::server
        Bexide("Bexide Routes"):::routes
        Line("Line Routes"):::routes
        Neptune("Neptune Routes"):::routes
        AssetBundle("Asset Bundle Router"):::routes
        Config("Configuration"):::config
        DockerConfig("Docker Container"):::docker
    end

    DB("Database"):::database
    Proto("Protocol Buffers Module"):::proto
    Assets("Static Assets & Player Data"):::assets

    Client -->|"HTTP_Request"| DenWeb
    DenWeb -->|"dispatch"| Bexide
    DenWeb -->|"dispatch"| Line
    DenWeb -->|"dispatch"| Neptune
    DenWeb -->|"dispatch"| AssetBundle
    DenWeb -->|"loads"| Config

    Bexide -->|"db_access"| DB
    Bexide -->|"protocol_comm"| Proto

    Line -->|"db_access"| DB
    Line -->|"protocol_comm"| Proto

    Neptune -->|"db_access"| DB
    Neptune -->|"protocol_comm"| Proto

    AssetBundle -->|"serves"| Assets

    DockerConfig -->|"deploys"| DenWeb

    click DenWeb "https://github.com/zultimapg3d/toro-webserver/blob/main/main.ts"
    click DenWeb "https://github.com/zultimapg3d/toro-webserver/blob/main/server.ts"
    click Bexide "https://github.com/zultimapg3d/toro-webserver/tree/main/routes/bexide"
    click Line "https://github.com/zultimapg3d/toro-webserver/tree/main/routes/line"
    click Neptune "https://github.com/zultimapg3d/toro-webserver/tree/main/routes/neptune"
    click AssetBundle "https://github.com/zultimapg3d/toro-webserver/blob/main/routes/assetbundleRouter.ts"
    click DB "https://github.com/zultimapg3d/toro-webserver/blob/main/db.ts"
    click DB "https://github.com/zultimapg3d/toro-webserver/tree/main/migrations"
    click Proto "https://github.com/zultimapg3d/toro-webserver/tree/main/protobuf"
    click Config "https://github.com/zultimapg3d/toro-webserver/blob/main/config.json"
    click Config "https://github.com/zultimapg3d/toro-webserver/blob/main/config.ts"
    click DockerConfig "https://github.com/zultimapg3d/toro-webserver/tree/main/Dockerfile"
    click DockerConfig "https://github.com/zultimapg3d/toro-webserver/blob/main/.dockerignore"
    click Assets "https://github.com/zultimapg3d/toro-webserver/tree/main/assets"
    click Assets "https://github.com/zultimapg3d/toro-webserver/tree/main/player_data"

    classDef client fill:#a2d9ce,stroke:#1abc9c,stroke-width:2px;
    classDef server fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef routes fill:#d6eaf8,stroke:#3498db,stroke-width:2px;
    classDef config fill:#fad7a0,stroke:#e67e22,stroke-width:2px;
    classDef docker fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef database fill:#f5b7b1,stroke:#e74c3c,stroke-width:2px;
    classDef proto fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
    classDef assets fill:#fcf3cf,stroke:#f39c12,stroke-width:2px;
```
