How yonexdu0ra/qltv works
Project Type and Purpose
• This is a full-stack Node.js/Express monolith for “qltv” (quản lý thư viện) – a library management system.
• It follows an MVC/service/repository layered architecture, rendering EJS views on the server and serving static assets.
Top-Level Components
• Client Layer
– Web browser accessing EJS-rendered HTML and public JS/CSS.
• Presentation Layer (Express App)
– Static asset serving (src/public, src/css, tailwind.config.js)
– View rendering (src/views/*.ejs)
• API Layer
– Routing (src/routes/public & src/routes/private)
– Middleware (authentication, authorization)
• Controller Layer (src/controllers)
– Orchestrates HTTP requests → business logic.
• Service Layer (src/services)
– Core business rules and transaction management.
• Repository Layer (src/repositories)
– Data access via ORM (Sequelize models in src/models).
• Data Layer
– Relational Database (configured in src/config/database.js)
– Redis cache (src/config/redisClient.js)
– File storage (Cloudinary via src/config/cloudinary.js; multer for uploads)
• Utilities
– JWT, slug generator, base64, formatting (src/utils).
• Seeders (src/seeders)
– Initial data population.
Interactions and Data Flow
1. Client → HTTP GET/POST to Express server
2. Express static middleware serves /public and /css assets directly
3. Dynamic routes hit src/routes → pass through authenticationMiddleware → authorizationMiddleware
4. Route handler invokes corresponding controller
5. Controller calls service layer for business logic
6. Service uses repositories to CRUD via Sequelize models ↔ Database
7. For caching reads/writes, repositories use Redis client
8. For file uploads, controllers use multer → cloudinary upload
9. Controller returns data or renders EJS view back to client
Architectural Patterns and Principles
• Layered Architecture (Routing → Middleware → Controller → Service → Repository → Model)
• Separation of Concerns (controllers do orchestration, services contain logic, repositories handle data)
• Single Responsibility per module
• Config modules isolate infrastructure details (DB, Redis, Cloudinary)
• Seeders for idempotent data setup