# ciekce/stormphrax architecture

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

## Overview

##### Core Engine Components
- UCI Interface (src/uci.*)
- Search Engine (src/search.*)
- Move Generation (src/movegen.*)
- Management (src/position/*)
- Evaluation System (src/eval/*)

##### NNUE Architecture (Critical Component)
- Input Layer (768x16)
- Hidden Layer (1280)
- Output Layer (1x8)
- Horizontal Mirroring

##### Attack Generation System
- BMI2 Implementation (src/attacks/bmi2/*)
- Black Magic Implementation (src/attacks/black_magic/*)
- Use conditional paths to show CPU-dependent selection

##### Supporting Systems
- Transposition Table (src/ttable.*)
- Syzygy Tablebase Integration (src/tb.*)
- Thread Management (indicated by Threads UCI option)
- Time Management (src/limit/*)

##### Layer the Components
Top: UCI Interface
Middle: Core Engine (search, position, moves)
Bottom: Supporting Systems (NNUE, tablebases, attack generation)

##### Data Flow
- Double lines: Critical paths

##### Technical Details
- CPU feature requirements (AVX2, BMI2, etc.)
- Memory management (Hash size)
- Threading model (Lazy SMP)

##### Time Management → Search Control

- Component types (Core, Supporting, External)
- Special symbols

Remember to include version information and CPU feature requirements as metadata, as these are critical for deployment decisions.

This design should be created using a professional diagramming tool that supports UML or similar notation, with careful attention to layout and spacing for clarity.

## Diagram (Mermaid)

```mermaid
graph TB
    classDef core fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef nnue fill:#90EE90,stroke:#333,stroke-width:2px
    classDef perf fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px

    subgraph Interface
        UCI["UCI Interface"]:::external
    end
    click UCI "https://github.com/Ciekce/Stormphrax/blob/main/src/uci.h"

    subgraph Core
        Search["Search Engine"]:::core
        Position["Position Management"]:::core
        MoveGen["Move Generation"]:::core
    end
    click Search "https://github.com/Ciekce/Stormphrax/blob/main/src/search.h"
    click Position "https://github.com/Ciekce/Stormphrax/blob/main/src/position/position.h"
    click MoveGen "https://github.com/Ciekce/Stormphrax/blob/main/src/movegen.h"

    subgraph "Attack System"
        AttackChoice{"CPU Features"}
        BMI2["BMI2 Implementation"]:::perf
        BlackMagic["Black Magic Implementation"]:::perf
    end
    click BMI2 "https://github.com/Ciekce/Stormphrax/tree/main/src/attacks/bmi2/"
    click BlackMagic "https://github.com/Ciekce/Stormphrax/tree/main/src/attacks/black_magic/"

    subgraph "NNUE Evaluation"
        InputLayer["Input Layer (768x16)"]:::nnue
        HiddenLayer["Hidden Layer (1280)"]:::nnue
        OutputLayer["Output Layer (1x8)"]:::nnue
        Mirror["Horizontal Mirroring"]:::nnue
    end
    click InputLayer "https://github.com/Ciekce/Stormphrax/blob/main/src/eval/nnue/input.h"
    click OutputLayer "https://github.com/Ciekce/Stormphrax/blob/main/src/eval/nnue/output.h"

    subgraph "Supporting Systems"
        TTable["Transposition Table"]:::perf
        Syzygy["Syzygy Tablebase"]:::external
        TimeManagement["Time Management"]:::core
        ThreadManagement["Thread Management"]:::core
    end
    click TTable "https://github.com/Ciekce/Stormphrax/blob/main/src/ttable.h"
    click Syzygy "https://github.com/Ciekce/Stormphrax/blob/main/src/tb.h"
    click TimeManagement "https://github.com/Ciekce/Stormphrax/blob/main/src/limit/time.h"
    click ThreadManagement "https://github.com/Ciekce/Stormphrax/blob/main/src/util/barrier.h"

    UCI --> Search
    Search --> Position
    Search --> MoveGen
    Position --> MoveGen
    
    AttackChoice -->|Has BMI2| BMI2
    AttackChoice -->|No BMI2| BlackMagic
    BMI2 --> MoveGen
    BlackMagic --> MoveGen

    Position --> InputLayer
    InputLayer --> HiddenLayer
    HiddenLayer --> OutputLayer
    Mirror --> OutputLayer
    OutputLayer --> Search

    Search <--> TTable
    Search --> Syzygy
    TimeManagement --> Search
    ThreadManagement --> Search

    %% Legend
    classDef legendBox fill:#fff,stroke:#333,stroke-width:1px
    subgraph Legend
        L1["Core Components"]:::core
        L2["NNUE Components"]:::nnue
        L3["Performance Critical"]:::perf
        L4["External Systems"]:::external
    end
```
