# ai0702/among-us-clone architecture

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

- Interactive diagram: https://gitdiagram.com/ai0702/among-us-clone
- Repository: https://github.com/ai0702/among-us-clone

## Overview

##### Project Type & Purpose
- This is a multiplayer game (LAN) with optional voice chat, built in Python using pygame, pytmx, sockets, asyncore, threading, and pyaudio.
- Supports single-player (“Freeplay”) and local multiplayer via a custom game server and an optional voice chat server.

##### Main Architectural Components
a. Game Client
– Menu/UI Layer (menu.py)
– Game Loop & Renderer (main.py → game.py → drawable.py → sprites.py → tilemap.py)
– Input & Control Handlers (func.py, gamefunctions.py)
– Task Subsystem (tasks.py)
– Network Client (client side sockets in game.py)
– Voice Chat Client (voice.py, pyaudio streams)
– Asset Loader (loads images under Assets/, sounds under Assets/Sounds/, maps via pytmx)
b. Game Server (server.py)
– Connection Manager (asyncore / threading)
– Game State Manager (maintains player positions, tasks, impostor logic)
– Broadcast Loop (sends serialized state via pickle over sockets)
c. Voice Chat Server (server_voice.py)
– Audio Stream Manager (accepts pyaudio streams, forwards to clients)
d. Persistence & Configuration
– settings.py (configurable constants)
– setup.py (installation entry)

##### Relationships & Data Flows
- Clients ↔ Game Server
– TCP/UDP sockets carry serialized game state and player input.
- Clients ↔ Voice Chat Server
– pyaudio streams via sockets.
- Client Internal
– Game Loop → Rendering → Display
– Input Handler → Game Logic → Network Client
- Asset Loading
– Static assets (images, sounds, maps) are read at startup and cached by the client.

##### Architectural Patterns & Principles
- Client-Server (authoritative server) for game logic
- Modular layering inside Client:
– Presentation (UI/Menu)
– Application Logic (Game Loop, Tasks)
– Infrastructure (Networking, Audio I/O)
- Threaded / asynchronous I/O to prevent blocking (asyncore + threading + pyaudio callbacks)
- Asset separation (Assets folder) for maintainability
- Single Responsibility: each Python module handles one concern (e.g., tilemap.py for TMX parsing)

- Arrowheads to show direction of data/commands
– Client components (blue)
– Server components (green)
– External/third‐party (gray)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Game Clients Group
    subgraph "Game Client" 
        direction TB
        menu["Menu/UI Layer\n(menu.py)"]:::client
        subgraph "Game Loop & Renderer"
            direction TB
            main["Main Script\n(main.py)"]:::client
            game["Core Loop & Networking\n(game.py)"]:::client
            drawable["Drawing Primitives\n(drawable.py)"]:::client
            sprites["Sprite Definitions\n(sprites.py)"]:::client
            tilemap["TMX Map Parsing\n(tilemap.py)"]:::client
        end
        subgraph "Input & Control Handlers"
            direction TB
            func["func.py"]:::client
            gamefunctions["gamefunctions.py"]:::client
        end
        tasks["Task Subsystem\n(tasks.py)"]:::client
        voice["Voice Chat Client\n(voice.py)"]:::client
        subgraph "Asset Loader"
            direction TB
            assetsImg["Images\n(Assets/Images/)"]:::client
            assetsSnd["Sounds\n(Assets/Sounds/)"]:::client
            assetsMap["Maps\n(Assets/Maps/)"]:::client
        end
    end

    %% Servers and External
    server["Game Server\n(server.py)"]:::server
    server_voice["Voice Chat Server\n(server_voice.py)"]:::voice
    AssetStore(("Asset Store\n(Filesystem)")):::external
    settings["Settings\n(settings.py)"]:::external
    setup["Setup\n(setup.py)"]:::external

    %% Connections
    game -->|"socket + pickle"| server
    voice -->|"pyaudio"| server_voice
    assetsImg --> AssetStore
    assetsSnd --> AssetStore
    assetsMap --> AssetStore

    %% Click Events
    click menu "https://github.com/ai0702/among-us-clone/blob/main/menu.py"
    click main "https://github.com/ai0702/among-us-clone/blob/main/main.py"
    click game "https://github.com/ai0702/among-us-clone/blob/main/game.py"
    click drawable "https://github.com/ai0702/among-us-clone/blob/main/drawable.py"
    click sprites "https://github.com/ai0702/among-us-clone/blob/main/sprites.py"
    click tilemap "https://github.com/ai0702/among-us-clone/blob/main/tilemap.py"
    click func "https://github.com/ai0702/among-us-clone/blob/main/func.py"
    click gamefunctions "https://github.com/ai0702/among-us-clone/blob/main/gamefunctions.py"
    click tasks "https://github.com/ai0702/among-us-clone/blob/main/tasks.py"
    click voice "https://github.com/ai0702/among-us-clone/blob/main/voice.py"
    click server "https://github.com/ai0702/among-us-clone/blob/main/server.py"
    click server_voice "https://github.com/ai0702/among-us-clone/blob/main/server_voice.py"
    click settings "https://github.com/ai0702/among-us-clone/blob/main/settings.py"
    click setup "https://github.com/ai0702/among-us-clone/blob/main/setup.py"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef server fill:#90EE90,stroke:#000,stroke-width:1px
    classDef voice fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
