How premkmr16/tms works
Project Type and Purpose
• This is a monolithic backend API (TMS.API) built with .NET 7 following a Clean/Onion Architecture.
• Purpose: expose HTTP endpoints for managing Employees, EmployeeTypes, WorkItems, Projects, etc., with support for CRUD, Excel import/export, real-time updates (SignalR), and paginated responses.
a. Presentation Layer
• Project: Presentation/TMS.API
• Contains: Minimal HTTP endpoints (EmployeeEndpoints.cs, EmployeeTypeEndpoints.cs), middleware (ApiResponseMiddleware), configuration (Program.cs, appsettings.json)
• Tech: ASP.NET Core Minimal API
b. Application Layer
• Project: Application/TMS.Application
• Contains: CQRS via Mediatr, Features (Commands, Queries, Handlers), Common services (Excel import/export, MappingProfile for AutoMapper, Validation with FluentValidation), Repository interfaces, ApiResponse models
• Tech: Mediatr, AutoMapper, FluentValidation
c. Core (Domain) Layer
• Project: Core/TMS.Core
• Contains: Domain Entities (Employee, WorkItem, Project, etc.), domain-specific error messages, raw SQL queries, endpoint definition helpers
• Tech: Plain C# classes, SQL query strings
d. Infrastructure Layer
• Project: Infrastructure/TMS.Infrastructure
• Contains: EF Core DbContext (TMSDbContext), Migrations, EntityTypeConfigurations, Repository implementations, ConnectionFactory, SignalR Hubs
• Tech: Entity Framework Core, SQL Server provider, SignalR
e. Database
• Folder: Database/StoredProcedures/*.sql
• Contains: Stored procedures for complex queries; underlying relational schema
Interactions & Data Flow
1) HTTP Client → Presentation:
• Client issues an HTTP request (e.g., POST /employees).
• Middleware handles cross-cutting concerns (logging, ApiResponse shaping).
2) Presentation → Application:
• Endpoint invokes Mediatr.Send() with a Command or Query DTO.
3) Application Internals:
• Mediatr dispatches to the appropriate Handler (AddEmployeeHandler, GetEmployeesHandler).
• Handler uses Validators (FluentValidation) and Mapping (AutoMapper) from Common.
• Handler calls a Repository Interface (IEmployeeWriteRepository or IEmployeeReadRepository).
4) Application → Infrastructure:
• Repository interface is implemented in Infrastructure.Persistence.Repositories.
• Implementation uses TMSDbContext (EF Core) or raw SQL queries from Core.Database.
5) Infrastructure → Database:
• DbContext issues SQL commands, applies Migrations, executes StoredProcedures where needed.
6) Real-Time Notifications:
• Some handlers push notifications via SignalR Hubs (EmployeeHub) in Infrastructure, broadcasting to connected WebSocket clients.
7) Responses travel back up the stack to the HTTP Client.
Architectural Patterns & Principles
• Onion/Clean Architecture: strict dependency rule (outer layers depend inward only on abstractions).
• CQRS + Mediator: separation of Commands (writes) vs. Queries (reads).
• Repository Pattern: abstract data access interfaces in Application, concrete EF Core implementations in Infrastructure.
• Dependency Injection: wiring all layers in Presentation via built-in DI container.
• Layered Error Handling & ApiResponse Wrapping via middleware.