# frzleaf/aolang architecture

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

- Interactive diagram: https://gitdiagram.com/frzleaf/aolang
- Repository: https://github.com/frzleaf/aolang

## Overview

##### Project Type and Purpose
- This is a network‐proxy tool (“AO LÀNG”) that lets multiple players host and join LAN‐only games (e.g., Warcraft III) over the Internet.
- It comprises two main binaries: a central TCP “proxy_server” and a client‐side “proxy_client” (plus optional “lan_agent” and “sandbox” helpers).

##### File‐Structure Analysis
- Top level:
- build/, doc/, server.sh, README.md
- src/main/ – entrypoints:
– proxy_server.go (the server app)
– proxy_client.go (the client app)
– lan_agent.go (local network agent for game broadcast interception)
– sandbox.go (network sandbox for isolating/redirecting traffic)
- src/proxy/ – shared library modules (bootstrap, connectors, controller, host/guest logic, logging, monitoring, settings, DTOs, utilities)
- src/test/ – unit tests and mock host/guest apps
- There is no database; the server maintains in‐memory sessions and forwards packets.

##### README Insights
- Server listens on TCP port 9999; clients connect here.
- Clients optionally build from source or use prebuilt releases.
- Purpose: intercept LAN game traffic, tunnel via Internet proxy, forward to other clients so the game believes participants are on the same LAN.

##### Key Components and Their Relationships
a. Client Machine Components
- Game executable (e.g. Warcraft III)
- lan_agent: intercepts/broadcasts game discovery packets
- sandbox: sets up virtual NIC or routing rules (isolates game traffic)
- proxy_client:
– LocalConnector: captures outbound UDP/TCP game traffic
– ServerConnector: maintains persistent TCP connection to proxy_server
– Controller: orchestrates guest/host operations
– Logger/Monitor: logs and optionally reports health metrics
b. Central Proxy Server Components
- proxy_server:
– ServerConnector: accepts incoming client TCP connections
– Controller: authenticates and tracks sessions
– Host/Guest modules: manage packet forwarding logic
– Settings: global config (e.g. port, timeouts)
– Logger/Monitor: collects runtime metrics and logs
– DTOs & Util: serialize/deserialize messages, shared helpers
c. Data Flows
1. Game → lan_agent → LocalConnector (proxy_client)
2. LocalConnector → ServerConnector → over Internet → ServerConnector (proxy_server)
3. ServerController dispatches to other clients’ ServerConnector → their LocalConnector → sandbox → game
d. Architectural Patterns
- Modular library (src/proxy) shared between client & server
- Single‐host central server orchestrator
- Packet forwarding (tunnel/proxy) design
- Separation of concerns: connectors vs. controller vs. utils vs. monitoring

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Zone
    subgraph "Client Machine" 
        direction TB
        Game["Game Executable"]:::client
        LanAgent["lan_agent"]:::client
        Sandbox["sandbox"]:::sandbox
        ProxyClient["proxy_client"]:::client
        LocalConnector["LocalConnector"]:::client
        ClientServerConnector["ServerConnector (Client)"]:::client
        ClientController["Controller"]:::client
        ClientLogger["Logger/Monitor"]:::client

        Game -->|discovers| LanAgent
        LanAgent -->|forwards packets| LocalConnector
        Sandbox -->|routes traffic| LocalConnector
        LocalConnector -->|captures| ClientServerConnector
        ClientServerConnector -->|TCP tunnel| Internet
        ClientController --> ProxyClient
        ProxyClient --> ClientLogger
    end

    %% Internet Cloud
    Internet["Public Internet (port 9999)"]:::internet

    %% Proxy Server Zone
    subgraph "Central Proxy Server"
        direction TB
        ServerConnector["ServerConnector (Server)"]:::server
        ServerController["Controller"]:::server
        HostLogic["Host Logic"]:::server
        GuestLogic["Guest Logic"]:::server
        Settings["Settings"]:::server
        ServerLogger["Logger/Monitor"]:::server
        DTOs["DTOs"]:::server
        Bootstrap["Bootstrap"]:::server
        Utilities["Utilities"]:::server

        Internet -->|TCP connect| ServerConnector
        ServerConnector --> ServerController
        ServerController --> HostLogic
        ServerController --> GuestLogic
        Bootstrap --> Settings
        DTOs --> Utilities
        ServerController --> ServerLogger
    end

    Internet2["Public Internet"]:::internet

    %% Other Clients Zone
    subgraph "Other Clients"
        direction TB
        OtherServerConnector["ServerConnector (Client)"]:::client
        OtherLocalConnector["LocalConnector"]:::client
        OtherSandbox["sandbox"]:::sandbox
        OtherLanAgent["lan_agent"]:::client
        OtherGame["Game Executable"]:::client

        Internet2 --> OtherServerConnector
        OtherServerConnector --> OtherLocalConnector
        OtherLocalConnector --> OtherSandbox
        OtherSandbox --> OtherLanAgent
        OtherLanAgent --> OtherGame
    end

    %% Click Events
    click ProxyClient "https://github.com/frzleaf/aolang/blob/master/src/main/proxy_client.go"
    click LanAgent "https://github.com/frzleaf/aolang/blob/master/src/main/lan_agent.go"
    click Sandbox "https://github.com/frzleaf/aolang/blob/master/src/main/sandbox.go"
    click Bootstrap "https://github.com/frzleaf/aolang/blob/master/src/proxy/bootstrap.go"
    click LocalConnector "https://github.com/frzleaf/aolang/blob/master/src/proxy/local_connector.go"
    click ClientServerConnector "https://github.com/frzleaf/aolang/blob/master/src/proxy/server_connector.go"
    click ServerConnector "https://github.com/frzleaf/aolang/blob/master/src/server.go"
    click ServerController "https://github.com/frzleaf/aolang/blob/master/src/proxy/controller.go"
    click HostLogic "https://github.com/frzleaf/aolang/blob/master/src/proxy/host.go"
    click GuestLogic "https://github.com/frzleaf/aolang/blob/master/src/proxy/guest.go"
    click DTOs "https://github.com/frzleaf/aolang/blob/master/src/proxy/dto.go"
    click Settings "https://github.com/frzleaf/aolang/blob/master/src/proxy/settings.go"
    click ServerLogger "https://github.com/frzleaf/aolang/blob/master/src/proxy/logger.go"
    click Utilities "https://github.com/frzleaf/aolang/blob/master/src/proxy/util.go"
    click Utilities "https://github.com/frzleaf/aolang/blob/master/src/proxy/common.go"
    click ProxyServer "https://github.com/frzleaf/aolang/blob/master/src/main/proxy_server.go"
    click ServerScript "https://github.com/frzleaf/aolang/blob/master/server.sh"

    %% Styles
    classDef client fill:#eaffea,stroke:#28a745
    classDef server fill:#e0eaff,stroke:#0066cc
    classDef internet fill:#ffe5cc,stroke:#cc5500
    classDef sandbox fill:#fff3cd,stroke:#ffcc00
```
