RESTful API developed with .NET 8 for project and task management. This solution implements a layered architecture (N-Layer Architecture) focused on separation of concerns, scalability, and robust error handling.
- Core: .NET 8 SDK
- ORM: Entity Framework Core
- Database: SQL Server (Compatible with InMemory/Postgres)
- Error Format: ProblemDetails (RFC 7807)
- ProjectManagementRestAPI (Web Layer)
- The entry point of the application.
- Controllers (
ProjectController,TaskItemController): Implement the "Skinny Controller" pattern. They don't contain business logic; they only orchestrate the HTTP request and delegate to the service. - Middleware (
GlobalExceptionHandler): Centralizes error handling. It captures exceptions likeKeyNotFoundExceptionorInvalidOperationExceptionand converts them into standardized HTTP responses (404, 400).
- BusinessLogic (Service Layer)
- The "brain" of the application. Contains
ProjectServiceandTaskItemService. - Business validation rules reside here (e.g., "A project with pending tasks cannot be completed").
- Communicates with the data layer through interfaces (Dependency Injection).
- Data (Persistence Layer)
- Contains the
ApplicationDbContextand the Repository pattern implementation (ProjectRepository,TaskItemRepository). - Abstracts database access using Entity Framework Core.
- Models (Domain Layer)
- Contains pure entities (
Project,TaskItem) and Enumerations (StatusProject,StatusTask,PriorityTask). - Represents the database schema.
- DTOs (Data Transfer Objects)
- Flat objects used to transfer data between the client and server.
- Allows decoupling database entities from the public API and applying input validations (
[Required],[StringLength]).
Instead of using repetitive try-catch blocks in each controller, a GlobalExceptionHandler was implemented.
- Benefit: Cleaner code and consistent error responses under the ProblemDetails standard.
- If a resource doesn't exist, the service throws an exception and the handler automatically returns a 404 Not Found.
Data access was separated from business logic.
- Repository: Responsible only for interacting with the DB (CRUD).
- Service: Orchestrates business rules and validations before calling the repository.
Non-trivial rules are validated in the Service, not in the Controller or Database.
- Example: Validating that
DueDateis not a past date or preventing deletion of an active project.
Projects (Project):
- A project cannot be deleted if it has pending or in-progress tasks.
- Cannot be marked as
Finishedif it has incomplete tasks. - Automatic calculation of progress percentage.
Tasks (TaskItem):
- Date Integrity: Tasks cannot be created with
DueDatein the past. - State Flow: A task cannot jump directly from
PendingtoCompleted; it must go throughInProgress. - Queries: Filtering by priority and detection of overdue tasks.
- Clone the repository:
git clone https://github.com/your-username/ProjectManagerAPI.git-
Configure Database: Make sure you have the connection string configured in
appsettings.json. -
Apply Migrations: From the terminal in the
Dataproject folder or root:
dotnet ef database update --project Data --startup-project ProjectManagementRestAPI- Run:
dotnet run --project ProjectManagementRestAPI