# shelman2/minimal_api architecture

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

- Interactive diagram: https://gitdiagram.com/shelman2/minimal_api
- Repository: https://github.com/shelman2/minimal_api

## Overview

##### Project type and purpose
- This is a backend HTTP API built with .NET 8 using the Minimal API pattern.
- Its sole purpose is to expose a “/weather” endpoint that, given a city name, returns current weather data by calling the external OpenWeatherMap service.
- It’s structured for maintainability: dependency injection, route grouping, separation of concerns, and has unit tests (xUnit/Moq/FluentAssertions).

##### File structure
- Top-level:
- Api/             ← the web application
- Tests/           ← unit tests for business logic
- WeatherApiSolution.sln
- Api/ contains:
- Program.cs       ← entry point, builds the WebApplication
- Extensions/      ← IServiceCollection and IEndpointRouteBuilder extensions for DI and route registration
- Managers/        ← WeatherManager.cs (business logic abstraction)
- Services/        ← OpenWeatherService.cs (HTTP client wrapper for external API)
- Models/          ← WeatherResponse.cs (DTO for API output)
- appsettings*.json← configuration (API key, swagger settings)
- Tests/ contains:
- WeatherManagerTests.cs ← unit tests against WeatherManager (mocking OpenWeatherService)

##### Pulling insights from README
- Uses Minimal API (no Controllers)
- Employs DI to inject IWeatherManager and IOpenWeatherService
- Registers routes via extension methods
- Swagger UI enabled under Development
- Tests with xUnit, Moq, FluentAssertions
- Configuration-driven (appsettings.json) for OpenWeatherMap API key

##### Main components
a. Client (HTTP consumer, e.g. browser or Postman)
b. ASP.NET Core Minimal API
- Program.cs
- Route registration (RouteBuilderExtension)
- DependencyInjection setup
- Swagger UI
c. WeatherManager (business logic layer)
d. OpenWeatherService (external API adapter)
e. External OpenWeatherMap API
f. Configuration store (appsettings.json)
g. Unit test project (Tests) – optional to include

##### Relationships & data flow
1. Client → HTTP GET /weather?city={name}
2. Minimal API Endpoint → routed via RouteBuilderExtension
3. Endpoint handler resolves IWeatherManager from DI container
4. WeatherManager calls IOpenWeatherService.GetCurrentWeatherAsync(city)
5. OpenWeatherService uses HTTPClient to call OpenWeatherMap REST API
6. OpenWeatherMap responds with JSON → deserialized into internal model
7. WeatherManager maps service DTO to WeatherResponse
8. Minimal API returns WeatherResponse JSON to Client
9. Configuration (OpenWeatherApiKey) is read at startup by DI setup

##### Architectural patterns & principles
- Minimal API (no MVC controllers)
- Dependency Injection (IServiceCollection extensions)
- Separation of Concerns (API layer / Manager layer / Service layer / Model layer)
- Testability (WeatherManager unit tests with Moq)
- Configuration-driven (appsettings.json for secrets)
- Extension methods for clear route and service registration

##### Technologies & frameworks
- .NET 8, C#, ASP.NET Core Minimal API
- Swagger / Swashbuckle (dev-time API documentation)
- xUnit, Moq, FluentAssertions for unit testing
- HttpClient for external REST calls
- JSON serialization (System.Text.Json)

## Diagram (Mermaid)

```mermaid
flowchart TB
    client["Client (HTTP Consumer)"]:::external

    subgraph "ASP.NET Core Minimal API"
        Program["Program.cs (Entry Point)"]:::api
        DI["DependencyInjection Setup"]:::api
        Routes["RouteBuilderExtension"]:::api
        Swagger["Swagger UI"]:::api
    end

    subgraph "Configuration"
        Config["appsettings.json + appsettings.Development.json"]:::config
        Launch["launchSettings.json"]:::config
    end

    Manager["WeatherManager"]:::manager
    Service["OpenWeatherService"]:::service
    WeatherResponse["WeatherResponse DTO"]:::model
    External["OpenWeatherMap API"]:::externalService

    subgraph "Tests"
        Tests["WeatherManagerTests"]:::tests
    end

    Solution["WeatherApiSolution.sln"]:::solution

    client -->|"GET /weather?city={name}"| Program
    Program --> DI
    Program --> Routes
    Program --> Swagger
    Config --> Program
    Launch --> Program
    DI --> Program
    DI --> Manager
    DI --> Service
    Routes --> Program
    Program --> Manager
    Manager -->|"GetCurrentWeatherAsync(city)"| Service
    Service -->|"HTTP GET (JSON)"| External
    External -->|"JSON"| Service
    Service --> Manager
    Manager --> WeatherResponse
    WeatherResponse --> Program
    Program -->|"200 OK (JSON)"| client
    Tests --> Manager
    Solution -.-> Program
    Solution -.-> Tests

    click Program "https://github.com/shelman2/minimal_api/blob/develop/Api/Program.cs"
    click DI "https://github.com/shelman2/minimal_api/blob/develop/Api/Extensions/DependencyInjection.cs"
    click Routes "https://github.com/shelman2/minimal_api/blob/develop/Api/Extensions/RouteBuilderExtension.cs"
    click Manager "https://github.com/shelman2/minimal_api/blob/develop/Api/Managers/WeatherManager.cs"
    click Service "https://github.com/shelman2/minimal_api/blob/develop/Api/Services/OpenWeatherService.cs"
    click WeatherResponse "https://github.com/shelman2/minimal_api/blob/develop/Api/Models/WeatherResponse.cs"
    click Config "https://github.com/shelman2/minimal_api/blob/develop/Api/appsettings.json"
    click Launch "https://github.com/shelman2/minimal_api/blob/develop/Api/Properties/launchSettings.json"
    click Tests "https://github.com/shelman2/minimal_api/blob/develop/Tests/WeatherManagerTests.cs"
    click Solution "https://github.com/shelman2/minimal_api/blob/develop/WeatherApiSolution.sln"

    classDef api fill:#dae8fc,stroke:#6c8ebf
    classDef manager fill:#d5e8d4,stroke:#82b366
    classDef service fill:#ffe6cc,stroke:#d79b00
    classDef externalService fill:#f8cecc,stroke:#b85450
    classDef model fill:#ffffff,stroke:#888888
    classDef config fill:#ebebeb,stroke:#aaaaaa
    classDef tests fill:#f5e6ff,stroke:#a45cae
    classDef solution fill:#ffffff,stroke:#000000,stroke-dasharray:5 5
    classDef external fill:#fff2cc,stroke:#d6b656
```
