# guiriosoficial/tmb-challenge-api architecture

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

- Interactive diagram: https://gitdiagram.com/guiriosoficial/tmb-challenge-api
- Repository: https://github.com/guiriosoficial/tmb-challenge-api

## Overview

##### Project type and purpose
- This is a .NET 9 Back-End API for the “TMB-Challenge.”
- It exposes REST endpoints (OrdersController) and a WebSocket endpoint (WebSocketController).
- It persists data to a PostgreSQL database (via Entity Framework Core) and integrates with Azure Service Bus for asynchronous order processing.

##### File structure
- Top-level entry: `Program.cs` configures services and middleware.
- Config/ holds external service configurations (AzureServiceBus, JSON serializer).
- Controllers/ handle HTTP and WS requests.
- Data/ defines the EF Core `ApplicationDbContext`.
- Repositories/Interfaces + Implementations implement the Repository pattern, abstracting data access.
- Services/Interfaces + Implementations implement business logic.
- Workers/ contains background services (OrderWorker) consuming from Azure Service Bus.
- Migrations/ define the EF schema versions.
- `appsettings.*.json` + `.env` drive configuration.
- `docker-compose.yml` orchestrates API, DB, and migrator profiles.

##### Key architectural insights from README
- Layered architecture: Controllers → Services → Repositories → Database.
- Async processing with Azure Service Bus queue.
- Real-time updates via WebSocket.
- Supports Docker-based deployment with profiles for migrations and app.

##### Detail
- Configuration entry points (`appsettings.json`, `.env`).
- Don’t omit the Azure Service Bus integration and Worker component—they’re central to the async processing requirement.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    ClientApp["Frontend Application"]:::external

    %% API Container
    subgraph "ASP.NET Core API"
        subgraph "Controllers"
            OC["OrdersController"]:::api
            WSC["WebSocketController"]:::api
        end
        subgraph "Services"
            OSvc["OrderService"]:::business
            WSvc["WebSocketService"]:::realtime
        end
        subgraph "Repositories"
            IOR["IOrderRepository"]:::data
            OR["OrderRepository"]:::data
        end
        ADC["ApplicationDbContext"]:::data
        ConfigJSON["JsonSerializerConfig"]:::config
        ConfigASB["AzureServiceBusOptions"]:::config
    end

    %% External Systems
    Postgres[(PostgreSQL Database)]:::database
    ASB[(Azure Service Bus Queue)]:::queue

    %% Worker Container
    subgraph "Background Worker"
        Worker["OrderWorker"]:::worker
    end

    %% Configuration & Deployment
    Program["Program.cs"]:::config
    DockerCompose["docker-compose.yml"]:::infra
    Dockerfile["Dockerfile"]:::infra
    AppSettings["appsettings*.json & .env"]:::config
    Migrations["EF Core Migrations"]:::config

    %% Data Models
    OrderModel["Order (Model)"]:::data
    OrderDto["OrderDto"]:::data

    %% Connections
    ClientApp -->|"HTTP POST /api/orders"| OC
    ClientApp -->|"WebSocket /ws"| WSC

    OC -->|"injects IOrderService"| OSvc
    WSC -->|"injects IWebSocketService"| WSvc

    OSvc -->|"calls IOrderRepository"| IOR
    WSvc -->|"pushes updates"| ClientApp

    IOR -->|"implemented by"| OR
    OR -->|"uses"| ADC
    ADC -->|"SQL operations"| Postgres

    OSvc -->|"sends message"| ASB
    Worker -->|"consumes message"| ASB
    Worker -->|"uses IOrderService"| OSvc
    Worker -->|"updates DB via"| OR

    %% Config & Deployment Flows
    Program --> ConfigJSON
    Program --> ConfigASB
    Program --> ADC
    Program --> OC
    Program --> WSC
    DockerCompose --> Program
    DockerCompose --> Postgres
    DockerCompose --> Worker
    Program --> Migrations
    AppSettings --> Program

    %% Click Events
    click OC "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Controllers/OrdersController.cs"
    click WSC "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Controllers/WebSocketController.cs"
    click ADC "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Data/ApplicationDbContext.cs"
    click IOR "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Repositories/Interfaces/IOrderRepository.cs"
    click OR "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Repositories/Implementations/OrderRepository.cs"
    click OSvc "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Services/Implementations/OrderService.cs"
    click WSvc "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Services/Implementations/WebSocketService.cs"
    click Worker "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Workers/OrderWorker.cs"
    click ConfigASB "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Config/AzureServiceBusOptions.cs"
    click ConfigJSON "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Config/JsonSerializerConfig.cs"
    click Migrations "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Migrations/20250606215615_InitialMigration.cs"
    click Migrations "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Migrations/20250606215615_InitialMigration.Designer.cs"
    click Migrations "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Migrations/ApplicationDbContextModelSnapshot.cs"
    click Program "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/Program.cs"
    click DockerCompose "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/docker-compose.yml"
    click Dockerfile "https://github.com/guiriosoficial/tmb-challenge-api/tree/main/Dockerfile"
    click AppSettings "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/appsettings.json"
    click AppSettings "https://github.com/guiriosoficial/tmb-challenge-api/blob/main/appsettings.Development.json"

    %% Styles
    classDef external fill:#f0f0f0,stroke:#999,stroke-width:1px
    classDef api fill:#cce5ff,stroke:#3399ff,stroke-width:2px
    classDef business fill:#e6f7ff,stroke:#66b2ff,stroke-width:2px
    classDef data fill:#e6ffe6,stroke:#33cc33,stroke-width:2px
    classDef database fill:#d9ead3,stroke:#6aa84f,stroke-width:2px
    classDef queue fill:#d9d2e9,stroke:#8e7cc3,stroke-width:2px
    classDef worker fill:#ffe6cc,stroke:#ff9933,stroke-width:2px
    classDef realtime fill:#f4cccc,stroke:#cc0000,stroke-width:2px
    classDef config fill:#fff2cc,stroke:#ffcc00,stroke-width:2px
    classDef infra fill:#d9d9d9,stroke:#999999,stroke-width:2px
```
