# ahmed-debbech/go_chess_puzzle architecture

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

## Overview

##### Main Components Identification

The project consists of several key services:
- Backend service (in /backend)
- Cutter service (in /cutter)
- Generator service (in /generator)
- Storer service (in /storer)

##### Cutter Service
- File Management (fileman/)
- Parser Component
- Scanner Component

##### Generator Service
- Chess Logic Component (chess/)
- Engine Interface (engine/)
- Puzzle Generation Logic (logic/)
- Configuration Management (config/)

##### Storer Service
- MongoDB Client
- Route Handlers
- Business Logic

##### Backend Service
- Web Interface (views/)
- Database Interface (logic/db.go)
- Puzzle Management (logic/puzzles.go)

##### Flow Representation

- Lichess.com → Cutter (game data ingestion)
- Cutter → Generator (processed game data)
- Generator → Stockfish (position analysis)
- Generator → Storer (puzzle storage)
- Storer → MongoDB (persistence)
- Backend ← MongoDB (puzzle retrieval)
- Backend → Web Client (puzzle serving)

##### Component Details

Labels showing:
- Technology stack (Go, MongoDB, Stockfish)
- Key file locations
- API endpoints
- Data formats (JSON, UCI protocol)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        L["Lichess.com API"]:::external
        S["Stockfish Engine"]:::external
    end

    subgraph Data
        DB[(MongoDB)]:::database
    end

    subgraph "Cutter Service"
        C["Cutter Service"]:::service
        FM["File Management"]:::component
        P["Parser"]:::component
        SC["Scanner"]:::component
        
        C --> FM
        C --> P
        FM --> SC
    end

    subgraph "Generator Service"
        G["Generator Service"]:::service
        CL["Chess Logic"]:::component
        EI["Engine Interface"]:::component
        PGL["Puzzle Generation Logic"]:::component
        CM["Configuration Management"]:::component
        
        G --> CL
        G --> EI
        G --> PGL
        G --> CM
    end

    subgraph "Storer Service"
        ST["Storer Service"]:::service
        MC["MongoDB Client"]:::component
        RH["Route Handlers"]:::component
        
        ST --> MC
        ST --> RH
    end

    subgraph "Backend Service"
        B["Backend Service"]:::service
        WI["Web Interface"]:::component
        DI["Database Interface"]:::component
        PM["Puzzle Management"]:::component
        
        B --> WI
        B --> DI
        B --> PM
    end

    L -.->|Game Data| C
    C -->|Processed Games| G
    G -->|Analysis Request| S
    S -->|Move Analysis| G
    G -->|Generated Puzzles| ST
    ST -->|Store| DB
    B -->|Retrieve| DB
    B -->|Serve| WI

    %% Click Events
    click B "https://github.com/ahmed-debbech/go_chess_puzzle/tree/master/backend"
    click C "https://github.com/ahmed-debbech/go_chess_puzzle/tree/master/cutter"
    click G "https://github.com/ahmed-debbech/go_chess_puzzle/tree/master/generator"
    click ST "https://github.com/ahmed-debbech/go_chess_puzzle/tree/master/storer"
    click MC "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/storer/mongo/client.go"
    click CL "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/generator/chess/chess.go"
    click EI "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/generator/engine/uci.go"
    click FM "https://github.com/ahmed-debbech/go_chess_puzzle/tree/master/cutter/fileman"
    click P "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/cutter/parser.go"
    click SC "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/cutter/fileman/scanner.go"
    click RH "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/storer/routes/routes.go"
    click WI "https://github.com/ahmed-debbech/go_chess_puzzle/tree/master/backend/views"
    click PGL "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/generator/logic/logic.go"
    click CM "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/generator/config/config.go"
    click DI "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/backend/logic/db.go"
    click PM "https://github.com/ahmed-debbech/go_chess_puzzle/blob/master/backend/logic/puzzles.go"

    %% Styling
    classDef service fill:#3498db,stroke:#2980b9,stroke-width:2px
    classDef component fill:#e74c3c,stroke:#c0392b,stroke-width:2px
    classDef external fill:#2ecc71,stroke:#27ae60,stroke-width:2px
    classDef database fill:#f1c40f,stroke:#f39c12,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Service"]:::service
        L2["Component"]:::component
        L3["External Service"]:::external
        L4[(Database)]:::database
    end
```
