Welcome to the Library Management System, a project demonstrating the Domain-Driven Design (DDD) pattern implemented with .NET 8, PostgreSQL, Entity Framework Core, and Swagger for API documentation.
DDD is a software design philosophy that emphasizes focusing on the core domain and domain logic of an application. It’s about aligning your code with the real-world problem you're solving, ensuring that your application structure mirrors the business processes and rules.
- Domain Layer: The heart of your application. Contains entities, value objects, and domain logic.
- Application Layer: Coordinates tasks and delegates work to the domain. It contains use cases (e.g.,
BorrowBookHandler). - Infrastructure Layer: Handles communication with external resources like databases and APIs.
- Clean Architecture: Layers your application to ensure separation of concerns and flexibility.
- Implements DDD and Clean Architecture principles.
- Uses PostgreSQL as the database.
- Entity Framework Core for data access and migrations.
- Swagger for API exploration and testing.
- CRUD operations for managing books in a library.
- Implements a use case for borrowing a book.
- .NET 8
- PostgreSQL
- Entity Framework Core
- Swagger (Swashbuckle)
git clone https://github.com/your-username/library-management-ddd.git
cd library-management-dddEnsure you have the following installed on your machine:
- .NET 8 SDK
- PostgreSQL
- Any IDE or text editor (e.g., Visual Studio, Visual Studio Code)
- Install PostgreSQL locally if not already installed.
- Update the
appsettings.jsonfile with your PostgreSQL credentials:{ "ConnectionStrings": { "LibraryDatabase": "Host=localhost;Port=5432;Database=LibraryManagement;Username=postgres;Password=yourpassword" } }
To create the database schema and seed data, run the following commands:
- Add Migrations (already included in the project):
dotnet ef migrations add InitialCreate
- Apply Migrations:
dotnet ef database update
This will create the Books table in the LibraryManagement database and populate it with seed data.
Run the application:
dotnet runThe project will start on http://localhost:5000 (or another port if configured).
Navigate to the Swagger UI to explore and test the API:
http://localhost:5000/swagger
- GET /api/books: Retrieve all books.
- POST /api/books/{id}/borrow: Borrow a book by its ID.
- Domain: Core logic (e.g.,
Bookentity). - Application: Use cases (e.g.,
BorrowBookHandler). - Infrastructure: Database setup and EF Core repositories.
- Controller: Entry point for HTTP requests.
- Aligns code with business processes.
- Reduces technical debt by focusing on the domain.
- Improves code maintainability and scalability.
After running migrations and starting the application:
- Use Swagger to test the endpoints.
- Verify the database changes using your PostgreSQL client (e.g.,
pgAdminor DBeaver).
- Add authentication and authorization.
- Extend domain logic for returning books.
- Introduce a search feature for books.
- Add pagination and filtering for large datasets.
Feel free to fork the repository and submit pull requests. Contributions and feedback are always welcome!
This project is licensed under the MIT License.
Enjoy exploring Domain-Driven Design with this project! 🎉