FenecApi is a clean and scalable RESTful API built with .NET Core 8, designed to manage products, orders, and categories efficiently. It follows best practices in software architecture, implementing repository patterns, service layers, middleware for error handling, and structured logging with NLog. The API is ready for cloud deployment in Azure and supports database migrations with EF Core.
FenecApi follows a clean and modular architecture to ensure maintainability and scalability:
- Repository Pattern - Encapsulates database access logic.
- Service Layer - Handles business logic and interacts with repositories.
- Middleware - Centralized exception handling.
- Logging (NLog) - Structured logging for debugging and monitoring.
- AutoMapper - Simplifies DTO-to-entity mapping.
- Dependency Injection - Ensures loose coupling between components.
FenecApi/
│-- Configurations/ # Entity Framework configurations for models
│-- Controllers/ # API Controllers (REST endpoints)
│-- Data/ # DbContext configuration
│-- DTOs/ # Data Transfer Objects
│ ├── utils/ # Shared utility DTOs
│-- Extensions/ # Custom service and middleware extensions
│-- Mapping/ # AutoMapper profile configuration
│-- Middlewares/ # Global error handling middleware
│-- Migrations/ # EF Core migrations
│-- Models/ # Entity models
│-- Repositories/ # Repository pattern implementation
│ ├── Interfaces/ # Repository interfaces
│-- SeedData/ # Database seed data
│-- Services/ # Business logic services
│ ├── Interfaces/ # Service interfaces
│-- appsettings.json # Configuration settings
- .NET Core 8 - Backend framework
- Entity Framework Core - ORM for database operations
- SQL Server - Relational database
- NLog - Logging
- Swagger (NSwag) - API documentation
- AutoMapper - Object mapping
- Dependency Injection - Loose coupling
- Azure App Service - Cloud deployment
git clone https://github.com/yourgithubusername/FenecApi.git
cd FenecApiUpdate the appsettings.json file with your SQL Server connection string:
"ConnectionStrings": {
"DefaultConnection": "Server=YOUR_SERVER;Database=FenecDb;User Id=YOUR_USER;Password=YOUR_PASSWORD;"
}Run the following command to apply migrations and seed data:
dotnet ef database updatedotnet runThe API will be available at: http://localhost:5000
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/categories |
Retrieve all categories |
| POST | /api/categories |
Create a new category |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health/db-connection |
Check database connection status |
For a full list of endpoints, access the Swagger UI: http://localhost:5000/swagger
- Centralized Exception Handling Middleware ensures consistent error responses.
- NLog integration logs all API requests, responses, and errors.
- Logs are stored in
logs/logfile.log.
- Create an Azure App Service.
- Configure SQL Server Database in Azure.
dotnet publish -c Release -o out
az webapp deploy --resource-group YOUR_RESOURCE_GROUP --name YOUR_APP_NAME --src-path out/- Test the Health Check Endpoint:
curl https://yourapp.azurewebsites.net/api/health/db-connectionFeel free to fork this project, open issues, and submit pull requests.
- GitHub: alonsoegm
- LinkedIn: Alonso Gallegos
- Email: alonsoegm@gmail.com