How rajanshah23/yipl-backend-2025 works
Project Type & Purpose
• This is a backend‐only RESTful API for a Library Management System, built with Node.js, Express, Sequelize (ORM), and SQLite.
• It exposes CRUD endpoints for Authors and Books, with pagination, filtering, error handling, optional JWT‐based authentication, and Docker support for easy deployment.
High‐Level Architectural Overview
• Pattern: Classic MVC (Model‐View‐Controller) adapted for an API (no “View” layer beyond JSON responses).
• Layers:
a. Presentation/API Layer (Routes & Middleware)
b. Application/Business Logic Layer (Controllers & Services)
c. Persistence Layer (Sequelize Models + Raw SQLite DB)
d. Infrastructure (Configuration, Migrations, Seeders, Docker)
A. Client (e.g., Frontend App or API Client like Postman)
B. API Server (Docker Container running Node/Express)
1. Routes Layer
• authorRoute.js, bookRoute.js, userRoute.js
2. Middleware
• isAuthenticated.js
3. Controllers
• authorController.js, bookController.js, userController.js
4. Services/Utilities
• catchAsync.js (error‐wrapping)
5. Config
• config/config.json (DB credentials, env variables)
6. Server Entrypoints
• server.js (HTTP server + Docker binding)
• src/app.js (Express app setup)
C. Database
• Sequelize CLI artifacts (migrations/, seeders/)
• SQLite file (sqlite_data/database.sqlite)
D. External/DevOps
• Dockerfile & dockerignore
• .env (JWT_SECRET, DB_PATH – implied)
• npm scripts for migrate/seed/dev
Data Flow & Interactions
1. Client → HTTP Request → Express Routes
2. Route → (Optional) Authentication Middleware
3. Middleware → Controller
4. Controller → Service Wrapper (catchAsync) → Business Logic
5. Business Logic → Sequelize Models → SQLite DB
6. DB → Sequelize → Controller → Client (JSON Response)
7. Migrations/Seeders interact directly with Config & DB for schema & initial data
8. Docker wraps entire API Server + persistent volume for sqlite_data
Architectural Patterns & Principles
• Separation of Concerns: Routes vs Controllers vs Services vs Models
• Layered Architecture: each layer only calls the next lower layer
• Single Source of Truth: models/index.js exports the DB connection & models
• Resilience: catchAsync for uniform async error handling
• Configuration Management: config/config.json with environment overrides
• Infrastructure as Code: Dockerfile + migrations/seeders for DB lifecycle
Technologies & Frameworks
• Node.js & Express for HTTP server
• Sequelize ORM for DB abstraction & migrations
• SQLite for zero-admin, file‐based persistence
• Docker for containerization
• npm scripts for automation (migrate, seed, dev, start)