# teddyxiong53/guess_num architecture

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

- Interactive diagram: https://gitdiagram.com/teddyxiong53/guess_num
- Repository: https://github.com/teddyxiong53/guess_num

## Overview

##### Project type and purpose
- This is a multiplayer “guess the number” game server built on the Skynet lightweight game‐server framework.
- All code is in Lua and lives under the `app/` directory. Skynet launches each Lua file as a separate “service.”
- Users connect via TCP (port 8888) and issue text commands (`login`, `ready`, `guess`, etc.).

##### File structure
- Top level
- `config/` – Skynet configuration files (defines services, thread pools, logging, network bindings).
- `app/` – Lua services that Skynet will launch.
– `main.lua` – bootstrap service that starts your other services.
– `redis.lua` – a Skynet service that wraps Redis calls (caching, persistence).
– `hall.lua` – matchmaking/hall logic: queues players, assigns them to rooms.
– `agent.lua` – per‐connection service: parses client commands, forwards them to hall/room.
– `room.lua` – game‐room service: holds game state, enforces guess logic and turn order.

##### README for insights
- Skynet startup sequence (bootstrap → launcher → harbor → datacenter → service_mgr → main → …).
- Example logs show agents being launched dynamically for each new TCP client, plus one persistent room service.
- Flow: client connects → agent spawns → login → ready → hall assigns a “room” → room governs the game → room signals end → agent closes.

##### Detailed breakdown of components
- Skynet Core: thread pool, message queue
- bootstrap.lua & launcher (start sequence)
- datacenterd & service_mgr (service registry)
- main.lua (your custom init)
- redis.lua (client wrapper) → Redis Server
- hall.lua (matchmaking logic)
- agent.lua (per‐client handler)
- room.lua (game instance)
- TCP clients

##### Final advice
- Dynamic interactions (agent spawn, room spawn).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Clients["TCP Clients"]:::external
    Datastore[(Redis Server)]:::datastore

    %% Skynet Core
    subgraph "Skynet Core"
        Core["Thread Pool & Message Queue"]:::infra
    end

    %% Infrastructure Services
    subgraph "Infrastructure Services"
        Bootstrap["bootstrap & launcher"]:::infra
        Datacenter["datacenterd & service_mgr"]:::infra
    end

    %% Application Services
    subgraph "Application Services"
        Main["main.lua service"]:::app
        RedisWrapper["redis.lua service"]:::app
        Hall["hall.lua service"]:::logic
        AgentPool["agent.lua instances"]:::network
        RoomPool["room.lua instances"]:::logic
    end

    %% Relationships
    Clients -->|"TCP"| AgentPool
    Bootstrap -->|"launches"| Main
    Bootstrap -->|"starts registry"| Datacenter
    Main -->|"initializes"| RedisWrapper
    Main -->|"initializes"| Hall
    Main -->|"initializes"| AgentPool
    Main -->|"initializes"| RoomPool

    AgentPool -->|"login/ready"| Hall
    Hall -->|"assign room"| RoomPool
    AgentPool -->|"guess commands"| RoomPool
    RoomPool -->|"turn updates"| AgentPool

    %% Redis interactions
    Hall -->|"state ops"| RedisWrapper
    AgentPool -->|"cache/persist"| RedisWrapper
    RoomPool -->|"state ops"| RedisWrapper
    RedisWrapper -->|calls| Datastore

    %% Service registration
    Main -->|register| Datacenter
    RedisWrapper -->|register| Datacenter
    Hall -->|register| Datacenter
    AgentPool -->|register| Datacenter
    RoomPool -->|register| Datacenter

    %% Core integration
    Bootstrap -.-> Core
    Datacenter -.-> Core

    %% Click Events
    click config "https://github.com/teddyxiong53/guess_num/tree/main/config/"
    click Main "https://github.com/teddyxiong53/guess_num/blob/main/app/main.lua"
    click RedisWrapper "https://github.com/teddyxiong53/guess_num/blob/main/app/redis.lua"
    click Hall "https://github.com/teddyxiong53/guess_num/blob/main/app/hall.lua"
    click AgentPool "https://github.com/teddyxiong53/guess_num/blob/main/app/agent.lua"
    click RoomPool "https://github.com/teddyxiong53/guess_num/blob/main/app/room.lua"

    %% Styles
    classDef external fill:#FFE599,stroke:#E69138,stroke-width:2px
    classDef infra fill:#D9D9D9,stroke:#7F7F7F,stroke-width:2px
    classDef app fill:#C9DAF8,stroke:#6D9EEB,stroke-width:2px
    classDef logic fill:#A2C4C9,stroke:#3C8DAD,stroke-width:2px
    classDef network fill:#B6D7A8,stroke:#6AA84F,stroke-width:2px
    classDef datastore fill:#F9CB9C,stroke:#E06666,stroke-width:2px
```
