Skip to content

HFsa-RaShid/library_management_server

Repository files navigation

Library Management System - Backend API

A robust, scalable, and type-safe backend for a Library Management System. Built with Node.js, Express, and Prisma ORM, this server handles everything from user memberships and book inventories to complex borrowing workflows and fine management.

Key Features

  • Relational Data Modeling: Optimized PostgreSQL schema for Users, Memberships, Books, and Borrowing records.

  • High-Performance Caching: Integrated Redis to cache heavy endpoints (e.g., membership details, user lists), drastically reducing API response times and database load.

  • Containerized Environment: Fully dockerized setup using Docker Compose for seamless and instant local environment replication without manual installations.

  • Automated Borrowing System: Tracks due dates, return dates, and renewal counts.

  • Fine Management: Automatically manages different fine types like OVERDUE, LOST_BOOK, and DAMAGED_BOOK.

  • Role-Based Access (RBAC): Distinct logic for Admin, Librarian, and User.

  • Inventory Tracking: Detailed logs for added, removed, or damaged books.

  • Notifications & Alerts: Notification system for due reminders and system announcements.

Tech Stack & Tools

  • Language: TypeScript

  • Framework: Express.js

  • ORM: Prisma

  • Database: PostgreSQL

  • Caching: Redis

  • Containerization: Docker & Docker Compose

  • Environment: Node.js

Prisma Database Setup

Since this project uses Prisma, follow these steps to sync your database:

  1. Configure Environment Create a .env file in the root directory and add your PostgreSQL connection string:
DATABASE_URL="postgresql://username:password@localhost:5432/library_db?schema=public"
PORT=3003
  1. Install Dependencies
npm install
  1. Sync Database (Migrations)
 npx prisma migrate dev --name init
  1. Generate Client
 npx prisma generate
  1. Explore via Prisma Studio
 npx prisma studio

Getting Started

 npm run dev

Docker & Redis Setup (The Quick Way 🐳)

Alternatively, you can run the entire project (App, Database, and Redis) using Docker Compose with just one command without any local configuration:

  1. Create a .env file in the root directory:
  PORT=3003
  POSTGRES_USER=postgres
  POSTGRES_PASSWORD=your_password
  POSTGRES_DB=library_management
  NODE_ENV=development
  1. Spin up everything:
  docker-compose up --build

Getting Started

  npm run dev

NPM Packages Used

  • @prisma/client - Type-safe database client.

  • ioredis - Robust, full-featured Redis client for Node.js.

  • express - Fast and minimalist web framework.

  • http-status - Consistent HTTP response status codes.

  • dotenv - Managing environment variables.

  • typescript - For strict typing and better developer experience.

Backend Architecture

  • The project follows a modular structure for maintainability:

  • Interfaces: Data definitions and types.

  • Services: Core business logic and database interactions.

  • Controllers: Request handling and response formatting.

  • Routes: API endpoint mapping.

  • Utils: Shared utility files (Prisma & Redis Client configs).

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Developed with ❤️ by Hafsa

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors