A production-grade, modular Library Management Platform: FastAPI + SQLAlchemy + PostgreSQL backend, React + TypeScript frontend, JWT auth with role-based access control, a real circulation domain (issue/return/ renew/reserve/fines with enforced state machines), an explainable recommendation engine, analytics, audit logging, and an AI librarian built on a swappable provider abstraction.
This is a from-scratch architectural rebuild of an earlier CSV-backed student project of the same name β see CHANGELOG.md for exactly what changed and why.
- Book catalog & copies β books and their individual physical copies (accession number, location, condition) are modeled separately.
- Circulation β issue, return, renew (with a renewal cap), reserve, cancel reservation, automatic overdue detection, fine calculation on late return.
- RBAC β ADMIN / LIBRARIAN / MEMBER roles with an explicit,
centralized permission map (
app/core/dependencies.py). - JWT authentication β bcrypt password hashing, access + refresh tokens, account-status enforcement on every request.
- Analytics dashboard β totals, utilization rate, most-borrowed books, category distribution, monthly circulation trend β rendered as live charts in the frontend.
- Explainable recommendations β deterministic signals (category/ author history + popularity), each with a plain-language reason. No ML is used or claimed.
- AI librarian β provider-agnostic (
LLMProviderprotocol); ships with a dependency-freeMockProviderby default and an optional Anthropic-backed provider. - Audit logging β every meaningful mutation is recorded to an
append-only
audit_logstable. - REST API β versioned under
/api/v1, documented at/swaggerand/redoc.
| Layer | Technology |
|---|---|
| Backend | Python 3.12, FastAPI, SQLAlchemy 2.0, Alembic, Pydantic v2 |
| Auth | passlib/bcrypt, python-jose (JWT) |
| Database | PostgreSQL (production), SQLite (dev/tests) |
| Frontend | React 19, TypeScript, Vite, React Router, Recharts |
| Testing | pytest, pytest-cov, httpx (via FastAPI TestClient) |
| Quality | ruff, mypy, oxlint, tsc |
| Deployment | Docker, docker-compose, GitHub Actions |
library-management-system-v5/
βββ app/ # FastAPI backend
β βββ core/ # config, security, logging, exceptions, RBAC deps
β βββ api/v1/ # HTTP routes β thin, no business logic
β βββ models/ # SQLAlchemy ORM models + state machines
β βββ schemas/ # Pydantic request/response schemas
β βββ repositories/ # Data access (SQLAlchemy)
β βββ services/ # Business logic β the real "domain layer"
β βββ ai/ # LLMProvider protocol + Mock/Anthropic providers
β βββ database/ # Session, Base, Alembic migrations
βββ frontend/ # React + TypeScript + Vite SPA
βββ tests/ # unit / api / integration pytest suites
βββ scripts/ # seed_database.py, migrate_data.py, create_admin.py
βββ docs/ # architecture, api, database, security, deployment, development
βββ data/seed/ # copied legacy CSVs, used by migrate_data.py
βββ Dockerfile, docker-compose.yml
βββ .github/workflows/ # ci.yml, security.yml
cp .env.example .env
docker compose up --build- Frontend: http://localhost:5173
- API docs: http://localhost:8000/swagger
# Backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt
cp .env.example .env
alembic upgrade head
python scripts/seed_database.py # demo accounts + books
uvicorn app.main:app --reload
# Frontend (separate terminal)
cd frontend
npm install
npm run devDemo accounts after seeding (see script output):
admin@example.com / AdminPass123! (also librarian@ and two member@ accounts).
Dev default is SQLite (zero setup). For PostgreSQL, set DATABASE_URL
in .env and run alembic upgrade head. See docs/database.md.
See .env.example for the full list with descriptions.
Full endpoint reference: docs/api.md. Interactive/auto-generated
docs at /swagger and /redoc once the server is running.
JWT access + refresh tokens; see docs/security.md for the full auth/authorization design.
pytest -q --cov=app --cov-report=term-missingVerified in this environment: 25 passed, ~80% statement coverage. Covers unit tests for circulation state machines, the recommendation engine, analytics, user management, and the AI mock provider; API tests for auth and books; and one full end-to-end integration test that exercises the exact workflow β create user β create book β create copy β issue β verify unavailable β return β verify available.
.github/workflows/ci.yml runs lint (ruff/oxlint), type checks
(mypy/tsc), the pytest suite, an Alembic migration smoke test, and a
frontend production build on every push/PR.
.github/workflows/security.yml runs pip-audit and npm audit on a
weekly schedule.
See docs/deployment.md for Docker Compose and bare-metal instructions.
scripts/migrate_data.py converts the legacy books.csv into the new
schema. Verified against this repository's actual data: 211/211 book
rows migrated, 0 rejected (see docs/database.md for
what is and isn't migrated, and why).
See docs/architecture.md. Default
AI_PROVIDER=mock requires no API key. Set AI_PROVIDER=anthropic and
AI_API_KEY to use a real Claude model instead.
See docs/security.md and SECURITY.md.
See CONTRIBUTING.md.
Honestly documented rather than glossed over β see the end of CHANGELOG.md:
- Token revocation/denylist not implemented (stateless JWT logout only).
- Rate limiting is a reverse-proxy responsibility, not in-process middleware.
- Legacy circulation history (
issued_books.csv,issue_log.txt) is reported by the migration script but not fabricated intoLoanrows. - The frontend covers the core flows end-to-end but not every UI component listed in the original brief (e.g. a dedicated copy-management screen, per-role dashboard layouts) β these are natural next additions on top of a now-complete API.
MIT β see LICENSE.