# tcec-chess/tcecgui architecture

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

- Interactive diagram: https://gitdiagram.com/tcec-chess/tcecgui
- Repository: https://github.com/tcec-chess/tcecgui

## Overview

##### Main Components

a. Frontend Layer:
- 3D Chess Interface (indicated by js/3d.js and THREE.js libraries)
- User Interface Components (various JS files in js/ directory)
- Theme System (css/ directory with multiple themes)
- Internationalization System (translate/ directory)

b. Backend Layer:
- Game Server (server.js, server-new.js)
- Chat System (chat_server.js, chat_engine.py)
- WebSocket Communication (indicated by socket.io library)

c. Core Chess Components:
- Chess Engine Interface (js/engine.js)
- Game Logic (js/game.js)
- WASM Modules (chess-wasm.wasm)
- Worker Thread (js/worker.js)

d. Additional Systems:
- Sound System (sound/ directory)
- Analytics (js/chart.js)
- PGN Analysis (analyse_pgn.js)

**[Client Browser Layer]**
- ↓↑
**[Frontend Components]**
- ↓↑
**[WebSocket/Network Layer]**
- ↓↑
**[Backend Services]**

##### Component Relationships

Key interactions:
- WebSocket connections between client and server
- 3D rendering pipeline
- Chess engine communication flow
- Event handling system
- Theme and translation system integration

##### Technical Details

a. Technologies:
- Three.js for 3D rendering
- Socket.io for real-time communication
- WebAssembly modules
- Web Workers for parallel processing

b. File Organization:
- Distinguish between distribution (dist/) and development (js/) code
- Asset management (sounds, images, translations)
- Configuration management (preset/ directory)

##### Implementation Details

- Double lines for data streaming

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph Frontend
        UI["User Interface"]:::frontend
        ThreeD["3D Chess Interface"]:::frontend
        Theme["Theme System"]:::frontend
        I18n["Internationalization"]:::frontend
        Sound["Sound System"]:::frontend
        Analytics["Analytics"]:::frontend
    end

    subgraph Core
        GameLogic["Game Logic"]:::core
        Engine["Chess Engine Interface"]:::core
        WASM["WASM Module"]:::core
        Worker["Worker Thread"]:::core
        Network["Network Layer"]:::core
        Common["Common Utilities"]:::core
    end

    subgraph Backend
        GameServer["Game Server"]:::backend
        ChatServer["Chat System"]:::backend
        WebSocket["WebSocket Server"]:::backend
    end

    subgraph Assets
        Models["3D Models"]:::asset
        Configs["Configuration"]:::asset
        PGN["PGN Analysis"]:::asset
    end

    %% Relationships
    Browser --> UI
    UI --> ThreeD
    UI --> Theme
    UI --> I18n
    UI --> Sound
    UI --> Analytics
    
    ThreeD --> Models
    GameLogic --> Engine
    Engine --> WASM
    Engine --> Worker
    
    Network --> WebSocket
    WebSocket --> GameServer
    WebSocket --> ChatServer
    
    GameLogic --> Common
    UI --> Common
    
    GameServer --> PGN
    GameServer --> Configs

    %% Click Events
    click ThreeD "https://github.com/TCEC-Chess/tcecgui/blob/master/js/3d.js"
    click Theme "https://github.com/TCEC-Chess/tcecgui/tree/master/css/"
    click I18n "https://github.com/TCEC-Chess/tcecgui/tree/master/translate/"
    click GameServer "https://github.com/TCEC-Chess/tcecgui/blob/master/server.js"
    click ChatServer "https://github.com/TCEC-Chess/tcecgui/blob/master/chat_server.js"
    click WebSocket "https://github.com/TCEC-Chess/tcecgui/blob/master/js/libs/socket.io.dev.js"
    click Engine "https://github.com/TCEC-Chess/tcecgui/blob/master/js/engine.js"
    click GameLogic "https://github.com/TCEC-Chess/tcecgui/blob/master/js/game.js"
    click WASM "https://github.com/TCEC-Chess/tcecgui/blob/master/js/chess-wasm.wasm"
    click Worker "https://github.com/TCEC-Chess/tcecgui/blob/master/js/worker.js"
    click Sound "https://github.com/TCEC-Chess/tcecgui/tree/master/sound/"
    click Analytics "https://github.com/TCEC-Chess/tcecgui/blob/master/js/chart.js"
    click PGN "https://github.com/TCEC-Chess/tcecgui/blob/master/analyse_pgn.js"
    click Models "https://github.com/TCEC-Chess/tcecgui/blob/master/export/pieces-draco.glb"
    click Configs "https://github.com/TCEC-Chess/tcecgui/tree/master/preset/"
    click Network "https://github.com/TCEC-Chess/tcecgui/blob/master/js/network.js"
    click Common "https://github.com/TCEC-Chess/tcecgui/blob/master/js/common.js"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef core fill:#f1c40f,stroke:#f39c12,color:black
    classDef asset fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Service"]:::backend
        CoreComp["Core Component"]:::core
        AssetComp["Asset/Resource"]:::asset
    end
```
