How adityakhattri21/postit works
Main Components
• Frontend:
• Represented by the static files in the “public” directory (with subfolders for “home”, “login”, and “signup”).
• These pages connect to the backend via client-side JavaScript.
• Backend Server:
• Centralized in “server.js”. It initiates the Express application.
• Controllers:
• Found in the “controller” directory (authController.js, postController.js, commentController.js). They handle business logic for user authentication, post management, and comment management.
• Routes:
• Defined in the “routes” folder (authRouter.js, postRouter.js, commentRouter.js). They map HTTP endpoints to the corresponding controllers.
• Middleware:
• In the “middleware” folder. This contains error handling, authentication (authMiddleware.js), and asynchronous error handler (asyncErrors.js).
• Database Layer:
• The “database” folder holds the connection logic (connect.js) and models (userModel, postModel, commentModel) for MongoDB using Mongoose or similar.
• Utility Modules:
• “utils” folder for generic error handling.
• Infrastructure/Deployment:
• Docker related files (Dockerfile, docker-compose.yml) and configuration (environment variable instructions in README) which illustrate how the application can be containerized and deployed.
Component Relationships and Interactions
• User interactions begin at the frontend (public HTML/JS pages). The UI sends HTTP requests to the backend.
• Incoming HTTP requests are routed via the routes folder, which delegates them to the appropriate controllers.
• Controllers process requests and interact with the database models (from the “database/models” directory) to execute CRUD operations.
• Middleware components sit in the request pipeline to handle authentication, error handling, and asynchronous operations.
• The database connection (database/connect.js) is established when the server starts, and all models use this connection to interact with the MongoDB instance.
Architectural Patterns and Design Principles
• MVC-like Separation: The project follows a pattern where the routes (Controller interface) forward requests to controllers (Logic Layer), which then interact with models (Data Layer).
• RESTful API Design: Routes define clear endpoints for authentication, posts, and comments.
• Middleware Pipeline: Utilization of custom middleware for error handling and authentication.
• Containerization: Deployment using Docker and Docker Compose ensures a consistent environment between local development and production.
Relevant Technology & Frameworks
• Node.js with ExpressJS for the backend server.
• MongoDB (and possibly Mongoose) for the database.
• Static HTML, CSS, and client-side JavaScript for the frontend.
• Docker for containerization.
• JWT for authentication.
• Other utilities such as dotenv for environment variable management (implied by the .env file instructions).