# coen-potgieter/chess-encoding architecture

> Architecture diagram of the GitHub repository coen-potgieter/chess-encoding, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coen-potgieter/chess-encoding
- Repository: https://github.com/coen-potgieter/chess-encoding

## Overview

##### Main Components

a) Client-Side Components:
- Message Input/Output System
- Encryption/Decryption Engine
- Chess Game Generator
- Lichess Bot Interface

b) External Services:
- Lichess.org API
- Bot Accounts (2 separate bots)

##### Specific Component Details

a) File System Component (Yellow):
- Hierarchy: data/<folder_name>/{secret.txt, played-games, predefined-moves}
- Storage for moves.json and ids.json

b) Processing Pipeline (Green):
- Text to Binary Converter
- Binary to Chess Move Encoder
- Chess Move to Binary Decoder
- Binary to Text Converter

c) Bot System (Purple):
- Bot A Controller (play_a.py)
- Bot B Controller (play_b.py)
- Bot Synchronization Mechanism

d) API Integration (Red):
- Lichess.org API Interface
- Game State Tracker
- Move Validator

##### Key Processes to Highlight

a) Encryption Process:
1. Read secret.txt
2. Convert to binary
3. Generate chess moves
4. Store in moves.json

b) Game Execution:
1. Bot A reads moves
2. Bot B responds
3. Game ID storage
4. PGN retrieval

c) Decryption Process:
1. Load PGN files
2. Extract moves
3. Convert to binary
4. Recover message

##### Additional Elements

- Version/state information for key components
- Error handling paths
- Configuration dependencies

##### Technical Details to Note

- File formats (PGN, JSON, TXT)
- API endpoints
- Asynchronous operations
- Security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User_Layer
        Input["Input File (secret.txt)"]:::io
        Output["Output File (outp.txt)"]:::io
    end

    subgraph Processing_Layer
        EncEngine["Encryption/Decryption Engine"]:::process
        MoveGen["Chess Move Generator"]:::process
        BinConv["Binary Converter"]:::process
        MainCtrl["Main Controller"]:::process
    end

    subgraph Storage_Layer
        GameStore["Chess Game Storage"]:::storage
        MoveStore["Move Storage"]:::storage
        IDTracker["Game ID Tracker"]:::storage
    end

    subgraph Bot_Layer
        BotA["Bot A Controller"]:::bot
        BotB["Bot B Controller"]:::bot
        BotMgr["Bot Manager"]:::bot
    end

    subgraph External_Layer
        LichessAPI["Lichess.org API"]:::external
        APIInterface["API Interface"]:::external
    end

    Input --> MainCtrl
    MainCtrl --> BinConv
    BinConv --> EncEngine
    EncEngine --> MoveGen
    MoveGen --> MoveStore
    
    MoveStore --> BotA
    BotA --> APIInterface
    APIInterface <--> LichessAPI
    LichessAPI --> BotB
    
    BotA --> IDTracker
    BotB --> IDTracker
    
    IDTracker --> GameStore
    GameStore --> BinConv
    BinConv --> Output
    
    BotMgr --> BotA
    BotMgr --> BotB

    click Input "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/data/*/secret.txt"
    click Output "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/data/*/outp.txt"
    click EncEngine "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/encrytion.py"
    click GameStore "https://github.com/Coen-Potgieter/Chess-Encoding/tree/main/src/data/*/played-games"
    click MoveStore "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/data/*/predefined-moves/moves.json"
    click IDTracker "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/data/*/played-games/ids.json"
    click BotA "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/play_a.py"
    click BotB "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/play_b.py"
    click BotMgr "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/upgrade_bots.py"
    click APIInterface "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/api.py"
    click MainCtrl "https://github.com/Coen-Potgieter/Chess-Encoding/blob/main/src/main.py"

    classDef io fill:#3498db,stroke:#2980b9,stroke-width:2px
    classDef process fill:#2ecc71,stroke:#27ae60,stroke-width:2px
    classDef storage fill:#f1c40f,stroke:#f39c12,stroke-width:2px
    classDef bot fill:#9b59b6,stroke:#8e44ad,stroke-width:2px
    classDef external fill:#e74c3c,stroke:#c0392b,stroke-width:2px

    subgraph Legend
        L1[Input/Output]:::io
        L2[Processing]:::process
        L3[Storage]:::storage
        L4[Bot Components]:::bot
        L5[External Services]:::external
    end
```
