How aryan-upa/pg-finder-v2 works
Project Type & Purpose
• PG Finder is a full-stack web application built using Node.js, Express, and MongoDB.
• Its primary purpose is to help users (riders) find and book PGs/hostels while also allowing providers to add and manage properties, with an admin module overseeing the overall operations.
• The README clearly indicates that the application is modular with three primary roles: Rider, Provider, and Admin.
Main Components Identification
a. Frontend / Presentation Layer:
• “views” directory: EJS templates for various pages (home, login, dashboards, property details), including separate layouts and partials.
• “public” directory: Static files including CSS, JavaScript, images, and site-data files.
b. Routing and Controllers:
• “routes” directory: Contains route files like admin.js, auth.js, booking.js, contact.js, property.js, provider.js, review.js, rider.js. These files handle endpoint definitions and traffic routing.
c. Middleware:
• “middlewares” directory: Includes common middleware functions for features such as file uploading, role validation, schema validation, and others.
d. Data Models:
• “models” directory: Defines the data structure for different entities such as booking, contact, login, property, provider, register, review, and rider.
e. Configuration & Application Bootstrapping:
• Files like app.js and config.js initialize the application and setup configurations.
f. Utilities & Helpers:
• “utils” directory: Contains modules for internal processes (cron jobs, database connection, key generation, mail sending, validation schemas, and more).
g. Data static file:
• “data” directory: May contain JSON data such as top_property.json, likely used for initial data seeding or reference.
Relationships and Interactions
• The central Express app (app.js) is configured in conjunction with config.js and loads the routes. Incoming HTTP requests route to controllers present in the “routes” directory.
• Each route may use one or more middleware functions (from the “middlewares” folder) to perform validations or handle file uploads.
• Data interaction is abstracted through the defined models in “models” which interact with the underlying database (MongoDB).
• The “views” render the dynamic HTML pages using data passed from the controllers.
• Utility modules perform supplementary functions (e.g., sending emails on booking success, running cron jobs for background tasks, handling database connections).
Architectural Patterns and Design Principles
• MVC (Model-View-Controller) Pattern: Clearly visible with models defining data, routes and controllers managing the business logic, and views handling the presentation layer.
• Layered Architecture: Separation of concerns exists across static assets (public), server-side logic (app.js, routes, middleware, and models), and utility functions.
• Modularization by Roles: The application is divided into Rider, Provider, and Admin modules, each with specific routes and associated views.
• Use of middleware for separation of common concerns such as validation, file uploads, and role checking.
Final Implementation Advice
• Drill down into the server by splitting it into logical directories (Routes, Middlewares, Models, Utilities) and then further detail the role-specific modules.