How ccb16/peli_backend works
Project Components
• Server Layer: This is comprised of the main entry points (server.js and app.js) that initialize and run the Express application.
• Routing: The routes (found in routes/authRoutes.js) define endpoints for user authentication, mapping HTTP requests to controller actions.
• Controllers: The business logic is encapsulated in controllers (e.g., controllers/authController.js), which process requests, handle validation, and interact with the database.
• Database Access: The database connection module (db/connection.js) manages MySQL connectivity and defines how queries are executed.
• Environment/Configuration: The .env file holds configuration values (database connection details, JWT secret, etc.). This is critical for parameterizing the application.
• Testing: The __tests__ directory contains unit tests (e.g., auth.test.js) with Jest and supertest, which simulate API interactions ensuring proper behavior.
Relationships and Interactions
• Incoming HTTP requests hit the Express server where the defined routes (authRoutes.js) are invoked.
• Routes pass requests onto the appropriate controller methods (such as the authController.js) that encapsulate the authentication logic.
• Controllers interact with the database by using the connection module in db/connection.js to query or update the MySQL database.
• Responses are sent back to the client while JWT tokens are created and validated as part of the security process.
• Additionally, environment configuration (dotenv) is used at start-up to load .env variables, and tests run separately to validate the functionality.
Architectural Patterns & Design Principles
• Modular Design: The project separates concerns into distinct modules (controllers, routes, database access) which enhances maintainability.
• MVC-like Approach: Although simple and focused on authentication, the separation between routes (as a lightweight view or interface), controllers (logic), and database (model) follows the MVC mindset.
• Test Driven/Testing Integration: The inclusion of Jest and supertest suggests that tests are essential to validate the core features.
• Security Practices: Use of JWT and bcrypt highlights that secure practices are embedded in the system design.
Final Checklist
• Client ---> Server ---> Routes ---> Controllers ---> Database.
• Environment feeds configuration into Server and Database.
• Testing simulates client requests.