How tanishk794/taskback works
Main Components
• Backend Server: The entry point is server.js, which starts the Node.js/Express server.
• API Endpoints: There are two main APIs – Authentication (AUTH API) and Task management (TASK API).
• Controllers: authController.js and taskController.js handle the logic for incoming requests.
• Routes: The authRoutes.js and taskRoutes.js files define URL endpoints and map them to controller functions.
• Middleware: The authMiddleware.js file validates requests for secure operations.
• Models: Task.js and User.js reside in the model directory to define the data structure.
• Database Connection: src/config/connectDb.js sets up the connection to a MongoDB cloud instance.
• Utility: src/utils/generateToken.js is responsible for generating authentication tokens.
• Environment/Configuration: .env is used to store configuration values.
Relationships and Interactions
• A client (or frontend) sends HTTP requests (e.g., registration, login, task operations) to the backend.
• Requests flow through the corresponding route (e.g., /api/auth or /api/tasks).
• For secure endpoints, authMiddleware intercepts the request for token validation.
• Routes then hand off the requests to the appropriate controller.
• Controllers perform business logic and interact with the models (User and Task) to perform database operations.
• The database operations are managed through the MongoDB connection that is established via src/config/connectDb.js.
• Utilities like generateToken are used within the authentication controller to create tokens.
• Responses flow back through the route to the client.
Architectural Patterns and Design Principles
• MVC (Model-View-Controller)-inspired separation: Though it’s an API backend, hosting models, controllers, middleware, and routes gives a clear separation of concerns.
• Modular design: Each logical component is isolated for better maintainability.
• Environment-based configuration: Using .env provides flexibility to swap configurations without code modifications.
Important Labels and Details
• Endpoints names in the Routes layer (e.g., /api/auth/register, /api/tasks/).