How anujtambake936-ctrl/staywise works
Purpose and startup
Staywise is a server-rendered Node.js accommodation/listing application. It manages user accounts, listings, reviews, image-backed listing content, maps, chat endpoints, and payment/history flows. The runtime starts at app.js, which composes Express middleware, route modules, database access, sessions/authentication, static assets, and EJS rendering.
HTTP composition and request boundaries
Routes separate URL/middleware declarations from business actions:
• routes/listing.js → controllers/listings.js
• routes/user.js → controllers/users.js
• routes/review.js → controllers/reviews.js
• routes/payments.js → controllers/payments.js
• routes/chat.js → controllers/chat.js
Cross-cutting request behavior is centralized in middleware.js; asynchronous failures and application errors are normalized through utils/wrapAsync.js and utils/ExpressError.js.
Identity and authorization
User registration and login are handled by the user route/controller layer, with the persistent user shape in models/user.js. Passport is a declared architectural dependency, so authenticated session state is expected to gate protected listing, review, payment, and possibly chat actions. Session security depends on SESSION_SECRET.
Listings as the primary domain aggregate
Listings are the central content resource, persisted in models/listing.js and operated on by controllers/listings.js. The listing route layer supports creation, editing, browsing, detail display, dashboard, and booking-oriented views. Server-rendered screens are under views/listings/, including index.ejs, show.ejs, dashboard.ejs, and listingBookings.ejs.
Reviews and relational content
Reviews are a separate persisted domain object in models/review.js, exposed through routes/review.js and controllers/reviews.js. This layer represents user-generated feedback attached to listing workflows; listing detail rendering (views/listings/show.ejs) is the natural presentation boundary for review data.
Payments and booking history
Payment actions are isolated from listing CRUD in routes/payments.js and controllers/payments.js, with records modeled by models/payment.js. The UI boundary is views/payments/success.ejs and views/payments/history.ejs; listing booking presentation is kept in views/listings/listingBookings.ejs. No specific external payment processor is identified by the repository inputs.
Rendering, browser code, and external services
The app renders EJS views using the shared base layout views/layouts/boilerplate.ejs and reusable navigation/flash fragments in views/includes/. Browser assets in public/js/map.js and public/js/script.js support client behavior; Mapbox uses MAP_TOKEN for map display. Cloudinary integration is configured in cloudConfig.js and uses CLOUD_NAME, CLOUD_API_KEY, and CLOUD_API_SECRET for image upload/storage. MongoDB is the persistence backend via Mongoose, configured through DB_URL.
Initialization and operational configuration
Seed/bootstrap data is represented by init/data.js and executed from init/index.js, separate from normal application startup. Required deployment configuration is documented by .env.example; secrets and service credentials remain environment-provided rather than repository-stored.
Main entry points: app.js Express startup · .env.example Environment configuration · listing.js Listings · user.js Users and sessions
Components 17
HTTP application
- Express startup · Composes middleware, routes, database access, sessions, static assets, and EJS.
app.js - Route modules · Declares listing, user, review, payment, and chat endpoints.
- Controllers · Implements business actions for each route area.
- Request middleware · Centralizes cross-cutting request behavior and authorization.
middleware.js - Async error handling · Normalizes asynchronous and application errors.
utils/wrapAsync.js
Domain and persistence
- Users and sessions · Passport-backed registration, login, and authenticated sessions.
models/user.js - Listings · Central accommodation content, browsing, editing, dashboards, and booking views.
models/listing.js - Reviews · User feedback attached to listings.
models/review.js - Payments · Payment actions and booking history records.
models/payment.js
Rendering and browser
- EJS views · Listing, payment, layout, navigation, and flash presentation.
views/layouts/boilerplate.ejs - Browser assets · Provides general client behavior and map display.
public/js/map.js
External services and operations
- MongoDB · Mongoose database configured through DB_URL.
- Mapbox · Map display using MAP_TOKEN.
- Cloudinary · Stores uploaded listing images using environment credentials.
cloudConfig.js - Seed bootstrap · Loads bootstrap data outside normal application startup.
init/index.js - Seed data
init/data.js - Environment configuration · Documents required database, session, map, and image-service variables.
.env.example
Connections 24
- Express startup → Route modules: mounts
- Express startup → Request middleware: applies
- Express startup → Async error handling: uses
- Express startup → MongoDB: connects via Mongoose
- Route modules → Controllers: dispatches to
- Request middleware → Users and sessions: checks sessions
- Controllers → Users and sessions: registers and authenticates
- Controllers → Listings: manages
- Controllers → Reviews: creates and updates
- Controllers → Payments: records and queries
- Listings → Reviews: has feedback
- Users and sessions → MongoDB: persists in
- Listings → MongoDB: persists in
- Reviews → MongoDB: persists in
- Payments → MongoDB: persists in
- Controllers → EJS views: renders
- EJS views → Browser assets: loads
- Browser assets → Mapbox: renders maps with
- Controllers → Cloudinary: uploads listing images
- Seed bootstrap → Seed data: loads
- Seed bootstrap → MongoDB: initializes
- Environment configuration → Express startup: supplies runtime settings
- Environment configuration → Mapbox: supplies MAP_TOKEN
- Environment configuration → Cloudinary: supplies credentials