Skip to content

Repository files navigation

📚 Library Management System – Backend (C# .NET API)

A lightweight and efficient RESTful API backend built using ASP.NET Core and Entity Framework Core with SQLite, designed to support a Library Management System.

This backend handles:

  • 📚 Book CRUD operations
  • 🔐 User Authentication (JWT-based)
  • 🗄 SQLite database with Entity Framework
  • 🌐 API endpoints for frontend integration

🚀 Features

📘 Book Management (CRUD)

  • Create new books
  • Retrieve all books
  • Retrieve book by ID
  • Update book details
  • Delete a book

🔐 User Authentication (Optional Feature)

  • Register new users
  • Login with username & password
  • JWT authentication
  • Secure password hashing (BCrypt)

🛠 Technical Capabilities

  • ASP.NET Core Web API
  • Entity Framework Core
  • SQLite Integration
  • Layered folder structure
  • DTO models for input validation

📦 Project Structure

Library Management System/
├── Controllers/
│   ├── AuthController.cs           # User Register/Login
│   ├── BookController.cs           # CRUD endpoints for books
│   └── WeatherForecastController.cs  # Default sample
│
├── Data/
│   └── AppDbContext.cs             # EF Core DB Context
│
├── Migrations/                     # Auto-generated EF Migrations
│
├── Models/
│   ├── AddBookDto.cs               # DTO for adding books
│   ├── UpdateBookDto.cs            # DTO for updating books
│   ├── UserDto.cs                  # DTO for user authentication
│   ├── Book.cs                     # Book model
│   └── User.cs                     # User model
│
├── library.db                      # SQLite database
├── appsettings.json                # DB + JWT Config
├── Program.cs                      # API configuration
└── README.md

⚙️ Technologies Used

Layer Technology
Backend Framework ASP.NET Core Web API
Database SQLite
ORM Entity Framework Core
Authentication JWT (JSON Web Tokens)
Password Hashing BCrypt.Net
Language C#
Tooling .NET 8

🔧 API Endpoints

📚 Books API

Method Endpoint Description
GET /api/books Get all books
GET /api/books/{id} Get book by ID
POST /api/books Add a new book
PUT /api/books/{id} Update a book
DELETE /api/books/{id} Delete a book

🔐 Authentication API

Method Endpoint Description
POST /api/auth/register Register a new user
POST /api/auth/login Login user + return JWT token

🗄 Database

SQLite database file is auto-generated:

library.db
library.db-shm
library.db-wal

EF Core handles migrations.


🚀 Getting Started

1️⃣ Install Dependencies

Make sure you have:

  • .NET 8 SDK
  • SQLite installed (optional)

2️⃣ Update Database Connection (optional)

In appsettings.json:

"ConnectionStrings": {
  "DefaultConnection": "Data Source=library.db"
}

3️⃣ Apply Migrations

dotnet ef database update

4️⃣ Run the API

dotnet run

Backend will run on:

https://localhost:7036
http://localhost:5239

(Ports may vary based on your system)


🔐 Authentication Flow

Registration

User provides:

  • username
  • password

Password is hashed using BCrypt.

Login

  • Validate password
  • Generate JWT token
  • Frontend stores token in localStorage

Protect Endpoints (Optional)

You can protect routes using:

[Authorize]

📄 Environment Variables (JWT Config)

Inside appsettings.json:

"Jwt": {
  "Key": "YOUR_SECRET_KEY_HERE",
  "Issuer": "library-api",
  "Audience": "library-api"
}

Use a long, secure key for real apps.


🧪 Testing the API

You can use:

  • Postman
  • Thunder Client (VS Code)
  • Swagger UI (built-in)

Swagger loads automatically at:

https://localhost:7036/swagger

🎓 Developer Notes

  • Code follows clean architecture principles
  • DTOs used for safety and input validation
  • Controllers separated for maintainability
  • Easy to integrate with any frontend (React, Vue, Angular)

📜 License

MIT License – Free to use, modify, and distribute.


👏 Acknowledgements

  • Microsoft ASP.NET Core Team
  • Entity Framework Core
  • BCrypt.Net
  • SQLite Development Team

About

Backend API for Library Management System

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages