# svenplb/aace architecture

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

- Interactive diagram: https://gitdiagram.com/svenplb/aace
- Repository: https://github.com/svenplb/aace

## Overview

##### Main components
- Main Entry Point: Represented by main.go, which is the starting script that bootstraps the engine.
- Router Component: Found in router/main.go, this module seems to handle the API routing, taking care of interactions between the external calls and internal application logic.
- Handlers: The handlers/ directory contains modules for board evaluation and move search (evaluate.go, evaluate_old.go, search.go, and search_old.go). These are the core functional units responsible for calculating board evaluations and constructing the search trees using chess algorithms.
- Application Setup: The app/setup.go file appears to handle initialization or configuration settings required to start or maintain the engine environment.

##### Relationships and interactions
- The entry point (main.go) initializes the application, calling the setup routines from app/setup.go.
- It then configures the router, defined in router/main.go, which maps incoming API calls (or system-level events) to the appropriate handlers.
- The API endpoints routed to handlers then invoke the specific logic related to chess piece evaluation and search algorithms. You might want to illustrate the interaction between:
- API Call → Router → Evaluation Handler (evaluate.go) for board state assessments.
- API Call → Router → Search Handler (search.go) for move generation (with support to potentially compare or fall back to old logic as indicated by evaluate_old.go and search_old.go).

##### Architectural patterns and design principles
- Modularity: The separation into distinct directories for setup (app), API routing (router), and core chess logic (handlers) suggests a modular design.
- Separation of Concerns: Distinct responsibilities are clearly allocated (initialization, routing, core algorithms) making it easier to maintain and extend.
- Version/Legacy Code: The presence of “old” versions of evaluation and search handlers could imply that the engine developers retain older versions for reference or rollback, which is important for understanding the evolution of the algorithms.

##### Relevant technologies and frameworks
- Programming Language: Go (Golang) is the core language used.
- Web/API Framework: Although not explicitly named, the separation into router and handlers suggests use of an HTTP router which might be one of Go's standard libraries or a framework like Gin or Echo if integrated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Initialization Layer
    subgraph "Initialization Layer"
        MAIN("Main Application (main.go)"):::main
        SETUP("Setup & Configuration (app/setup.go)"):::setup
        MAIN -->|"initialize"| SETUP
    end

    %% API Layer
    subgraph "API Layer"
        ROUTER("API Router (router/main.go)"):::router
        SETUP -->|"configureRouter"| ROUTER
    end

    %% Handlers Layer
    subgraph "Handlers Layer"
        %% Active Handlers
        subgraph "Active Handlers"
            EVAL("Evaluation Handler (handlers/evaluate.go)"):::handler
            SEARCH("Search Handler (handlers/search.go)"):::handler
            ROUTER -->|"routeToEval"| EVAL
            ROUTER -->|"routeToSearch"| SEARCH
        end
        %% Legacy Handlers
        subgraph "Legacy Handlers"
            EVAL_OLD("Legacy Evaluation (handlers/evaluate_old.go)"):::legacy
            SEARCH_OLD("Legacy Search (handlers/search_old.go)"):::legacy
            EVAL ---|"fallback"| EVAL_OLD
            SEARCH ---|"fallback"| SEARCH_OLD
        end
    end

    %% Click Events
    click MAIN "https://github.com/svenplb/aace/blob/main/main.go"
    click SETUP "https://github.com/svenplb/aace/blob/main/app/setup.go"
    click ROUTER "https://github.com/svenplb/aace/blob/main/router/main.go"
    click EVAL "https://github.com/svenplb/aace/blob/main/handlers/evaluate.go"
    click EVAL_OLD "https://github.com/svenplb/aace/blob/main/handlers/evaluate_old.go"
    click SEARCH "https://github.com/svenplb/aace/blob/main/handlers/search.go"
    click SEARCH_OLD "https://github.com/svenplb/aace/blob/main/handlers/search_old.go"

    %% Styles
    classDef main fill:#FFCCFF,stroke:#333,stroke-width:2px;
    classDef setup fill:#CCEEFF,stroke:#333,stroke-width:2px;
    classDef router fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef handler fill:#FFF0B3,stroke:#333,stroke-width:2px;
    classDef legacy fill:#E0E0E0,stroke:#333,stroke-dasharray: 5 5,stroke-width:2px;
```
