A sample implementation of the Clean Architecture pattern using .NET 6. This repository demonstrates how to structure a .NET application following best practices, ensuring maintainability, scalability, and testability.
- Role-based Authentication and Authorization: Provides secure access based on user roles.
- JWT Authentication: Ensures secure communication between the client and server.
- Centralized Error Handler: Simplifies error handling across the application.
- Serilog Integration: Comprehensive logging support for monitoring and troubleshooting.
- Entity Framework Code-First Approach: Simplified database management and schema generation.
- Customized AutoMapper: Streamlines object mapping between layers.
- Authentication:
- Register as a user.
- Register as an admin.
- Login.
- Weather Forecast Management (Admin-only):
- Create, Update, Delete, View Weather Forecast entries.
- View Weather Forecast:
- Accessible to any logged-in user.
- .NET 6
- ASP.NET Core Web API
- Entity Framework Core
- AutoMapper
- Serilog
- JWT Authentication
- Visual Studio 2022 or Visual Studio Code
- .NET 6 SDK
- SQL Server (or any configured database)
Follow these steps to set up and run the project locally:
git clone https://github.com/biswajitpanday/CleanArchitecture.Net6.git
cd CleanArchitecture.Net6
Restore NuGet packages and build the solution:
dotnet build
Ensure your database connection string is configured in the appsettings.json
file. Then apply migrations:
dotnet ef database update
Run the application using the following command:
dotnet run --project .\src\Presentation\CleanArchitecture.Api\CleanArchitecture.Api.csproj
The repository follows a structured design for better maintainability and scalability:
├── src
│ ├── CleanArchitecture.Api # API Layer (Presentation)
│ │ ├── Controllers # API endpoints
│ │ ├── Middleware # Centralized error handling middleware
│ │ ├── appsettings.json # Configuration files
│ │ ├── Program.cs # Application entry point
│ ├── CleanArchitecture.Core # Core Business Logic
│ │ ├── AutoMapper # Customized AutoMapper profiles
│ │ ├── Constants # Application constants
│ │ ├── Dtos # Data transfer objects
│ │ ├── Entities # Database entities
│ │ ├── Interfaces # Interfaces for Repositories and Services
│ │ ├── Settings # Application settings
│ ├── CleanArchitecture.Repository # Data Access Layer
│ │ ├── Auth # Authentication-related data access
│ │ ├── DatabaseContext # EF Core DB context
│ │ ├── Migrations # EF Core migrations
│ ├── CleanArchitecture.Service # Service Layer
│ ├── Dependencies # Service implementations
│ ├── WeatherForecastService # Business logic for Weather Forecast
└── tests # (Future placeholder for unit and integration tests)
The API is documented using Swagger. You can explore all available endpoints and their schemas through the Swagger UI:
- POST
/api/Auth/login
: Login for registered users. - POST
/api/Auth/register
: Register as a regular user. - POST
/api/Auth/register-admin
: Register as an admin.
- GET
/WeatherForecast
: View weather forecasts (Any logged-in user). - POST
/WeatherForecast
: Create a weather forecast (Admin only). - PUT
/WeatherForecast
: Update a weather forecast (Admin only). - GET
/WeatherForecast/{id}
: View specific weather forecast (Any logged-in user). - DELETE
/WeatherForecast/{id}
: Delete a weather forecast (Admin only).
Contributions are welcome! If you would like to improve this repository:
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature
. - Commit your changes:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature/your-feature
. - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Have questions or need support? Reach out via:
- Inspired by the principles of Clean Architecture.
- Special thanks to the .NET community for valuable resources and tools.