# burstcode/simracingschedule architecture

> Architecture diagram of the GitHub repository burstcode/simracingschedule, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/burstcode/simracingschedule
- Repository: https://github.com/burstcode/simracingschedule

## Overview

1. **Overall architecture**
   This is a .NET backend solution organized as a layered/Clean Architecture style system: **API** for HTTP entry points, **Application** for use-case models, **Core** for domain rules and abstractions, and **Infrastructure** for persistence and repository implementations.

2. **Domain/Core boundary**
   `SimracingSchedule.Core` contains the business model and contracts only: entities (`Employee`, `Shift`, `ShiftExchangeRequest`), domain enums (`EmployeeRole`, `ExchangeRequestStatus`, `ShiftSource`, `ShiftStatus`, `ShiftType`), a `DomainException`, and repository interfaces. This layer is the dependency root for the rest of the system.

3. **Use-case layer**
   `SimRacingSchedule.Application` is focused on shift-exchange workflows. It defines command/query models for creating an exchange, responding to an exchange, and retrieving pending exchanges, plus request/response DTOs and AutoMapper profiles. This layer shapes data for the API and coordinates application-level operations.

4. **HTTP/API layer**
   `SimRacingSchedule.Api` exposes the system through controllers, currently `EmployeeController` and `ShiftExchangeController`. `Program.cs` wires the app together, and the API project is the only surface that external clients talk to.

5. **Persistence layer**
   `SimRacingSchedule.Infrastructure` provides EF Core persistence via `ApplicationDbContext`, entity configurations, migrations, and repository implementations. It bridges the domain repository interfaces from Core to a relational database model.

6. **Repository pattern usage**
   The core defines repository abstractions such as `IEmployeeRepository`, `IShiftRepository`, `IShiftExchangeRepository`, and a generic `IRepository`. Infrastructure implements them with concrete classes like `EmployeeRepository`, `ShiftRepository`, `ShiftExchangeRepository`, and a shared base repository.

7. **Data model and relational mapping**
   EF Core configurations exist for all main entities: `EmployeeConfiguration`, `ShiftConfiguration`, and `ShiftExchangeRequestConfiguration`. That indicates the domain model is persisted as a relational schema, with migrations already checked in under `Infrastructure/Migrations`.

8. **Primary business flow**
   The clearest end-to-end flow is the **shift exchange** use case: an API request enters `ShiftExchangeController`, becomes an application command/query or DTO, is processed through domain/repository abstractions, and is persisted or read through `ApplicationDbContext`.

9. **Business rules and state**
   Most domain state is encoded as enums, especially for shift lifecycle and exchange request lifecycle. `DomainException` suggests invariant enforcement lives in the domain/core boundary rather than in controllers.

10. **Composition and dependency injection**
   `Infrastructure/DependencyInjection.cs` likely registers EF Core, repositories, and related services, while the API project composes those registrations at startup. This keeps the API thin and makes Infrastructure replaceable behind interfaces.

11. **Runtime and deployment shape**
   The repository includes `Dockerfile` for the API, `docker-compose.yml`, `.env.dist`, and environment-specific appsettings. That means the service is designed to run containerized, with configuration externalized from code.

12. **Diagram takeaway**
   For an architecture diagram, the key boundaries are: **Client -> API controllers -> Application use cases -> Core domain abstractions -> Infrastructure repositories/DbContext -> database**. The core domain stays isolated, and all persistence concerns are pushed into Infrastructure.

Main entry points: [`SimRacingSchedule.Api/Controllers/ShiftExchangeController.cs`](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Api/Controllers/ShiftExchangeController.cs) (Shift Exchange), [`SimracingSchedule.Core/Entities/ShiftExchangeRequest.cs`](https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Entities/ShiftExchangeRequest.cs) (Exchange Request), [`SimracingSchedule.Core/Interfaces/IRepository.cs`](https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Interfaces/IRepository.cs) (Contracts), [`SimRacingSchedule.Application/Mapping/MappingProfile.cs`](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Mapping/MappingProfile.cs) (Mapping)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_program["Startup<br/>host wiring<br/>[Program.cs]"]
  node_employee_controller["Employees<br/>controller"]
  node_shift_exchange_controller["Shift Exchange<br/>controller"]
end

subgraph group_app["Application"]
  node_create_exchange_cmd["Create Exchange<br/>command"]
  node_respond_exchange_cmd["Respond Exchange<br/>command"]
  node_pending_query["Pending Query"]
  node_dto_models["DTOs<br/>api models"]
  node_mapping_profile["Mapping<br/>mapper profile<br/>[MappingProfile.cs]"]
end

subgraph group_core["Core"]
  node_employee_entity["Employee<br/>domain entity<br/>[Employee.cs]"]
  node_shift_entity["Shift<br/>domain entity<br/>[Shift.cs]"]
  node_exchange_entity["Exchange Request<br/>domain entity"]
  node_domain_contracts["Contracts<br/>interfaces<br/>[IRepository.cs]"]
  node_domain_rules["Rules<br/>domain support<br/>[DomainException.cs]"]
end

subgraph group_infra["Infrastructure"]
  node_db_context[("DbContext<br/>ef core context")]
  node_configurations["Mappings<br/>ef configurations"]
  node_repositories["Repos<br/>implementations<br/>[Repository.cs]"]
  node_migrations["Migrations<br/>schema history"]
  node_di["DI Setup<br/>composition"]
end

node_client(("Client<br/>external actor"))

node_client -->|"HTTP"| node_employee_controller
node_client -->|"HTTP"| node_shift_exchange_controller
node_program -->|"maps routes"| node_employee_controller
node_program -->|"maps routes"| node_shift_exchange_controller
node_program -->|"registers"| node_di
node_employee_controller -->|"uses"| node_domain_contracts
node_shift_exchange_controller -->|"creates"| node_create_exchange_cmd
node_shift_exchange_controller -->|"creates"| node_respond_exchange_cmd
node_shift_exchange_controller -->|"runs"| node_pending_query
node_create_exchange_cmd -->|"updates"| node_exchange_entity
node_respond_exchange_cmd -->|"updates"| node_exchange_entity
node_pending_query -->|"reads"| node_exchange_entity
node_dto_models -->|"mapped by"| node_mapping_profile
node_mapping_profile -->|"maps"| node_employee_entity
node_mapping_profile -->|"maps"| node_shift_entity
node_mapping_profile -->|"maps"| node_exchange_entity
node_domain_contracts -->|"abstracts"| node_employee_entity
node_domain_contracts -->|"abstracts"| node_shift_entity
node_domain_contracts -->|"abstracts"| node_exchange_entity
node_repositories -->|"uses"| node_db_context
node_db_context -->|"applies"| node_configurations
node_db_context -->|"evolves via"| node_migrations
node_repositories -->|"implements"| node_domain_contracts
node_di -->|"registers"| node_db_context
node_di -->|"registers"| node_repositories
node_domain_rules -->|"constrains"| node_exchange_entity
node_domain_rules -->|"constrains"| node_shift_entity
node_shift_exchange_controller -->|"binds"| node_dto_models

click node_program "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Api/Program.cs"
click node_employee_controller "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Api/Controllers/EmployeeController.cs"
click node_shift_exchange_controller "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Api/Controllers/ShiftExchangeController.cs"
click node_create_exchange_cmd "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Commands/ShiftExchange/CreateShiftExchangeCommand.cs"
click node_respond_exchange_cmd "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Commands/ShiftExchange/RespondToShiftExchangeCommand.cs"
click node_pending_query "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Queries/ShiftExchange/GetPendingExchangesQuery.cs"
click node_dto_models "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/DTOs/ShiftExchangeRequestDto.cs"
click node_mapping_profile "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Mapping/MappingProfile.cs"
click node_employee_entity "https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Entities/Employee.cs"
click node_shift_entity "https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Entities/Shift.cs"
click node_exchange_entity "https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Entities/ShiftExchangeRequest.cs"
click node_domain_contracts "https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Interfaces/IRepository.cs"
click node_domain_rules "https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Exceptions/DomainException.cs"
click node_db_context "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Data/ApplicationDbContext.cs"
click node_configurations "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Data/Configurations/ShiftExchangeConfiguration.cs"
click node_repositories "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Repositories/Repository.cs"
click node_migrations "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Migrations/20260404092900_InitialCreate.cs"
click node_di "https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/DependencyInjection.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_program,node_employee_controller,node_shift_exchange_controller toneBlue
class node_create_exchange_cmd,node_respond_exchange_cmd,node_pending_query,node_dto_models,node_mapping_profile toneAmber
class node_employee_entity,node_shift_entity,node_exchange_entity,node_domain_contracts,node_domain_rules toneMint
class node_db_context,node_configurations,node_repositories,node_migrations,node_di toneRose
class node_client toneNeutral
```

## Components

### API

HTTP entrypoints and app startup

- [Startup](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Api/Program.cs): host wiring · Composes the API and dependency injection · `SimRacingSchedule.Api/Program.cs`
- [Employees](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Api/Controllers/EmployeeController.cs): controller · HTTP endpoints for employees · `SimRacingSchedule.Api/Controllers/EmployeeController.cs`
- [Shift Exchange](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Api/Controllers/ShiftExchangeController.cs): controller · HTTP endpoints for exchange workflows · `SimRacingSchedule.Api/Controllers/ShiftExchangeController.cs`

### Application

Use-case orchestration and DTO mapping

- [Create Exchange](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Commands/ShiftExchange/CreateShiftExchangeCommand.cs): command · Command model for creating an exchange request · `SimRacingSchedule.Application/Commands/ShiftExchange/CreateShiftExchangeCommand.cs`
- [Respond Exchange](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Commands/ShiftExchange/RespondToShiftExchangeCommand.cs): command · Command model for approving or rejecting an exchange · `SimRacingSchedule.Application/Commands/ShiftExchange/RespondToShiftExchangeCommand.cs`
- [Pending Query](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Queries/ShiftExchange/GetPendingExchangesQuery.cs): query · Query model for retrieving pending exchanges · `SimRacingSchedule.Application/Queries/ShiftExchange/GetPendingExchangesQuery.cs`
- [DTOs](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/DTOs/ShiftExchangeRequestDto.cs): api models · Request and response shapes shared with controllers · `SimRacingSchedule.Application/DTOs/ShiftExchangeRequestDto.cs`
- [Mapping](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Application/Mapping/MappingProfile.cs): mapper profile · AutoMapper configuration between domain and DTOs · `SimRacingSchedule.Application/Mapping/MappingProfile.cs`

### Core

Domain model and repository contracts

- [Employee](https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Entities/Employee.cs): domain entity · Employee aggregate/data model · `SimracingSchedule.Core/Entities/Employee.cs`
- [Shift](https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Entities/Shift.cs): domain entity · Shift aggregate/data model · `SimracingSchedule.Core/Entities/Shift.cs`
- [Exchange Request](https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Entities/ShiftExchangeRequest.cs): domain entity · Shift exchange workflow entity · `SimracingSchedule.Core/Entities/ShiftExchangeRequest.cs`
- [Contracts](https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Interfaces/IRepository.cs): interfaces · Repository abstractions used by the application · `SimracingSchedule.Core/Interfaces/IRepository.cs`
- [Rules](https://github.com/burstcode/simracingschedule/blob/main/SimracingSchedule.Core/Exceptions/DomainException.cs): domain support · Domain exception and enum-based state model · `SimracingSchedule.Core/Exceptions/DomainException.cs`

### Infrastructure

EF Core persistence and repository implementations

- [DbContext](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Data/ApplicationDbContext.cs): ef core context · Primary persistence session and unit of work · `SimRacingSchedule.Infrastructure/Data/ApplicationDbContext.cs`
- [Mappings](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Data/Configurations/ShiftExchangeConfiguration.cs): ef configurations · Entity-to-table configuration classes · `SimRacingSchedule.Infrastructure/Data/Configurations/ShiftExchangeConfiguration.cs`
- [Repos](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Repositories/Repository.cs): implementations · Concrete repository implementations · `SimRacingSchedule.Infrastructure/Repositories/Repository.cs`
- [Migrations](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/Migrations/20260404092900_InitialCreate.cs): schema history · Checked-in database schema evolution · `SimRacingSchedule.Infrastructure/Migrations/20260404092900_InitialCreate.cs`
- [DI Setup](https://github.com/burstcode/simracingschedule/blob/main/SimRacingSchedule.Infrastructure/DependencyInjection.cs): composition · Registers infrastructure services for the host · `SimRacingSchedule.Infrastructure/DependencyInjection.cs`

### Other components

- **Client**: external actor · Calls the HTTP API

## Connections

- Client → Employees: HTTP · External requests reach employee endpoints
- Client → Shift Exchange: HTTP · External requests reach shift exchange endpoints
- Startup → Employees: maps routes · Startup hosts the controllers
- Startup → Shift Exchange: maps routes · Startup hosts the controllers
- Startup → DI Setup: registers · Composes infrastructure services at startup
- Employees → Contracts: uses · Controller depends on application/domain abstractions
- Shift Exchange → Create Exchange: creates · Request payload becomes application command
- Shift Exchange → Respond Exchange: creates · Request payload becomes application command
- Shift Exchange → Pending Query: runs · Controller issues query for pending exchanges
- Create Exchange → Exchange Request: updates · Use case targets the exchange request model
- Respond Exchange → Exchange Request: updates · Use case changes exchange request state
- Pending Query → Exchange Request: reads · Query reads exchange request data
- DTOs → Mapping: mapped by · DTOs are translated through AutoMapper
- Mapping → Employee: maps · Profiles include domain-to-DTO mapping
- Mapping → Shift: maps · Profiles include domain-to-DTO mapping
- Mapping → Exchange Request: maps · Profiles include domain-to-DTO mapping
- Contracts → Employee: abstracts · Repository interface for employees
- Contracts → Shift: abstracts · Repository interface for shifts
- Contracts → Exchange Request: abstracts · Repository interface for exchange requests
- Repos → DbContext: uses · Repositories execute persistence operations through EF Core
- DbContext → Mappings: applies · Context applies entity configurations
- DbContext → Migrations: evolves via · Schema history is maintained by migrations
- Repos → Contracts: implements · Concrete repositories fulfill core contracts
- DI Setup → DbContext: registers · Dependency injection wires the EF Core context
- DI Setup → Repos: registers · Dependency injection wires repository implementations
- Rules → Exchange Request: constrains · Domain invariants and lifecycle states apply to entities
- Rules → Shift: constrains · Domain invariants and lifecycle states apply to entities
- Shift Exchange → DTOs: binds · Controller input and output use shared DTOs
