How pruthavik01/roombuddy works
Project Type & Purpose
• This is a full-stack web application (RoomBuddy) for listing and booking hostels, built on Node.js/Express with MongoDB as the database and EJS templates on the front end.
• It follows a classical MVC pattern, augmented by middleware and external services (Cloudinary, SendGrid, OSM/Leaflet).
Main Components
a. Client (Browser)
• Static assets: HTML (rendered from EJS), CSS/Bootstrap, JS (map.js, script.js)
• Interacts over HTTP/HTTPS with Express server.
b. Web Server (Express.js)
• app.js: Application entry point
• cloudConfig.js: Cloudinary setup
• middleware.js & utils (ExpressError, wrapAsync)
• schema.js: Joi validation
• Controllers: listings.js, reviews.js, users.js
• Routes: listing.js, review.js, user.js
• Session management: express-session + connect-mongo
• Authentication: Passport.js (local strategy) + passport-local-mongoose
c. Database (MongoDB)
• Collections: users, listings, reviews
• init scripts for seeding (init/index.js & init/data.js)
• Mongoose models & schemas in models/
d. External Services
• Cloudinary (image storage) via multer-storage-cloudinary
• SendGrid (OTP email verification)
• MapTiler / OpenStreetMap / Nominatim (geocoding & map tiles)
e. Deployment/Hosting
• Hosted on Render (as indicated by public URL)
• Environment variables managed by dotenv
Relationships & Data Flow
• 1. Client sends HTTP requests (GET/POST/PATCH/DELETE) to Express routes
• 2. Express routes ➔ controller methods (wrapped in async error handler)
• 3. Controllers perform:
• Input validation via Joi (schema.js)
• Business logic (e.g., check owner-only access)
• DB operations via Mongoose models
• File uploads to Cloudinary (if any)
• OTP generation & email via SendGrid (signup flow)
• Session & cookie handling
• 4. Database reads/writes to MongoDB
• 5. Controllers render EJS views or respond with redirects/JSON
• 6. Client receives HTML/CSS/JS, updates UI (e.g., Leaflet map)
Architectural Patterns & Design Principles
• MVC:
• Models: /models
• Views: /views (EJS templates + includes + layouts)
• Controllers: /controllers
• Middleware chain:
• Authentication & authorization
• Error handling (ExpressError)
• Validation (Joi)
• Static asset serving (/public)
• Service Integration Layer: external API wrappers (Cloudinary, SendGrid, Nominatim)
• Single codebase monolith but logically separated into layers