# kentywang/agamari architecture

> Architecture diagram of the GitHub repository kentywang/agamari, 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/kentywang/agamari
- Repository: https://github.com/kentywang/agamari

## Overview

##### Main Components

A. Client-Side (Browser)
- React Frontend Components
- Three.js 3D Rendering Engine
- Cannon.js Physics Engine
- Client-side Redux Store
- Socket.IO Client
- Game Logic Components

B. Server-Side
- Node.js Server
- Socket.IO Server
- Server-side Redux Store
- Game Engine
- World Management

**[Browser Client] <--Socket.IO--> [Node.js Server]**

**Client Side                    Server Side**

- React UI       |           | Game Engine    |
- Three.js       |           | World Manager  |
- Cannon.js      |<-Socket.->| Physics Sync   |
- Redux Store    |    IO     | Redux Store    |
- Game Logic     |           | State Manager  |

##### Data Flow Indicators

Specific data flows:
- Player inputs → Client physics calculations
- Physics updates → Server validation
- Server state changes → Client state updates
- Player interactions → Game state modifications

##### Key Technical Elements to Highlight

- Socket.IO real-time communication
- Distributed physics calculations
- State synchronization between client and server
- Redux store mirroring
- Three.js and Cannon.js integration

##### Implementation Notes

- browser/ directory mapping to client-side components
- server/ directory mapping to server-side components
- game/ subdirectories showing shared game logic
- reducers/ showing state management on both ends

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        direction TB
        ReactApp["React App"]:::frontend
        click ReactApp "https://github.com/kentywang/agamari/blob/master/browser/components/App.jsx"
        
        subgraph UI["UI Components"]
            direction TB
            Game["Game UI"]:::frontend
            click Game "https://github.com/kentywang/agamari/blob/master/browser/components/Game.jsx"
            ControlPanel["Control Panel"]:::frontend
            click ControlPanel "https://github.com/kentywang/agamari/blob/master/browser/components/ControlPanel.jsx"
            Chat["Chat Interface"]:::frontend
            click Chat "https://github.com/kentywang/agamari/blob/master/browser/components/Chat.jsx"
            Splash["Splash Screen"]:::frontend
            click Splash "https://github.com/kentywang/agamari/blob/master/browser/components/Splash.jsx"
        end
        
        subgraph GameLogic["Game Logic"]
            direction TB
            PlayerControls["Player Controls"]:::gamelogic
            click PlayerControls "https://github.com/kentywang/agamari/blob/master/browser/game/PlayerControls.js"
            FoodSystem["Food System"]:::gamelogic
            click FoodSystem "https://github.com/kentywang/agamari/blob/master/browser/game/food.js"
            PlayerLogic["Player Logic"]:::gamelogic
            click PlayerLogic "https://github.com/kentywang/agamari/blob/master/browser/game/player.js"
            MainGame["Main Game Logic"]:::gamelogic
            click MainGame "https://github.com/kentywang/agamari/blob/master/browser/game/game.js"
            GameConfig["Game Config"]:::gamelogic
            click GameConfig "https://github.com/kentywang/agamari/blob/master/browser/game/config.js"
        end
        
        subgraph ClientState["Client State Management"]
            direction TB
            ClientStore["Redux Store"]:::state
            click ClientStore "https://github.com/kentywang/agamari/blob/master/browser/store.js"
            ClientReducers["Reducers"]:::state
            click ClientReducers "https://github.com/kentywang/agamari/tree/master/browser/reducers/"
            PlayerState["Player State"]:::state
            click PlayerState "https://github.com/kentywang/agamari/blob/master/browser/reducers/players.js"
            GameState["Game State"]:::state
            click GameState "https://github.com/kentywang/agamari/blob/master/browser/reducers/gameState.js"
            FoodState["Food State"]:::state
            click FoodState "https://github.com/kentywang/agamari/blob/master/browser/reducers/food.js"
        end
        
        SocketClient["Socket.IO Client"]:::network
        click SocketClient "https://github.com/kentywang/agamari/blob/master/browser/socket.js"
        ThreeJS["Three.js Engine"]:::engine
        CannonJS["Cannon.js Physics"]:::engine
    end
    
    subgraph Server
        direction TB
        MainServer["Node.js Server"]:::server
        click MainServer "https://github.com/kentywang/agamari/blob/master/server/index.js"
        
        subgraph ServerComponents["Server Components"]
            direction TB
            GameEngine["Game Engine"]:::engine
            click GameEngine "https://github.com/kentywang/agamari/blob/master/server/game/engine.js"
            Listeners["Server Listeners"]:::server
            click Listeners "https://github.com/kentywang/agamari/blob/master/server/game/listeners.js"
        end
        
        subgraph ServerState["Server State Management"]
            direction TB
            ServerStore["Redux Store"]:::state
            click ServerStore "https://github.com/kentywang/agamari/blob/master/server/store.js"
            WorldManagement["World Management"]:::state
            click WorldManagement "https://github.com/kentywang/agamari/blob/master/server/reducers/worlds.js"
            EnvState["Environment State"]:::state
            click EnvState "https://github.com/kentywang/agamari/blob/master/server/reducers/environment.js"
            ServerPlayerState["Player State"]:::state
            click ServerPlayerState "https://github.com/kentywang/agamari/blob/master/server/reducers/players.js"
            ServerFoodState["Food State"]:::state
            click ServerFoodState "https://github.com/kentywang/agamari/blob/master/server/reducers/food.js"
        end
        
        SocketServer["Socket.IO Server"]:::network
    end
    
    %% Connections
    ReactApp --> UI
    UI --> GameLogic
    GameLogic --> ThreeJS
    GameLogic --> CannonJS
    GameLogic --> ClientState
    SocketClient <--> SocketServer
    MainServer --> ServerComponents
    ServerComponents --> ServerState
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef gamelogic fill:#2ecc71,stroke:#27ae60,color:white
    classDef state fill:#e67e22,stroke:#d35400,color:white
    classDef network fill:#9b59b6,stroke:#8e44ad,color:white
    classDef engine fill:#1abc9c,stroke:#16a085,color:white
    classDef server fill:#34495e,stroke:#2c3e50,color:white
    
    %% Legend
    subgraph Legend
        Frontend["Frontend Components"]:::frontend
        GameLogicComp["Game Logic"]:::gamelogic
        StateManagement["State Management"]:::state
        NetworkComm["Network Communication"]:::network
        Engines["Game Engines"]:::engine
        ServerComp["Server Components"]:::server
    end
```
