# fbadaro/rinha1-conc-net1 architecture

> Architecture diagram of the GitHub repository fbadaro/rinha1-conc-net1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fbadaro/rinha1-conc-net1
- Repository: https://github.com/fbadaro/rinha1-conc-net1

## Overview

##### Project Type and Purpose
- This is a standalone backend microservice (Minimal API) implemented in C#/.NET 7.
- It is designed to run entirely in Docker containers, orchestrated by Docker Compose, exposing an HTTP API behind an NGINX reverse proxy.
- It uses TDD (xUnit) for integration tests, and includes background processing via hosted services (queue consumer, record sync).

##### File Structure
- Top-level “src” folder contains two projects:
- RinhaBackEnd – the production API service
- RinhaBackEnd.Test – the xUnit integration tests (runs against real containers)
- Dock­er artifacts: Dockerfile, .dockerignore, docker-compose.yml (plus override/testing), nginx.conf, run.sh
- App code organized into Domain, Dtos (Requests/Responses), Extensions, HostedServices, Middlewares, Program.cs
- Tests mirror controllers and domain logic under RinhaBackEnd.Test
- External resources defined in docker-compose: Postgres, Redis, NGINX

##### README for Additional Insights
- Technologies: .NET 7 Minimal API, Swagger, xUnit, Docker Compose, Redis cache, NGINX load balancer, Postgres
- Endpoints: health check, CRUD for “People” stored in Postgres, simple search and count
- Stress test via Postman collection

##### Key Points to Emphasize
- Both synchronous request/response paths and asynchronous hosted-service flows.
- How TDD/integration testing fits into the same architecture.
- Don’t overcomplicate: break the system into these core components and their interactions.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients and Tests
    Client["Client (Browser/Postman)"]:::external
    IntegrationTests["Integration Tests (xUnit)"]:::external
    StressTest["Stress Test (Postman)"]:::external

    %% Docker Compose Network
    subgraph "Docker Compose Network" 
        direction TB
        NGINX["NGINX Reverse Proxy"]:::infra
        APIContainer["RinhaBackEnd Container"] 
        Postgres["Postgres DB"]:::datastore
        Redis["Redis Cache"]:::datastore
    end

    %% API Container Internal Structure
    subgraph "RinhaBackEnd Container"
        direction TB
        Program["Program.cs"]:::api
        Csproj["RinhaBackEnd.csproj"]:::api
        subgraph "Middlewares"
            LogMiddleware["LogHeadersMiddleware"]:::api
        end
        subgraph "Extensions"
            JsonExt["JsonExtensions"]:::api
            QueueExt["QueueExtensions"]:::api
            ExceptionExt["RequestException"]:::api
        end
        subgraph "DTOs"
            ReqDTO["PersonRequest"]:::api
            ResDTO["PersonResponse"]:::api
        end
        DomainEntity["Person.cs"]:::api
        subgraph "Hosted Services"
            QueueConsumer["QueueConsumerHostedService"]:::api
            SyncRecord["SyncRecordHostedService"]:::api
        end
    end

    %% Connections
    Client -->|"HTTP"| NGINX
    IntegrationTests -->|"HTTP"| NGINX
    StressTest -->|"HTTP"| NGINX
    NGINX -->|"Proxy"| Program
    Program -->|"CRUD"| Postgres
    Program -->|"Cache GET/SET"| Redis
    QueueConsumer -->|"Sync"| Postgres
    SyncRecord -->|"Sync"| Postgres

    %% Click Events
    click Program "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Program.cs"
    click Csproj "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/RinhaBackEnd.csproj"
    click DomainEntity "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Domain/Person.cs"
    click ReqDTO "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Dtos/Requests/PersonRequest.cs"
    click ResDTO "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Dtos/Response/PersonResponse.cs"
    click JsonExt "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Extensions/JsonExtensions.cs"
    click QueueExt "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Extensions/QueueExtensions.cs"
    click ExceptionExt "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Extensions/RequestException.cs"
    click LogMiddleware "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/Midlewares/LogHeadersMiddleware.cs"
    click QueueConsumer "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/HostedServices/QueueConsumerHostedService.cs"
    click SyncRecord "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd/HostedServices/SyncRecordHostedService.cs"
    click IntegrationTests "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd.Test/RinhaBackEnd.Test.csproj"
    click IntegrationTests "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd.Test/Controllers/PeopleControllerTest.cs"
    click IntegrationTests "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd.Test/Domain/PersonTests.cs"
    click IntegrationTests "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd.Test/ContainerFixture.cs"
    click IntegrationTests "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/RinhaBackEnd.Test/Collections.cs"
    click NGINX "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/nginx.conf"
    click APIContainer "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/run.sh"
    click Postgres "https://github.com/fbadaro/rinha1-conc-net1/blob/main/src/create-script.sql"
    click StressTest "https://github.com/fbadaro/rinha1-conc-net1/blob/main/test/stress/RinhaBackEnd.postman_collection.json"

    %% Styles
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef infra fill:#90EE90,stroke:#333,stroke-width:1px
    classDef api fill:#FFD580,stroke:#333,stroke-width:1px
    classDef datastore fill:#DDA0DD,stroke:#333,stroke-width:1px
```
