A RESTful Web API built with ASP.NET Core (.NET 8) that allows users to manage books, members, and loans in a library system. The API supports full CRUD operations, uses Entity Framework Core with SQLite for data persistence, and is secured with JWT authentication.
This project demonstrates backend development with modern .NET technologies, clean API design, a layered service architecture, and a full test suite.
Backend
- C#
- ASP.NET Core Web API (.NET 8)
- Entity Framework Core
- SQLite
Security
- JWT Bearer Authentication
- BCrypt password hashing
Testing
- xUnit
- WebApplicationFactory (integration tests)
- In-memory database (unit tests)
Tools
- Swagger / OpenAPI (with JWT Bearer support)
- .NET CLI
Books
- Full CRUD — create, retrieve, update, and delete books
- Input validation using Data Annotations
Members
- Full CRUD — create, retrieve, update, and delete library members
- Email uniqueness validation
- Layered architecture — Controller → Service → Database
- Structured error handling via
ServiceResult<T>
Loans
- Borrow a book — enforces availability and membership rules
- Return a book — updates availability automatically
- Maximum 3 active loans per member
- Full loan history per member
Authentication
- Register and login with email and password
- JWT Bearer tokens protect all API endpoints
- Passwords hashed with BCrypt
Tests
- 42 tests — unit and integration
- Unit tests cover all service business rules
- Integration tests cover all API endpoints end-to-end
General
- Swagger UI with JWT Bearer support
LibraryManagement.Api
│
├── Controllers
│ ├── AuthController.cs
│ ├── BooksController.cs
│ ├── MembersController.cs
│ └── LoansController.cs
│
├── Data
│ └── LibraryDbContext.cs
│
├── DTOs
│ ├── Books
│ │ ├── CreateBookRequest.cs
│ │ ├── UpdateBookRequest.cs
│ │ └── BookResponse.cs
│ ├── Members
│ │ ├── CreateMemberRequest.cs
│ │ ├── UpdateMemberRequest.cs
│ │ └── MemberResponse.cs
│ ├── Auth
│ │ ├── RegisterRequest.cs
│ │ ├── LoginRequest.cs
│ │ └── AuthResponse.cs
│ └── Loans
│ ├── CreateLoanRequest.cs
│ └── LoanResponse.cs
│
├── Models
│ ├── Book.cs
│ ├── Member.cs
│ ├── Loan.cs
│ └── User.cs
│
├── Services
│ ├── ServiceResult.cs
│ ├── IAuthService.cs
│ ├── AuthService.cs
│ ├── IBookService.cs
│ ├── BookService.cs
│ ├── IMemberService.cs
│ ├── MemberService.cs
│ ├── ILoanService.cs
│ └── LoanService.cs
│
├── Migrations
├── Program.cs
└── appsettings.json
| Method | Endpoint | Description | Auth required |
|---|---|---|---|
| POST | /api/auth/register |
Register a new user | No |
| POST | /api/auth/login |
Login and receive a JWT | No |
All other endpoints require a valid JWT Bearer token.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/books |
Get all books |
| GET | /api/books/{id} |
Get book by ID |
| POST | /api/books |
Create a new book |
| PUT | /api/books/{id} |
Update a book |
| DELETE | /api/books/{id} |
Delete a book |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/members |
Get all members |
| GET | /api/members/{id} |
Get member by ID |
| POST | /api/members |
Create a new member |
| PUT | /api/members/{id} |
Update a member |
| DELETE | /api/members/{id} |
Delete a member |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/loans |
Get all loans |
| GET | /api/loans/member/{memberId} |
Get loans by member |
| POST | /api/loans/borrow |
Borrow a book |
| PUT | /api/loans/return/{loanId} |
Return a book |
{
"email": "admin@library.com",
"password": "SecurePass123!",
"role": "Admin"
}{
"email": "admin@library.com",
"password": "SecurePass123!"
}{
"title": "Clean Code",
"author": "Robert C. Martin",
"isbn": "9780132350884",
"publicationYear": 2008
}{
"firstName": "Jane",
"lastName": "Doe",
"email": "jane.doe@example.com",
"phone": "555-1234"
}{
"bookId": 1,
"memberId": 1
}git clone https://github.com/kayanr/library-management-system-dotnet-api.gitcd library-management-system-dotnet-api/LibraryManagement.Apidotnet restoredotnet ef database updatedotnet runAfter running the project, open Swagger in your browser:
http://localhost:xxxx/swagger
Swagger allows you to interactively test all API endpoints.
To test protected endpoints in Swagger:
- Call
POST /api/auth/registerto create a user - Call
POST /api/auth/loginto get a token - Click the Authorize button and enter your token
- All subsequent requests will include the Bearer token
- React + TypeScript frontend
- Angular frontend
- Role-based authorization (Admin vs Member)
- PostgreSQL or SQL Server support
- Deployment (Railway / Render / Azure)