Application architecture - BOD-Tech-Trend-Emporium/Backend GitHub Wiki
Overview
The application uses a monolithic architecture, in which the Backend project and its tests are implemented. The backend project is made in .NET using C# and Entity Framework, connected to a SQL Server database. This project employs a Clean Architecture approach with vertical slicing, having for each module a domain, application, and infrastructure layer. Inside the domain layer are the entities, DTOs, enums, and the repository interface; at the application layer are the services, validation methods and mappers used to transform a DTO into an entity and vice versa. Finally, at the infrastructure layer is the main API, with its controller and the repository implementation.
Here is a class diagram that will allow a better understanding of how the project was developed Diagram
For the Test project, the xunit library was used, in conjunction with EntityFrameworkCore InMemory, fluent assertions and coverlet for test coverage. This projet uses a basic folder structure, in which each module has a folder with the test for its services and mappers.
For the deployment of the app, an Azure virtual machine was provisioned, using Ubuntu 24.04, 2 vCPU and 8 GiB of ram. This machine was configured to have docker engine running with 4 different containers, two containers used for the development and production environments, and the other two used for its databases.
Features to highlight
Error Handling
Inside the Backend project, in the src folder, there is a common folder in which the exceptions methods are created. These methods can be used in the app thanks to the use of an error handling middleware. This middleware runs after each request, and depending of the thrown exception returns one status code or another. This configuration is very useful, as it reduces repetitive lines of code in the controller, by delegating error handling to the middleware.
Secrets
Some values like the Bcrypt token key and databases credentials, where store inside the GitHub sectrets section. This allows for greater security and limits access to this data only during CI processes.
Scripting
A script repository was created, in order to populate the Product and Category tables of the database with the data from the FakeStoreApi. These scripts were made using JS and connects directly to the TechTrendEmporium API. These scripts allows to handle the same data than the one from the FakeStoreApi.