How hdang1612/ptit_dormitory works
Main Components
• Backend (ptit_dormitory_be):
• API Layer: The “routes” directory defines endpoints (e.g., authRoutes, userRoutes, areaRoute) that the client will call.
• Controller Layer: Under “controller”, you have components like authController, userController, areaController, etc. These handle incoming requests and coordinate between services and responses.
• Service Layer: The “services” directory contains business logic. For example, authServices and userServices encapsulate the core operations.
• Data/Model Layer: The “models” directory defines the database schema and objects (e.g., Users, RoomDetail, Role, etc.) which are used by services for database operations.
• Middleware & Utilities: Files under “middleware” (for auth, error handling, file upload) and “utils” (like apiError) offer cross-cutting functionalities.
• Database Configuration: The “config/db.js” file serves the purpose of connecting to the database.
• File Upload Module: The “upload” directory shows that the system supports file uploads, dealing with dormitory/student related excel files.
• Frontend (ptit_dormitory_fe):
• UI and Layout Components: Located under “src/components” (e.g., Sidebar, TopTable, Header) and “src/view” (e.g., Home, Login, ContractList).
• Global Styles and Assets: The “src/assets”, “src/style”, and various CSS/SCSS files configure the look and feel of the application.
• State Management: The “src/redux” directory includes the Redux store, indicating the use of Redux for state management.
• Entry Points & Configuration: Files like “index.html”, “index.css”, “main.jsx”, and “vite.config.js” define the project startup and bundling via Vite.
Relationships and Interactions
• Frontend → Backend Communication:
• The frontend communicates with the backend via REST API calls, as defined by the routes (e.g., authRoutes, userRoutes).
• Internal Flow in the Backend:
• Incoming HTTP requests pass through middleware (authentication, file upload handling, error handling).
• They are then routed to controllers (e.g., authController, userController) where requests are processed.
• Controllers call the service layer (business logic) to perform operations like user management, room allocation, or handling dormitory records.
• The service layer interacts with the models to perform database operations using the configuration defined in “config/db.js”.
• Auxiliary Flows:
• File uploads: Highlight the standalone module “upload” which manages excel files and is probably used within some controller/service workflows.
• Constant and utility modules provide common data and error handling across the system, ensuring consistency in processing date conversions or error reporting.
Important Architectural Patterns and Design Principles
• Layered Architecture: Each layer (routes, controllers, services, models, middleware) is clearly separated, promoting maintainability and clarity.
• Separation of Concerns: Frontend and backend are developed and deployed separately, focusing on UI and business logic respectively.
• RESTful API: The backend is designed following RESTful principles, with clearly structured endpoints and controllers.
• Use of Middleware: Cross-cutting concerns (authentication, error handling) are abstracted away using middleware modules.
• State Management in Frontend: Utilize Redux for managing application state, ensuring that the UI is synchronized with the backend data.
Specific Elements
• Clear labels for each module/component (e.g., “Authentication Controller”, “User Service”, “Redux Store”, etc.).
• Frontend → API Routes → Controllers → Services → Database
• Middleware intercepting requests (between routes and controllers)
• Service calls back for error handling or file uploads.
• A third distinct style for database and configuration components.
• If possible, indicate any dependencies (e.g., the mapping between functions in controllers and services).