How luciano655dev/daykeeper-api works
Main Components
• API Entry Point & Configuration:
• The main entry is app.js along with a config.js for global settings and constants. This is where the server is initialized.
• Routing Layer:
• The “routes” directory organizes all the endpoints (adminRoutes, authRoutes, dailyQuestionRoutes, dayRoutes, locationRoutes, postRoutes, searchRoutes, storiesRoutes, userRoutes). These routes map incoming HTTP requests to the appropriate controllers.
• Controller Layer:
• The “api/controllers” directory is where you find different controllers (admin, auth, daily question, day, location, post, stories, user). These components handle parsing the request and invoking business logic.
• Business Logic/Service Layer:
• Within “api/services” there are dedicated service files separated by domain (admin, auth, dailyQuestion, day, post, stories, user). They encapsulate the core business operations and often call the repository layer.
• Data Access (Repositories) Layer:
• The “api/repositories” directory’s structure (including “common”, “pipelines”, and a “hideProject” subfolder) suggests the use of pipeline patterns where data is validated and transformed before being sent to or retrieved from the database.
• Data Models:
• In “api/models”, MongoDB models are defined for various entities such as User, Post, CommentLikes, Stories, DailyQuestion, and so on.
• Middleware & Validations:
• The “middlewares” folder organizes various authentication, authorization, validation, and error-handling layers that are applied to many routes.
• Background Jobs:
• The “api/jobs” folder handles scheduled tasks like user cleanup and sending notifications.
• Utilities & External Services:
• Within “api/utils”, components such as email handling, timezone conversion, file deletion, and notification services assist the main business logic.
• External Dependencies:
• The integration with technologies such as AWS (for S3 in api/config/awsS3Config.js), and the use of Express, MongoDB, and NodeJS are crucial backbone services.
Relationships & Data Flow
• External Clients (e.g., App, Web) → HTTP Requests hit the defined endpoints in the “routes” directory.
• Routes then forward the requests through Middlewares (authentication, token validation, file validations, etc.) to the Controllers.
• Controllers parse requests, then delegate the processing to Service files.
• Service files execute business logic and interact with the Repository layer to perform CRUD operations on data models.
• Repositories use pipelines to gather and process required data before passing it to the services.
• Model operations interact directly with the MongoDB database.
• Background Jobs run on timed intervals (separate processes) performing tasks like deleting unconfirmed users and sending notifications.
• Utilities provide cross-cutting support like email notifications and file management in AWS.
• The configuration files (like config.js in the root and awsS3Config.js in the api/config folder) tie together environment-specific settings.
Architectural Patterns & Design Principles
• MVC (or close to layered architecture) – Routes/Controllers (Presentation), Services (Business Logic), Repositories/Models (Data Access).
• Separation of Concerns – Distinct directories for validations, middleware, models, repositories, services, and jobs.
• Pipeline/Chain-of-Responsibility – Seen in the repository pipelines and validations, ensuring data is processed in stages.
• Modularization – The project structure clearly separates modules by their responsibilities (such as “admin”, “user”, “day”, etc.) for maintainability and scalability.
Final Recommendations
• Always cross-check against the file tree to ensure every major module is represented.