A clean architecture implementation for a book management system built with .NET Core.
SimpleCleanArch is a book management system that allows users to manage books, authors, categories, and keywords. The project follows clean architecture principles to ensure separation of concerns, maintainability, and testability.
The solution is structured using Clean Architecture principles with the following layers:
- Domain Layer: Contains the core business logic, entities, and interfaces
- Application Layer: Contains application services, DTOs, and interfaces
- Infrastructure Layer: Contains implementations of repositories, database context, and external services
- Presentation Layer: Contains the API controllers and UI components
- Book management (CRUD operations)
- Author management
- Category management
- Keyword management
- Book-Author relationships
- Book-Category relationships
- Book-Keyword relationships
- Related books functionality
- .NET Core 9.0
- Entity Framework Core
- AutoMapper
- FluentValidation
- SQL Server
- .NET Core 9.0 SDK
- SQL Server
- Visual Studio 2022 or Visual Studio Code
-
Clone the repository:
git clone https://github.com/yourusername/SimpleCleanArch.git
-
Navigate to the project directory:
cd SimpleCleanArch
-
Update the connection string in
src/Presentation/SimpleCleanArch.API/appsettings.json
to point to your SQL Server instance. -
Run the database migrations:
dotnet ef database update --project src/Infrastructure/SimpleCleanArch.Infrastructure --startup-project src/Presentation/SimpleCleanArch.API
-
Run the application:
dotnet run --project src/Presentation/SimpleCleanArch.API
GET /api/books
- Get all booksGET /api/books/{id}
- Get a book by IDGET /api/books/slug/{slug}
- Get a book by slugGET /api/books/category/{categoryId}
- Get books by categoryGET /api/books/author/{authorId}
- Get books by authorPOST /api/books
- Create a new bookPUT /api/books/{id}
- Update a bookDELETE /api/books/{id}
- Delete a book
GET /api/authors
- Get all authorsGET /api/authors/{id}
- Get an author by IDGET /api/authors/book/{bookId}
- Get authors by bookPOST /api/authors
- Create a new authorPUT /api/authors/{id}
- Update an authorDELETE /api/authors/{id}
- Delete an author
GET /api/categories
- Get all categoriesGET /api/categories/{id}
- Get a category by IDGET /api/categories/slug/{slug}
- Get a category by slugPOST /api/categories
- Create a new categoryPUT /api/categories/{id}
- Update a categoryDELETE /api/categories/{id}
- Delete a category
GET /api/keywords
- Get all keywordsGET /api/keywords/{id}
- Get a keyword by IDGET /api/keywords/book/{bookId}
- Get keywords by bookPOST /api/keywords
- Create a new keywordPUT /api/keywords/{id}
- Update a keywordDELETE /api/keywords/{id}
- Delete a keyword
SimpleCleanArch/
├── src/
│ ├── Core/
│ │ ├── SimpleCleanArch.Domain/ # Domain layer
│ │ └── SimpleCleanArch.Application/ # Application layer
│ ├── Infrastructure/
│ │ └── SimpleCleanArch.Infrastructure/ # Infrastructure layer
│ └── Presentation/
│ └── SimpleCleanArch.API/ # API layer
└── tests/
└── SimpleCleanArch.Tests/ # Unit tests
This project follows these clean architecture principles:
- Dependency Rule: Dependencies only point inward. Inner layers have no knowledge of outer layers.
- Separation of Concerns: Each layer has a specific responsibility.
- Interface Segregation: Interfaces are defined in the domain layer and implemented in the infrastructure layer.
- Single Responsibility: Each class has a single responsibility.
- Open/Closed Principle: The system is open for extension but closed for modification.
This project is licensed under the MIT License - see the LICENSE file for details.
- Clean Architecture by Robert C. Martin
- .NET Core documentation
- Entity Framework Core documentation