# sam152/aoe2-micromania architecture

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

- Interactive diagram: https://gitdiagram.com/sam152/aoe2-micromania
- Repository: https://github.com/sam152/aoe2-micromania

## Overview

Key Components to Include:

##### Core Architecture Layers

a) Client Layer:
- React Frontend (src/client)
- Canvas Renderer System
- Input Management
- Client State Management
- Asset Management
- Sound System

b) Server Layer:
- Game Server (src/server)
- Room Management
- Recording System
- State Synchronization

c) Common Layer:
- Game State Management
- Unit Management
- AI Systems
- Terrain System
- Formation System

**┌─────────────────────────────────────────────┐**
- Client Tier                 │
- ┤
- React Components                          │
- Canvas Renderer                           │
- Input Manager                             │
- Client State                              │
- Asset Manager                             │
- ┬───────────────────────────────┘

**┌─────────────▼───────────────────────────────┐**
- Common Game Logic                 │
- ┤
- Game State                                │
- Unit System                               │
- Formation System                          │
- AI System                                 │
- Terrain System                            │
- ┬───────────────────────────────┘

**┌─────────────▼───────────────────────────────┐**
- Server Tier                      │
- ┤
- Room Management                           │
- State Synchronization                     │
- Game Recording                            │
- ┘

##### Key Interactions to Highlight

a) State Management Flow:
- How actions flow from client input to server validation
- State synchronization between clients
- Demonstrate the tick-based simulation system

b) Asset Pipeline:
- How graphics and sound assets are loaded and managed
- Asset cache system

c) Networking:
- Client-server communication
- Spectator connections
- Multiplayer synchronization

##### Implementation Details

- Annotations for critical systems like the tick rate (20 fps)

##### The networking architecture

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this implementation unique, such as the deterministic simulation and state synchronization system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef client fill:#3498db,color:white
    classDef server fill:#e67e22,color:white
    classDef common fill:#2ecc71,color:white
    classDef external fill:#9b59b6,color:white
    classDef data fill:#95a5a6,color:white

    subgraph ClientLayer["Client Layer"]
        ReactFrontend["React Frontend"]:::client
        CanvasRenderer["Canvas Renderer"]:::client
        InputManager["Input Management"]:::client
        ClientState["Client State"]:::client
        AssetManager["Asset Management"]:::client
        SoundSystem["Sound System"]:::client
        HotkeySystem["Hotkey System"]:::client
        AnimationSystem["Animation System"]:::client
        AssetPipeline["Asset Pipeline"]:::client
    end

    subgraph CommonLayer["Common Game Logic"]
        GameState["Game State"]:::common
        UnitSystem["Unit System"]:::common
        FormationSystem["Formation System"]:::common
        AISystem["AI System"]:::common
        TerrainSystem["Terrain System"]:::common
        StateSynch["State Synchronization"]:::common
    end

    subgraph ServerLayer["Server Layer"]
        GameServer["Game Server"]:::server
        RoomManagement["Room Management"]:::server
        RecordingSystem["Recording System"]:::server
    end

    %% Connections
    ReactFrontend --> CanvasRenderer
    ReactFrontend --> InputManager
    InputManager --> HotkeySystem
    CanvasRenderer --> AnimationSystem
    CanvasRenderer --> AssetManager
    AssetManager --> AssetPipeline
    ClientState --> GameState
    
    GameState --> StateSynch
    GameState --> UnitSystem
    UnitSystem --> FormationSystem
    UnitSystem --> AISystem
    UnitSystem --> TerrainSystem
    
    StateSynch --> GameServer
    GameServer --> RoomManagement
    GameServer --> RecordingSystem

    %% Legend
    subgraph Legend
        ClientComp["Client Component"]:::client
        ServerComp["Server Component"]:::server
        CommonComp["Common Component"]:::common
    end

    %% Click events
    click ReactFrontend "https://github.com/Sam152/aoe2-micromania/tree/main/src/client/components/"
    click CanvasRenderer "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/drawing/CanvasRenderer.ts"
    click InputManager "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/input/InputManager.ts"
    click ClientState "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/state/clientState.ts"
    click AssetManager "https://github.com/Sam152/aoe2-micromania/tree/main/src/common/drawing/assets/"
    click SoundSystem "https://github.com/Sam152/aoe2-micromania/tree/main/src/common/sounds/"
    click GameServer "https://github.com/Sam152/aoe2-micromania/blob/main/src/server/index.ts"
    click RoomManagement "https://github.com/Sam152/aoe2-micromania/tree/main/src/server/rooms/"
    click RecordingSystem "https://github.com/Sam152/aoe2-micromania/blob/main/src/server/recs/RecordedGame.ts"
    click GameState "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/state/gameState.ts"
    click UnitSystem "https://github.com/Sam152/aoe2-micromania/tree/main/src/common/units/"
    click AISystem "https://github.com/Sam152/aoe2-micromania/tree/main/src/common/ai/"
    click TerrainSystem "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/terrain/Grid.ts"
    click FormationSystem "https://github.com/Sam152/aoe2-micromania/tree/main/src/common/units/formations/"
    click StateSynch "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/state/managers/NetworkedStateManager.ts"
    click AssetPipeline "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/drawing/assets/assetCache.ts"
    click AnimationSystem "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/drawing/SmxAnimation.ts"
    click HotkeySystem "https://github.com/Sam152/aoe2-micromania/blob/main/src/common/input/HotkeyManager.ts"
```
