How gporto95/runtracker works
Main Components
• Web API Layer – Represented by the src/Web.Api folder. This holds all the endpoints (e.g., UserEndpoint.cs, WorkoutEndpoints.cs) along with middleware, global exception handling, request logging, and OpenAPI configuration. This is your presentation layer that handles HTTP requests.
• Application Layer – Found under src/Application. This layer follows a CQRS (Command Query Responsibility Segregation) pattern and includes Command/Query objects, their corresponding handlers, and several pipeline behaviors (for exception handling, logging, caching, validation, transactions). It acts as the intermediary between your presentation layer and the domain/business logic.
• Domain Layer – Located in src/Domain. This layer represents the business logic, entities (like User, Workout, Follower), domain events, and domain services. It encapsulates the core rules and invariants of the application.
• Infrastructure Layer – Under src/Infrastructure. This layer implements cross-cutting concerns such as database access (e.g., ApplicationReadDbContext, ApplicationWriteDbContext, repository implementations), caching, event bus, notifications, and the outbox pattern. It provides concrete implementations for interfaces defined in the Application and Domain layers and manages integration with external systems (e.g., database, external services, health checks).
• Shared Kernel – Contained in src/SharedKernel. This common library holds shared abstractions, such as error handling, domain event interfaces, date/time providers, and utility methods used throughout other layers.
Relationships and Interactions
• The Web API receives HTTP requests and maps them to endpoints. These endpoints translate client requests into application commands and queries.
• The Application layer processes these commands/queries using the pipeline behaviors. It coordinates validation, logging, caching, exception handling, and eventual interaction with both the Domain model and Infrastructure.
• Business logic resides in the Domain layer, where domain entities and services handle the core functionality (such as creating users, managing workouts, handling followers).
• Infrastructure provides the persistent storage and cross‑platform services (data contexts, repositories, caching services, messaging/event bus) that support Application and Domain operations.
• The Shared Kernel supplies common functionality that all layers rely on, ensuring consistency (for example, error handling and validation rules).
Architectural Patterns and Design Principles
• Layered Architecture and Domain‑Driven Design (DDD) – The clear separation into layers (Web API, Application, Domain, Infrastructure, and Shared Kernel) reflects typical DDD practices.
• CQRS – Evident in the command/query separation with distinct command handlers (e.g., CreateUserCommandHandler, CreateWorkoutCommandHandler) and query handlers.
• Pipeline Behaviors – Use of multiple pipeline behaviors (logging, caching, exception handling, validation, transactions) ensures cross‑cutting concerns are consistently managed.
• Event-Driven Communication – The presence of domain and integration events (e.g., FollowerCreatedDomainEvent, WorkoutRemovedIntegrationEvent) as well as an in‑memory message queue illustrate event-driven aspects.