# nzemlin/chess_movementor architecture

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

- Interactive diagram: https://gitdiagram.com/nzemlin/chess_movementor
- Repository: https://github.com/nzemlin/chess_movementor

## Overview

##### Main Components

a) Frontend Layer:
- Web interface components using the templates directory structure
- Extensive JavaScript modules in the static directory
- Chess board visualization components
- Audio feedback system

b) Backend Layer:
- Flask application structure (evident from the Python files and templates)
- Authentication system (auth.py)
- Database component (db.py)
- Opening moves management (openings.py)
- Scraping functionality (scrape.py)

c) External Components:
- Stockfish Chess Engine Integration (indicated by stockfish-nnue files)
- Database (SQLite, as indicated by schema.sql)

##### Component Relationships

**[Web Browser] ←→ [Frontend Components]**
- ↓
**[Authentication] ←→ [Flask Backend] ←→ [Database]**
- ↓
- [Stockfish Engine]

##### Detailed Component Breakdown

- Chess Board Interface (chess.js, chessboard-1.0.0.js)
- Move Management (move.js, premove.js)
- Game State Management (game.js, eval.js)
- User Interface Elements (page.js, buttons.js)
- Audio Feedback System (sounds.js)
- Visual Helpers (highlight.js, dot_circle.js)

- Authentication Module (auth.py)
- Database Operations (db.py)
- Opening Moves Management (openings.py)
- Web Scraping Module (scrape.py)
- Utility Functions (utils/)

##### Data Flow Indicators

- User interactions with the chess board
- Move validation flows
- Database operations
- Authentication processes
- Stockfish engine analysis paths

##### Technical Stack Indicators

Highlight:
- Flask (Python web framework)
- JavaScript (Frontend logic)
- Stockfish (Chess engine)
- SQLite (Database)
- HTML/CSS (Frontend rendering)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Frontend Layer"
        WB[Web Browser]
        UI["User Interface"]
        click UI "https://github.com/NZemlin/chess_movementor/tree/main/movementor/templates/"
        
        subgraph "Chess Interface Components"
            CB["Chess Board Interface"]
            click CB "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/chessboard-1.0.0.js"
            GM["Game State Management"]
            click GM "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/game.js"
            MM["Move Management"]
            click MM "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/move.js"
            PM["Pre-move System"]
            click PM "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/premove.js"
            PH["Piece Promotion"]
            click PH "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/promotion.js"
            TM["Timer"]
            click TM "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/timer.js"
        end

        subgraph "UI Components"
            VH["Visual Helpers"]
            click VH "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/highlight.js"
            AF["Audio Feedback"]
            click AF "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/sounds.js"
            GC["Game Controls"]
            click GC "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/buttons.js"
            EV["Evaluation Display"]
            click EV "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/eval.js"
        end
    end

    subgraph "Backend Layer"
        FB["Flask Backend"]
        
        subgraph "Core Services"
            AU["Authentication System"]
            click AU "https://github.com/NZemlin/chess_movementor/blob/main/movementor/auth.py"
            DB["Database Operations"]
            click DB "https://github.com/NZemlin/chess_movementor/blob/main/movementor/db.py"
            OM["Opening Moves Manager"]
            click OM "https://github.com/NZemlin/chess_movementor/blob/main/movementor/openings.py"
            SC["Web Scraper"]
            click SC "https://github.com/NZemlin/chess_movementor/blob/main/movementor/scrape.py"
            MU["Move Analysis Utils"]
            click MU "https://github.com/NZemlin/chess_movementor/tree/main/movementor/utils/move_info/"
        end
    end

    subgraph "External Components"
        SF["Stockfish Engine"]
        click SF "https://github.com/NZemlin/chess_movementor/blob/main/movementor/static/stockfish-nnue-16-single.js"
        SQL["SQLite Database"]
        click SQL "https://github.com/NZemlin/chess_movementor/blob/main/movementor/schema.sql"
    end

    %% Frontend Connections
    WB --> UI
    UI --> CB
    UI --> VH
    UI --> AF
    UI --> GC
    UI --> EV
    CB --> GM
    CB --> MM
    CB --> PM
    CB --> PH
    CB --> TM

    %% Backend Connections
    UI --> FB
    FB --> AU
    FB --> DB
    FB --> OM
    FB --> SC
    FB --> MU
    DB --> SQL
    FB --> SF

    %% Styling
    classDef frontend fill:#a8d1f0
    classDef backend fill:#90EE90
    classDef external fill:#FFB366
    classDef database fill:#FF9999

    class WB,UI,CB,GM,MM,PM,PH,TM,VH,AF,GC,EV frontend
    class FB,AU,DB,OM,SC,MU backend
    class SF external
    class SQL database
```
