A robust and well-structured RESTful API for managing ToDo tasks, built with .NET 9 and following Clean Architecture principles.
This project is a backend solution for a ToDo application. It provides a set of endpoints to perform CRUD operations on tasks. The application is designed with a focus on separation of concerns, testability, and maintainability by implementing a Clean Architecture with CQRS and Repository patterns.
- Create, Read, Update, and Delete (CRUD) operations for tasks.
- Update task status (
ToDo,InProgress,Done). - Validation for all incoming requests.
- Structured and consistent error handling.
- Interactive API documentation with Scalar.
- .NET 9 - The latest version of the .NET framework for building modern, cloud-based, and internet-connected applications.
- ASP.NET Core - For building the RESTful API.
- Entity Framework Core - For data access and object-relational mapping (ORM).
- SQL Server - As the database provider for EF Core.
- MediatR - For implementing the CQRS (Command Query Responsibility Segregation) pattern, which helps in separating read and write operations.
- AutoMapper - A convention-based object-object mapper.
- FluentValidation - For building strongly-typed validation rules.
- FluentResults - A lightweight .NET library for handling success and error states.
- xUnit & Moq - For unit and integration testing.
- Scalar - For beautiful and interactive API documentation.
The application is structured following the principles of Clean Architecture. This divides the project into three main layers:
ToDoApp.DAL(Data Access Layer): This layer is responsible for all data access logic. It contains the Entity Framework CoreDbContext, entity configurations, migrations, and the implementation of the Repository and Unit of Work patterns.ToDoApp.BLL(Business Logic Layer): This is the core of the application. It contains the business logic, MediatR handlers (Commands and Queries), DTOs, mappers, and validators. It is completely independent of the presentation and data access layers.ToDoApp.WebApi(Presentation Layer): This is the entry point of the application. It's an ASP.NET Core project that exposes the API endpoints. It handles HTTP requests and responses and delegates the execution to the BLL using MediatR.ToDoApp.UnitTests: This project contains unit tests for the BLL, ensuring the business logic is working as expected.
This layered architecture ensures a clear separation of concerns, making the application easier to maintain, test, and scale.
- .NET 9 SDK
- SQL Server (or any other database compatible with EF Core, but you'll need to change the provider)
- A code editor like Visual Studio or VS Code.
- Clone the repository:
git clone https://github.com/Skiper29/ToDoApp-Back
- Navigate to the project directory:
cd ToDoApp-Back - Configure the database connection:
Open the
appsettings.jsonfile in theToDoApp.WebApiproject and update theDefaultConnectionstring with your database credentials.{ "ConnectionStrings": { "DefaultConnection": "Server=your_server;Database=ToDoAppDb;User Id=your_user;Password=your_password;" } } - Apply database migrations:
Open a terminal in the root of the
ToDoApp.DALproject or use the Package Manager Console in Visual Studio and run the following command to create the database and apply the migrations:dotnet ef database update
- Run the application:
You can run the application from your IDE or by using the following command in the root of the
ToDoApp.WebApiproject:dotnet run
The API will be available at https://localhost:7156 and http://localhost:5133.
The API provides the following endpoints for managing tasks:
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/TodoTask |
Get all tasks |
GET |
/api/TodoTask/{id} |
Get a task by its ID |
POST |
/api/TodoTask |
Create a new task |
PUT |
/api/TodoTask |
Update an existing task |
PATCH |
/api/TodoTask/{id} |
Update the status of a task |
DELETE |
/api/TodoTask/{id} |
Delete a task |
You can explore and test the API endpoints using the interactive Scalar documentation, which is available at the root URL of the application when running in a development environment.
The project includes a comprehensive suite of unit tests in the ToDoApp.UnitTests project. To run the tests, you can use the Test Explorer in Visual Studio or run the following command from the root of the solution:
dotnet test