# mehdihadeli/vertical-slice-api-template architecture

> Architecture diagram of the GitHub repository mehdihadeli/vertical-slice-api-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mehdihadeli/vertical-slice-api-template
- Repository: https://github.com/mehdihadeli/vertical-slice-api-template

## Overview

##### Project type and purpose
- This is an ASP .NET Core “Vertical Slice API Template” implementing a feature-driven, CQRS-based, minimal-API style monolith (or microservices) template.
- It serves as a starting point for building RESTful services with built-in support for Postgres (via EF Core), OpenTelemetry (traces, metrics, logs), messaging (RabbitMQ), caching (Redis), health checks, and Docker/Kubernetes orchestration.

##### Key high-level directories (and what they imply
- src/App/Vertical.Slice.Template.Api: the HTTP service (Minimal APIs entry point)
- src/App/Vertical.Slice.Template: the domain/features assembly (vertical slices under Products, Shared modules)
- src/ApiClients: generated/hand-rolled clients for external services (ConnectedServiceClients, KiotaClients)
- Shared/*: common abstractions and infrastructure (CQRS interfaces, caching, messaging, EF Core base, observability, resiliency, OpenAPI, etc.)
- deployments/: Docker-Compose and Kubernetes YAMLs for infrastructure (Postgres, Redis, RabbitMQ, OpenTelemetry Collector, Grafana, Prometheus, Loki, Jaeger/Tempo, Zipkin)
- tests/: multi-level tests covering unit, integration, contract, end-to-end, load tests

##### Architectural patterns & flows
- Vertical Slice + CQRS: each feature implements its own command/query, handler, endpoint, DTOs, and domain entities in its own folder.
- Minimal API entry: Program.cs wires up slices via WebApplicationBuilderExtensions.
- MediatR pipeline behaviors for validation, caching, logging, observability.
- Infrastructure adapters (EF Core repositories, Redis cache, MassTransit for RabbitMQ).
- External API clients (REST or Kiota) represented in Shared/Clients and ApiClients projects.
- Observability pipeline: OpenTelemetry Collector aggregates traces/metrics/logs and exports to Jaeger/Tempo (traces), Prometheus (metrics), Loki/Kibana (logs).
- Deployment: orchestrated via PM2 or Microsoft Tye for local development; Docker Compose and Kubernetes for production.

##### Main components
A. API Service
- Minimal API host (Program.cs)
- Slices (Products, Catalogs)
- Shared infrastructure (EF Core, MediatR, FluentValidation, pipelines)
B. Data stores
- PostgreSQL (CatalogsDbContext, Products schema)
- Redis (caching, pub-sub)
C. Messaging
- RabbitMQ (integration events) via MassTransit
D. External dependencies
- External Catalogs API clients (ConnectedServiceClients/KiotaClients)
E. Observability
- OpenTelemetry Collector
- Jaeger/Tempo (tracing)
- Prometheus (metrics)
- Loki/Kibana (logs)
- Grafana (dashboard)
F. Orchestration/Deployment
- Docker Compose / Kubernetes (pods for each service and infra)
- Tye dashboard / PM2 process manager

##### Relationships & data flows
- HTTP Request → Minimal API endpoint → MediatR Command/Query → Handler
- Handler may:
- Query Postgres via EF Core repository
- Publish or consume integration events via RabbitMQ
- Cache or retrieve from Redis
- Call external Catalogs API via generated client
- Every pipeline stage emits telemetry to the OpenTelemetry Collector
- Collector forwards traces to Jaeger/Tempo, metrics to Prometheus, logs to Loki

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application" 
        direction TB
        API["API Service\n(Minimal API host)"]:::runtime
        Products["Products Slice\n(vertical features CQRS)"]:::code
        SharedApp["Shared Modules\n(application infrastructure)"]:::code
        ClientsGroup["API Clients"]:::code
        CSClients["ConnectedServiceClients"]:::code
        KiotaClients["KiotaClients"]:::code
        Pipeline["MediatR Pipeline Behaviors\n(Validation, Caching, Logging, Observability)"]:::code
    end

    %% Data & Messaging Layer
    subgraph "Data & Messaging"
        direction TB
        Postgres["PostgreSQL\n(CatalogsDbContext)"]:::runtime
        Redis["Redis Cache & Pub-Sub"]:::runtime
        RabbitMQ["RabbitMQ\n(MassTransit)"]:::runtime
    end

    %% Observability Layer
    subgraph "Observability"
        direction TB
        OTel["OpenTelemetry Collector"]:::infra
        Jaeger["Jaeger/Tempo\n(Tracing)"]:::infra
        Prometheus["Prometheus\n(Metrics)"]:::infra
        Loki["Loki\n(Logs)"]:::infra
        Grafana["Grafana\n(Dashboards)"]:::infra
    end

    %% Deployment Layer
    subgraph "Deployment"
        direction TB
        DockerCompose["Docker Compose"]:::deployment
        Kubernetes["Kubernetes"]:::deployment
        Tye["Tye Dashboard"]:::deployment
        PM2["PM2"]:::deployment
    end

    %% Relationships
    HTTPClient["HTTP Client"]:::external -->|HTTP Request| API
    API -->|"uses"| Products
    API -->|"uses"| SharedApp
    API -->|"invokes"| Pipeline
    API -->|"calls"| Postgres
    API -->|"calls"| Redis
    API -->|"publishes/subscribes"| RabbitMQ
    API -->|"calls"| CSClients
    API -->|"calls"| KiotaClients

    API -->|sends telemetry| OTel
    Postgres -->|sends telemetry| OTel
    Redis -->|sends telemetry| OTel
    RabbitMQ -->|sends telemetry| OTel

    OTel -->|"traces"| Jaeger
    OTel -->|"metrics"| Prometheus
    OTel -->|"logs"| Loki
    Grafana -->|"visualizes"| Prometheus
    Grafana -->|"visualizes"| Loki

    DockerCompose -->|deploys| API
    DockerCompose -->|deploys| Postgres
    DockerCompose -->|deploys| Redis
    DockerCompose -->|deploys| RabbitMQ
    DockerCompose -->|deploys| OTel
    DockerCompose -->|deploys| Jaeger
    DockerCompose -->|deploys| Prometheus
    DockerCompose -->|deploys| Loki
    DockerCompose -->|deploys| Grafana

    Kubernetes -->|deploys| API
    Kubernetes -->|deploys| Postgres
    Kubernetes -->|deploys| Redis
    Kubernetes -->|deploys| RabbitMQ
    Kubernetes -->|deploys| OTel
    Kubernetes -->|deploys| Jaeger
    Kubernetes -->|deploys| Prometheus
    Kubernetes -->|deploys| Loki
    Kubernetes -->|deploys| Grafana

    Tye -->|manages| API
    PM2 -->|manages| API

    %% Client grouping arrows
    ClientsGroup --> CSClients
    ClientsGroup --> KiotaClients
    API --> ClientsGroup

    %% Click Events
    click API "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/App/Vertical.Slice.Template.Api/Program.cs"
    click Products "https://github.com/mehdihadeli/vertical-slice-api-template/tree/main/src/App/Vertical.Slice.Template/Products"
    click SharedApp "https://github.com/mehdihadeli/vertical-slice-api-template/tree/main/src/App/Vertical.Slice.Template/Shared"
    click CSClients "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/ApiClients/Vertical.Slice.Template.ConnectedServiceClients"
    click KiotaClients "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/ApiClients/Vertical.Slice.Template.KiotaClients"
    click Postgres "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/App/Vertical.Slice.Template/Shared/Data/CatalogsDbContext.cs"
    click Redis "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/Shared/Cache/RedisPubSubService.cs"
    click RabbitMQ "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/Shared/Messaging.MassTransit/MasstransitExternalBus.cs"
    click OTel "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/deployments/configs/otel-collector-config.yaml"
    click Jaeger "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/deployments/k8s/jaeger.yaml"
    click Prometheus "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/deployments/k8s/prometheus.yaml"
    click Loki "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/deployments/k8s/loki.yaml"
    click Grafana "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/deployments/k8s/grafana.yaml"
    click DockerCompose "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/deployments/docker-compose/docker-compose.infrastructure.yaml"
    click Kubernetes "https://github.com/mehdihadeli/vertical-slice-api-template/tree/main/deployments/k8s/"
    click Tye "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/tye.yaml"
    click PM2 "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/pm2.yaml"
    click Pipeline "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/Shared/Validation/RequestValidationBehavior.cs"
    click Pipeline "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/Shared/Cache/Behaviors/CachingBehavior.cs"
    click Pipeline "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/Shared/Observability/Behaviors/ObservabilityPipelineBehavior.cs"
    click Pipeline "https://github.com/mehdihadeli/vertical-slice-api-template/blob/main/src/Shared/Logging/LoggingBehavior.cs"

    %% Styles
    classDef runtime fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef infra fill:#E6F9E6,stroke:#28a745,color:#000
    classDef deployment fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef code fill:#F0F0F0,stroke:#666,color:#000
    classDef external fill:#FFF0F5,stroke:#C71585,color:#000
```
