# captainsafia/minapi-sse architecture

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

- Interactive diagram: https://gitdiagram.com/captainsafia/minapi-sse
- Repository: https://github.com/captainsafia/minapi-sse

## Overview

##### Main Components
- API Server:
- Represented by Program.cs, which is the main entry point of the application.
- Configured via the MinimalServerSentEvents.csproj and the global.json (to align .NET tooling).
- Endpoints and SSE Logic:
- Minimal API endpoints that expose paths such as “/string-item”, “/json-item”, and “/sse-item” (and the sample “/sse-endpoint” shown in the README).
- That these endpoints use the TypedResults.ServerSentEvents API to stream data to clients.
- Configuration Components:
- “appsettings.json” and “appsettings.Development.json” which supply configuration details (i.e., hosting settings, logging, etc.).
- The “Properties/launchSettings.json” outlines the local development environment settings (such as ports and environment variables).
- External Clients:
- External consumers (or browsers) that connect to the API endpoints to receive streamed data.
- Framework & Libraries:
- That the system leverages .NET minimal API, ASP.NET Core hosting, and built-in configuration with dependency injection.

##### Relationships and Interactions
- Inside the API Server, indicate that incoming HTTP requests are processed by minimal API route handlers defined in Program.cs.
- Points where data is “streamed” back to the client using SSE (via the TypedResults.ServerSentEvents abstraction) should be clearly shown, with a note on the continuous asynchronous stream mechanism (using IAsyncEnumerable).
- Cancellation token mechanism flowing from the ASP.NET Core HTTP context into the SSE logic, ensuring proper cleanup.

##### Important Architectural Patterns and Design Principles
- Minimal API Pattern:
- That the project leverages the minimal API style, meaning it does not employ the MVC pattern or controllers; all endpoint mappings are done directly in Program.cs.
- Event Streaming:
- Use of server-sent events as a streaming method, with considerations for long-lived HTTP connections.
- Configuration & Environment Separation:
- Separate treatment of configuration files (appsettings.json vs. appsettings.Development.json) based on the environment.

##### Relevant Technologies and Tools
- .NET 10 Preview 3 and the Minimal APIs feature.
- ASP.NET Core hosting (for managing HTTP requests/responses).
- TypedResults for handling strongly-typed HTTP responses, especially for SSE.
- The use of global.json to specify tooling versions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration & Build Components
    subgraph "Configuration & Build"
        PC1["Project Config: MinimalServerSentEvents.csproj"]:::config
        GT["Tooling: global.json"]:::config
        AC1["App Configuration: appsettings.json"]:::config
        AC2["App Configuration: appsettings.Development.json"]:::config
        LS["Local Dev Settings: Properties/launchSettings.json"]:::config
    end

    %% API Server with Endpoints and SSE Logic
    subgraph "API Server"
        PS["Program.cs (Minimal API Entry & SSE Logic)"]:::api
        subgraph "Endpoints"
            E1["Endpoint: /string-item"]:::api
            E2["Endpoint: /json-item"]:::api
            E3["Endpoint: /sse-item"]:::api
            E4["Endpoint: /sse-endpoint"]:::api
        end
    end

    %% External Client
    EC["HTTP Client"]:::external

    %% Interactions
    EC -->|"HTTP_Request"| PS
    PS -->|"routes_to"| E1
    PS -->|"routes_to"| E2
    PS -->|"routes_to"| E3
    PS -->|"routes_to"| E4
    E4 -->|"Streams_SSE_Data"| EC
    EC -->|"CancellationToken"| PS

    %% Dependencies from Configuration & Build to API Server
    PC1 -->|"configures"| PS
    GT -->|"configures"| PS
    AC1 -->|"configures"| PS
    AC2 -->|"configures"| PS
    LS -->|"configures"| PS

    %% Click Events for Mapped Components
    click PS "https://github.com/captainsafia/minapi-sse/blob/main/Program.cs"
    click PC1 "https://github.com/captainsafia/minapi-sse/blob/main/MinimalServerSentEvents.csproj"
    click GT "https://github.com/captainsafia/minapi-sse/blob/main/global.json"
    click AC1 "https://github.com/captainsafia/minapi-sse/blob/main/appsettings.json"
    click AC2 "https://github.com/captainsafia/minapi-sse/blob/main/appsettings.Development.json"
    click LS "https://github.com/captainsafia/minapi-sse/blob/main/Properties/launchSettings.json"

    %% Styles
    classDef api fill:#bbf,stroke:#333,stroke-width:2px;
    classDef config fill:#ffd,stroke:#333,stroke-width:2px;
    classDef external fill:#cfc,stroke:#333,stroke-width:2px;
```
