# romanbulgac/tsp architecture

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

- Interactive diagram: https://gitdiagram.com/romanbulgac/tsp
- Repository: https://github.com/romanbulgac/tsp

## Overview

##### Project Type and Purpose
- This is a full‐stack Clean Architecture application for solving the Traveling Salesman Problem (TSP) using a pluggable Genetic Algorithm engine.
- Frontend: Blazor WebAssembly (TspLab.Web).
- Backend/API: ASP.NET Core 8 minimal API with SignalR (TspLab.WebApi).
- Core logic: Domain, Application, Infrastructure layers.
- Testing: Unit tests and performance benchmarks (TspLab.Tests).
- Containerization and CI/CD: Docker / Docker Compose, GitHub Actions.

##### File Structure Analysis
- Top-level projects correspond to Clean Architecture layers:
- TspLab.Domain: Entities (City, Tour), interfaces (ICrossover, IMutation, IFitnessFunction), config/result models.
- TspLab.Application: Services (GeneticEngine, TspSolverService, StrategyResolver), use-case models.
- TspLab.Infrastructure: Implementations of crossover, mutation, fitness. DI extension.
- TspLab.WebApi: HTTP endpoints, SignalR hub (TspHub), minimal API setup, static Blazor assets.
- TspLab.Web: Blazor UI pages, API/SignalR clients, static assets (Chart.js visualization).
- TspLab.Tests: Unit tests and BenchmarkDotNet benchmarks.
- Build & deploy: Dockerfile, docker‐compose.yml, GitHub Actions workflow, nginx.conf.

##### Key Architectural Patterns
- Clean Architecture (six layers).
- Dependency Injection resolves strategy implementations.
- Real-time streaming via SignalR.
- Blazor WASM served by WebApi static hosting.
- Multi‐threaded fitness evaluation in GeneticEngine.

- Web Client (Blazor WASM)
- API Server (ASP.NET Core minimal API + SignalR Hub)
- Application Layer (Business logic)
- Domain Layer (Entities & Interfaces)
- Infrastructure Layer (Crossover/Mutation/Fitness)
- External Libraries/Services (Chart.js, Tailwind CSS)
- Web Client → HTTP API (GET /api/…, POST /solve)
- Web Client ↔ SignalR Hub (real-time progress)
- API Server → Application Layer (invoke use cases)
- Application → Infrastructure (strategy resolution & algorithm operations)
- Application → Domain (entities & config models)
- Infrastructure → Domain (consume City/Tour entities)
- Tests → All layers (unit & benchmark calls)
c. Architectural Patterns & Principles:
- Layered separation: no direct Web → Domain see DI flows.
- Pluggable strategies via interfaces and DI container.
- Single responsibility per project.
- Bounded contexts: Domain vs Application vs Infrastructure.
d. Technologies & Libraries:
- ASP.NET Core 8 minimal APIs, SignalR
- Blazor WebAssembly, Chart.js, Tailwind CSS
- BenchmarkDotNet, Docker, GitHub Actions

##### Essential Details to Capture
- Clean Architecture layering
- Frontend ↔ Backend communication channels (HTTP vs SignalR)
- DI strategy resolution path (Application → Infrastructure)
- Real-time visualization (Chart.js) served by WebApi static assets
- Benchmarking module as an orthogonal slice

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Swimlanes
    subgraph "Client: Blazor WASM"
        direction TB
        WC["Program.cs"]:::frontend
        Pages["Pages"]:::frontend
        ServicesWC["Services"]:::frontend
        AssetsWC["Static Assets\n(wwwroot)"]:::frontend
    end

    subgraph "Server: ASP.NET Core API"
        direction TB
        API["Program.cs"]:::backend
        Hub["TspHub"]:::backend
        ApiModels["RequestModels"]:::backend
        Static["Static Blazor Assets\n(wwwroot)"]:::backend
    end

    subgraph "Core"
        direction TB
        subgraph "Application Layer"
            App["Services\n(GeneticEngine, StrategyResolver,\nTspSolverService)"]:::application
        end
        subgraph "Domain Layer"
            Entities["Entities"]:::domain
            Interfaces["Interfaces"]:::domain
            Models["Models"]:::domain
        end
    end

    subgraph "Infrastructure"
        direction TB
        Crossover["Crossover Ops"]:::infrastructure
        Mutation["Mutation Ops"]:::infrastructure
        Fitness["Fitness Fn"]:::infrastructure
    end

    subgraph "Tests & Benchmarks"
        direction TB
        UT["Unit Tests"]:::tests
        BM["Benchmarks"]:::tests
    end

    External["External Libs:\nChart.js, Tailwind CSS"]:::external

    %% Connections
    WC -->|"HTTP (GET/POST)"| API
    WC ---|"SignalR"| Hub
    API -->|"Invoke Use Cases"| App
    App -->|"Resolves Strategies via DI"| Crossover
    App -->|"Resolves Strategies via DI"| Mutation
    App -->|"Resolves Strategies via DI"| Fitness
    App -->|"Uses Entities"| Entities
    App -->|"Uses Interfaces"| Interfaces
    App -->|"Uses Models"| Models
    Crossover -->|"Consumes Entities"| Entities
    Mutation -->|"Consumes Entities"| Entities
    Fitness -->|"Consumes Entities"| Entities
    UT -.-> Entities
    UT -.-> Interfaces
    UT -.-> Models
    UT -.-> App
    UT -.-> Crossover
    UT -.-> Mutation
    UT -.-> Fitness
    UT -.-> API
    UT -.-> WC
    BM -.-> App
    BM -.-> Crossover
    BM -.-> Mutation
    BM -.-> Fitness

    %% Click Events
    click Entities "https://github.com/romanbulgac/tsp/tree/main/TspLab.Domain/Entities"
    click Interfaces "https://github.com/romanbulgac/tsp/tree/main/TspLab.Domain/Interfaces"
    click Models "https://github.com/romanbulgac/tsp/tree/main/TspLab.Domain/Models"
    click App "https://github.com/romanbulgac/tsp/tree/main/TspLab.Application/Services"
    click Crossover "https://github.com/romanbulgac/tsp/tree/main/TspLab.Infrastructure/Crossover"
    click Mutation "https://github.com/romanbulgac/tsp/tree/main/TspLab.Infrastructure/Mutation"
    click Fitness "https://github.com/romanbulgac/tsp/tree/main/TspLab.Infrastructure/Fitness"
    click API "https://github.com/romanbulgac/tsp/blob/main/TspLab.WebApi/Program.cs"
    click Hub "https://github.com/romanbulgac/tsp/blob/main/TspLab.WebApi/Hubs/TspHub.cs"
    click ApiModels "https://github.com/romanbulgac/tsp/blob/main/TspLab.WebApi/Models/RequestModels.cs"
    click Static "https://github.com/romanbulgac/tsp/tree/main/TspLab.WebApi/wwwroot"
    click WC "https://github.com/romanbulgac/tsp/blob/main/TspLab.Web/Program.cs"
    click Pages "https://github.com/romanbulgac/tsp/tree/main/TspLab.Web/Pages"
    click ServicesWC "https://github.com/romanbulgac/tsp/tree/main/TspLab.Web/Services"
    click AssetsWC "https://github.com/romanbulgac/tsp/tree/main/TspLab.Web/wwwroot"
    click UT "https://github.com/romanbulgac/tsp/blob/main/TspLab.Tests/UnitTest1.cs"
    click BM "https://github.com/romanbulgac/tsp/blob/main/TspLab.Tests/Benchmarks/GeneticAlgorithmBenchmarks.cs"
    click Dockerfile "https://github.com/romanbulgac/tsp/tree/main/Dockerfile"
    click DockerCompose "https://github.com/romanbulgac/tsp/blob/main/docker-compose.yml"
    click Nginx "https://github.com/romanbulgac/tsp/blob/main/nginx.conf"
    click CI "https://github.com/romanbulgac/tsp/blob/main/.github/workflows/ci-cd.yml"
    click DevContainer "https://github.com/romanbulgac/tsp/blob/main/.devcontainer/devcontainer.json"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#4d94ff;
    classDef backend fill:#d6f5d6,stroke:#33cc33;
    classDef application fill:#fff2cc,stroke:#ffcc00;
    classDef domain fill:#f2dede,stroke:#d9534f;
    classDef infrastructure fill:#fcf8e3,stroke:#ec971f;
    classDef tests fill:#eeeeee,stroke:#999999,stroke-dasharray: 5 5;
    classDef external fill:#e6e6ff,stroke:#6666ff;
```
