How mehdihadeli/vertical-slice-api-template works
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