# official-stockfish/fishtest architecture

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

## Overview

##### Main Components

a) Server Component (Central Hub):
- Web Interface (Pyramid framework, indicated by .mak templates)
- API Layer (api.py)
- Database Layer
- RunDB (rundb.py)
- UserDB (userdb.py)
- WorkerDB (workerdb.py)
- ActionDB (actiondb.py)
- Statistics Engine (stats/ directory)

b) Worker Component (Distributed Nodes):
- Worker Client (worker.py)
- Game Manager (games.py)
- Update System (updater.py)
- External Tools Integration
- Cutechess-cli
- Chess Engine Compilation

##### Test Submission Flow
- Developer → Web Interface → RunDB
##### Worker Communication Flow
- Worker → API → Task Queue → Worker
##### Game Results Flow
- Worker → API → Statistics Engine → Results Display

##### Specific Implementation Details

**┌─ Server Layer ─────────────────┐**
- ┌─ Web Interface ─┐           │
- Tests View    │           │
- User Mgmt     │           │
- Statistics    │           │
- ┘           │
- ┌─ API Layer ────┐           │
- Task Queue   │           │
- Results      │           │
- ┘           │
- ┌─ Database Layer ┐          │
- Runs         │          │
- Users        │          │
- Workers      │          │
- ┘          │
- ┘

**┌─ Worker Node ─────────────────┐**
- ┌─ Worker Client ┐           │
- Task Fetcher │           │
- Engine Comp  │           │
- ┘           │
- ┌─ Game Manager ┐           │
- Cutechess   │           │
- Results     │           │
- ┘           │
- ┘

##### Important Elements to Highlight

- SPRT Statistical Analysis (stats/sprt.py)
- Security/Authentication flow
- Task Distribution System
- Results Processing Pipeline

##### Architectural Patterns to Emphasize

- Distributed Task Queue Pattern
- Master-Worker Pattern
- RESTful API Structure
- Event-Driven Architecture

Remember to include version control integration points and the automated workflow components visible in the .github/workflows directory, as these are crucial for the continuous integration and deployment aspects of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Server["Server Component"]
        WI["Web Interface"]
        API["API Layer"]
        Views["Views Layer"]
        
        subgraph DB["Database Layer"]
            RunDB["Run Database"]
            UserDB["User Database"]
            WorkerDB["Worker Database"]
            ActionDB["Action Database"]
        end
        
        subgraph Stats["Statistics Engine"]
            SPRT["SPRT Analysis"]
            StatUtil["Statistical Utilities"]
        end
        
        subgraph Static["Static Resources"]
            JS["JavaScript"]
            CSS["CSS"]
        end
    end
    
    subgraph Workers["Worker Nodes"]
        WC["Worker Client"]
        GM["Game Manager"]
        US["Update System"]
        
        subgraph External["External Tools"]
            Cutechess["Cutechess-cli"]
            ChessEngine["Chess Engine"]
        end
    end
    
    subgraph CICD["CI/CD"]
        Workflows["GitHub Workflows"]
    end
    
    %% Relationships
    Developer -->|"Submit Test"| WI
    WI --> Views
    Views --> API
    API --> DB
    DB --> Stats
    Stats --> WI
    
    WC -->|"Request Task"| API
    API -->|"Assign Task"| WC
    WC --> GM
    GM --> Cutechess
    Cutechess --> ChessEngine
    GM -->|"Report Results"| API
    US -->|"Check Updates"| API
    
    %% Static Resource Relations
    WI --> JS
    WI --> CSS
    
    %% Component Styling
    classDef server fill:#b3d1ff
    classDef worker fill:#90EE90
    classDef external fill:#FFE5CC
    classDef database fill:#FFB366
    classDef static fill:#E6E6E6
    classDef cicd fill:#DDA0DD
    
    class WI,API,Views,Stats server
    class WC,GM,US worker
    class Cutechess,ChessEngine external
    class RunDB,UserDB,WorkerDB,ActionDB database
    class JS,CSS static
    class Workflows cicd
    
    %% Click Events
    click API "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/api.py"
    click RunDB "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/rundb.py"
    click UserDB "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/userdb.py"
    click WorkerDB "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/workerdb.py"
    click ActionDB "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/actiondb.py"
    click WI "https://github.com/official-stockfish/fishtest/tree/master/server/fishtest/templates/"
    click Stats "https://github.com/official-stockfish/fishtest/tree/master/server/fishtest/stats/"
    click SPRT "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/stats/sprt.py"
    click StatUtil "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/stats/stat_util.py"
    click WC "https://github.com/official-stockfish/fishtest/blob/master/worker/worker.py"
    click GM "https://github.com/official-stockfish/fishtest/blob/master/worker/games.py"
    click US "https://github.com/official-stockfish/fishtest/blob/master/worker/updater.py"
    click Views "https://github.com/official-stockfish/fishtest/blob/master/server/fishtest/views.py"
    click JS "https://github.com/official-stockfish/fishtest/tree/master/server/fishtest/static/js/"
    click CSS "https://github.com/official-stockfish/fishtest/tree/master/server/fishtest/static/css/"
    click Workflows "https://github.com/official-stockfish/fishtest/tree/master/.github/workflows/"
```
