# mnnlr/chess_vision_ml_server architecture

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

- Interactive diagram: https://gitdiagram.com/mnnlr/chess_vision_ml_server
- Repository: https://github.com/mnnlr/chess_vision_ml_server

## Overview

Key Components to Include:

##### Input Layer
- Image Input Component
- Image Preprocessing Module

##### Detection Layer
- YOLO Object Detection System
- Chess Piece Recognition Module

##### Processing Layer
- Board State Analyzer
- FEN Converter

##### Analysis Layer
- Stockfish Engine Integration
- Move Prediction System

##### Component Organization

- Detection Layer below that
- Processing Layer in the middle

##### Data Flow Representation

- Image data flow from input to YOLO detection
- Detected pieces information to board state analyzer
- Board state to FEN converter
- FEN notation to Stockfish engine
- Final move predictions back to the output

##### Specific Component Details

For each major component, include:
- Input Component: Show supported image formats
- YOLO Detection: Include reference to custom piece dataset (noted from custom_piece_dataset_making.ipynb)
- Board State Analyzer: Show connection to data.yaml configuration
- Stockfish Integration: Indicate engine version and communication protocol

##### Technical Specifications

- Python 3.8+ requirement
- YOLO model specifications
- Stockfish engine version
- Key dependencies from requirements.txt

##### Integration Points

Highlight:
- API endpoints if any
- File system interactions
- External service connections (Stockfish)

Special Considerations:

##### ML Pipeline
- Training data flow for the YOLO model
- Where the custom dataset is used
- Model checkpoint locations

##### Error Handling
- Validation steps between components
- Fallback paths for failed detections

##### Performance Optimization
- Caching mechanisms
- Parallel processing opportunities

##### System Requirements
- Hardware requirements
- Memory usage points
- CPU/GPU utilization areas

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Define styles
    classDef input fill:#a8d1f0,stroke:#000
    classDef detection fill:#90EE90,stroke:#000
    classDef processing fill:#FFE5B4,stroke:#000
    classDef analysis fill:#FFB6C1,stroke:#000
    classDef requirements fill:#E6E6FA,stroke:#000

    %% Input Layer
    subgraph InputLayer["Input Layer"]
        IMG[Image Input]
        PRE[Image Preprocessing]
    end

    %% Detection Layer
    subgraph DetectionLayer["Detection Layer"]
        YOLO[YOLO Object Detection]
        PCR[Chess Piece Recognition]
    end

    %% Processing Layer
    subgraph ProcessingLayer["Processing Layer"]
        BSA[Board State Analyzer]
        FEN[FEN Converter]
    end

    %% Analysis Layer
    subgraph AnalysisLayer["Analysis Layer"]
        SF[Stockfish Engine]
        MP[Move Prediction]
    end

    %% System Requirements
    subgraph Requirements["System Requirements"]
        PY["Python 3.8+"]
        DEP["Dependencies"]
        HW["Hardware Requirements"]
    end

    %% Connections
    IMG --> PRE
    PRE --> YOLO
    YOLO --> PCR
    PCR --> BSA
    BSA --> FEN
    FEN --> SF
    SF --> MP

    %% Optional/Validation Flows
    PRE -.-> |Validation| IMG
    PCR -.-> |Failed Detection| PRE
    BSA -.-> |State Validation| PCR
    
    %% Requirements Connections
    DEP --> SF
    PY --> YOLO
    HW --> SF

    %% Style Applications
    class IMG,PRE input
    class YOLO,PCR detection
    class BSA,FEN processing
    class SF,MP analysis
    class PY,DEP,HW requirements

    %% Click Events
    click YOLO "https://github.com/mnnlr/Chess_Vision_ML_Server/blob/main/custom_piece_dataset_making.ipynb"
    click PCR "https://github.com/mnnlr/Chess_Vision_ML_Server/blob/main/custom_piece_dataset_making.ipynb"
    click BSA "https://github.com/mnnlr/Chess_Vision_ML_Server/blob/main/data.yaml"
    click DEP "https://github.com/mnnlr/Chess_Vision_ML_Server/blob/main/requirements.txt"

    %% Legend
    subgraph Legend
        L1[Input/Output]:::input
        L2[Detection]:::detection
        L3[Processing]:::processing
        L4[Analysis]:::analysis
        L5[Requirements]:::requirements
    end
```
