# minbzk/amt architecture

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

- Interactive diagram: https://gitdiagram.com/minbzk/amt
- Repository: https://github.com/minbzk/amt

## Overview

##### Project Overview
- AMT is designed to manage and test algorithmic systems (both AI and non-AI). The project includes a web-based interface, an API backend, command-line tools (CLI), as well as a suite of supporting modules (middleware, repositories, services, models, migrations, etc.).
- The README emphasizes its web demo, CLI functionality (such as the “check-state” command), and contributions through the API endpoints.

##### Main Components (Based on the file tree structure)
- Client Side: The "amt/site/templates" directory indicates that the project uses server-side rendered pages (likely with Jinja2) and static assets (CSS/SCSS, TypeScript/JavaScript) that form the frontend UI.
- API Layer & Server: The "amt/api" directory and "amt/server.py" indicate that API endpoints are exposed, which are secured/manipulated by middleware (see "amt/middleware").
- Business Logic: Modules under "amt/core", "amt/services", and "amt/models" show where logic related to validation, data models, and service orchestration reside.
- Data Persistence: The presence of "amt/migrations", "amt/models", and database initialization scripts (in "database/") suggests an underlying relational database (possibly PostgreSQL or similar).
- CLI Tools: There is a distinct CLI package ("amt/cli"), and related tests indicate that the system’s command-line interface manages tasks such as checking algorithmic state.
- Internationalization & Localization: The "amt/locale" and "amt/languages" directories indicate a focus on supporting multiple languages.
- Testing & Continuous Integration: With extensive tests and GitHub Actions workflows (“.github/workflows/”), tests are a core part of the architecture.

##### Relationships and Interactions
- The Client (e.g., web browser) interacts with the Server, which dispatches requests to the API endpoints (found within the "amt/api" module).
- The API is layered by middleware functions (authorization, CSRF handling, route logging, etc.) before invoking business logic.
- Business logic calls services to execute operations on resources (algorithms, measures, organizations, tasks, etc.) and interact with the database.
- The CLI tool can trigger similar operations either for debugging, state checking, or administrative tasks.

##### Design Principles and Patterns
- Separation of Concerns: Clear division between API routing, middleware, business logic/services, and data persistence.
- Modular Structure: Numerous directories (such as "amt/api", "amt/core", "amt/services", "amt/repositories") suggest a modular design.
- Testing Focus: Separate test suites indicate high test coverage and intent for maintainability.
- Extensibility: The templates and internationalized language files imply that the application is designed to be adapted and extended.

##### Additional Recommendations
- Be as detailed as possible by breaking down components further if needed (for example, showing how middleware functions map to specific responsibilities like CSRF protection or authorization).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend"
        Browser("Web Browser"):::frontend
        Templates("Templates"):::frontend
        Static("Static Assets"):::frontend
        Templates --> Browser
        Static --> Browser
    end

    %% API Server & Application Logic Layer
    subgraph "API Server & Application Logic"
        HTTPServer("HTTP Server (amt/server.py)"):::api
        API("API Endpoints (amt/api)"):::api
        Middleware("Middleware Layer (amt/middleware)"):::api
        subgraph "Business Logic"
            Core("Core Logic (amt/core)"):::logic
            Services("Services (amt/services)"):::logic
        end
        HTTPServer -->|"HTTPRequests"| API
        API -->|"Calls"| Middleware
        Middleware -->|"RoutesTo"| Core
        Middleware -->|"RoutesTo"| Services
        Core -->|"Invokes"| Services
    end

    %% Data Persistence Layer
    subgraph "Data Persistence"
        DataModels("Data Models (amt/models)"):::data
        Repositories("Repositories (amt/repositories)"):::data
        Database("Database"):::data
        Migrations("Migrations (amt/migrations)"):::data
        Core -->|"CRUDOperations"| DataModels
        Services -->|"ServiceCalls"| Repositories
        DataModels -->|"DataQuery"| Database
        Repositories -->|"DataMutation"| Database
        Migrations -->|"UpdatesSchema"| Database
    end

    %% CLI Tools Layer
    subgraph "CLI Tools"
        CLI("CLI (amt/cli)"):::cli
        CLI -->|"ExecutesTasks"| HTTPServer
    end

    %% Internationalization & Localization
    subgraph "Internationalization"
        Locale("Locale (amt/locale)"):::i18n
        Languages("Languages (amt/languages)"):::i18n
    end

    %% Testing & Continuous Integration
    subgraph "Testing & CI"
        Testing("Testing (tests)"):::testing
        CI("CI (.github/workflows)"):::testing
    end

    %% Feedback arrow from Business Logic back to Middleware
    Services -.->|"Logs/Exceptions"| Middleware

    %% Interaction from Frontend to API Server
    Browser -->|"HTTPRequests"| HTTPServer

    %% Click Events
    click Templates "https://github.com/minbzk/amt/tree/main/amt/site/templates"
    click Static "https://github.com/minbzk/amt/tree/main/amt/site/static"
    click HTTPServer "https://github.com/minbzk/amt/blob/main/amt/server.py"
    click API "https://github.com/minbzk/amt/tree/main/amt/api"
    click Middleware "https://github.com/minbzk/amt/tree/main/amt/middleware"
    click Core "https://github.com/minbzk/amt/tree/main/amt/core"
    click Services "https://github.com/minbzk/amt/tree/main/amt/services"
    click DataModels "https://github.com/minbzk/amt/tree/main/amt/models"
    click Repositories "https://github.com/minbzk/amt/tree/main/amt/repositories"
    click Migrations "https://github.com/minbzk/amt/tree/main/amt/migrations"
    click CLI "https://github.com/minbzk/amt/tree/main/amt/cli"
    click Locale "https://github.com/minbzk/amt/tree/main/amt/locale"
    click Languages "https://github.com/minbzk/amt/tree/main/amt/languages"
    click Testing "https://github.com/minbzk/amt/tree/main/tests"
    click CI "https://github.com/minbzk/amt/tree/main/.github/workflows"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef api fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef logic fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef data fill:#fffacd,stroke:#000,stroke-width:2px;
    classDef cli fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef i18n fill:#e6e6fa,stroke:#000,stroke-width:2px;
    classDef testing fill:#f0e68c,stroke:#000,stroke-width:2px;
```
