# luccabb/lazy_smp architecture

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

## Overview

- Bidirectional communication between Lichess integration and the API interface
- Opening book consultation flows
- Move evaluation flows through the engine variants

##### Component Grouping

- Blue: Core engine components
- Green: Interface components
- Yellow: External integrations
- Gray: Support systems (testing, configuration)

##### Technical Details

Annotations for:
- UCI Protocol implementation
- Engine variants (Alpha-Beta, Lazy SMP)
- Elo Rating (~2000 on Lichess.org)
- Opening book integration points

##### Testing Framework (Bottom Section)
- Test components (test.py, test_bratko_kopec.py)
- Relationship to core engine components

##### Deployment Paths

Two deployment flows:
- Direct UCI engine execution
- Lichess bot deployment (via PyInstaller)

Key Architectural Considerations:

##### Modularity
- Engine variants' inheritance from base_engine.py
- Clear separation between core logic and interfaces

##### Integration Points
- UCI protocol implementation
- API endpoints for web server mode
- Lichess bot integration path

##### Configuration
- Config.py and environment configuration
- How configuration flows to different components

- Common abbreviations (UCI, API, SMP)

Level of Detail:
- Keep core engine components detailed
- Abstract away implementation details of individual algorithms
- Component interaction and data flow
- Extensibility points

Remember to include version control and build process elements as supporting components, as indicated by the presence of .gitignore, requirements.txt, and build scripts in the project structure.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef interface fill:#90EE90,stroke:#333
    classDef data fill:#FFE5B4,stroke:#333
    classDef external fill:#D3D3D3,stroke:#333
    classDef config fill:#FFA07A,stroke:#333
    classDef test fill:#DDA0DD,stroke:#333

    %% External Clients
    Client["External Clients/Tools"]:::external

    %% Interface Layer
    subgraph InterfaceLayer["Interface Layer"]
        UCI["UCI Protocol"]:::interface
        API["Web Server API"]:::interface
    end

    %% Core Engine Components
    subgraph CoreEngine["Engine Core"]
        BaseEngine["Base Engine"]:::core
        subgraph Implementations["Engine Implementations"]
            AlphaBeta["Alpha-Beta Engine"]:::core
            L1PAlpha["L1P Alpha-Beta"]:::core
            L2PAlpha["L2P Alpha-Beta"]:::core
            LazySMP["Lazy SMP Engine"]:::core
            Random["Random Engine"]:::core
        end
        MoveOrder["Move Ordering"]:::core
        PSQT["Position Square Tables"]:::core
    end

    %% Supporting Systems
    OpenBook[("Opening Book")]:::data
    Config["Configuration"]:::config
    Helper["Helper Utilities"]:::config
    LichessBot["Lichess Bot"]:::external
    Build["Build System"]:::external

    %% Testing Framework
    subgraph Testing["Testing Framework"]
        TestMain["Main Tests"]:::test
        TestBK["Bratko-Kopec Test"]:::test
    end

    %% Relationships
    Client --> UCI & API
    UCI & API --> BaseEngine
    BaseEngine --> AlphaBeta & L1PAlpha & L2PAlpha & LazySMP & Random
    BaseEngine --> OpenBook
    BaseEngine --> PSQT
    BaseEngine --> MoveOrder
    UCI & API --> Config
    API --> LichessBot
    Build --> CoreEngine
    TestMain & TestBK --> CoreEngine

    %% Click Events
    click BaseEngine "https://github.com/luccabb/lazy_smp/blob/master/engines/base_engine.py"
    click AlphaBeta "https://github.com/luccabb/lazy_smp/blob/master/engines/alpha_beta.py"
    click L1PAlpha "https://github.com/luccabb/lazy_smp/blob/master/engines/l1p_alpha_beta.py"
    click L2PAlpha "https://github.com/luccabb/lazy_smp/blob/master/engines/l2p_alpha_beta.py"
    click LazySMP "https://github.com/luccabb/lazy_smp/blob/master/engines/lazy_smp.py"
    click Random "https://github.com/luccabb/lazy_smp/blob/master/engines/random.py"
    click MoveOrder "https://github.com/luccabb/lazy_smp/blob/master/move_ordering.py"
    click PSQT "https://github.com/luccabb/lazy_smp/blob/master/psqt.py"
    click UCI "https://github.com/luccabb/lazy_smp/blob/master/mode/uci.py"
    click API "https://github.com/luccabb/lazy_smp/blob/master/mode/api.py"
    click OpenBook "https://github.com/luccabb/lazy_smp/blob/master/opening_book/cerebellum.bin"
    click Config "https://github.com/luccabb/lazy_smp/blob/master/config.py"
    click Helper "https://github.com/luccabb/lazy_smp/blob/master/helper.py"
    click LichessBot "https://github.com/luccabb/lazy_smp/tree/master/lichess/"
    click Build "https://github.com/luccabb/lazy_smp/blob/master/bin/build.sh"
    click TestMain "https://github.com/luccabb/lazy_smp/blob/master/tests/test.py"
    click TestBK "https://github.com/luccabb/lazy_smp/blob/master/tests/test_bratko_kopec.py"

    %% Legend
    subgraph Legend
        L1[" Core Components"]:::core
        L2[" Interfaces"]:::interface
        L3[" Data Stores"]:::data
        L4[" External Systems"]:::external
        L5[" Configuration"]:::config
        L6[" Testing"]:::test
    end
```
