# anujtambake936-ctrl/staywise architecture

> Architecture diagram of the GitHub repository anujtambake936-ctrl/staywise, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anujtambake936-ctrl/staywise
- Repository: https://github.com/anujtambake936-ctrl/staywise

## Overview

#### 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`](https://github.com/anujtambake936-ctrl/staywise/blob/main/app.js) (Express startup), [`.env.example`](https://github.com/anujtambake936-ctrl/staywise/blob/main/.env.example) (Environment configuration), [`models/listing.js`](https://github.com/anujtambake936-ctrl/staywise/blob/main/models/listing.js) (Listings), [`models/user.js`](https://github.com/anujtambake936-ctrl/staywise/blob/main/models/user.js) (Users and sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP application"]
  node_app["Express startup<br/>Node.js runtime<br/>[app.js]"]
  node_routes["Route modules<br/>Express routes"]
  node_controllers["Controllers<br/>request actions"]
  node_middleware["Request middleware<br/>auth and guards<br/>[middleware.js]"]
  node_errors["Async error handling<br/>error boundary<br/>[wrapAsync.js]"]
end

subgraph group_domain["Domain and persistence"]
  node_users[("Users and sessions<br/>identity model<br/>[user.js]")]
  node_listings[("Listings<br/>primary aggregate<br/>[listing.js]")]
  node_reviews[("Reviews<br/>relational model<br/>[review.js]")]
  node_payments[("Payments<br/>payment records<br/>[payment.js]")]
end

subgraph group_presentation["Rendering and browser"]
  node_ejs["EJS views<br/>server-rendered UI<br/>[boilerplate.ejs]"]
  node_browser["Browser assets<br/>client JavaScript<br/>[map.js]"]
end

subgraph group_integrations["External services and operations"]
  node_mongodb[("MongoDB<br/>persistence backend")]
  node_mapbox{{"Mapbox<br/>map service"}}
  node_cloudinary{{"Cloudinary<br/>image storage<br/>[cloudConfig.js]"}}
  node_seed["Seed bootstrap<br/>initialization script<br/>[index.js]"]
  node_seeddata["Seed data<br/>bootstrap content<br/>[data.js]"]
  node_environment["Environment configuration<br/>deployment secrets<br/>[.env.example]"]
end

node_app -->|"mounts"| node_routes
node_app -->|"applies"| node_middleware
node_app -->|"uses"| node_errors
node_app -->|"connects via Mongoose"| node_mongodb
node_routes -->|"dispatches to"| node_controllers
node_middleware -->|"checks sessions"| node_users
node_controllers -->|"registers and authenticates"| node_users
node_controllers -->|"manages"| node_listings
node_controllers -->|"creates and updates"| node_reviews
node_controllers -->|"records and queries"| node_payments
node_listings -->|"has feedback"| node_reviews
node_users -->|"persists in"| node_mongodb
node_listings -->|"persists in"| node_mongodb
node_reviews -->|"persists in"| node_mongodb
node_payments -->|"persists in"| node_mongodb
node_controllers -->|"renders"| node_ejs
node_ejs -->|"loads"| node_browser
node_browser -->|"renders maps with"| node_mapbox
node_controllers -->|"uploads listing images"| node_cloudinary
node_seed -->|"loads"| node_seeddata
node_seed -->|"initializes"| node_mongodb
node_environment -.->|"supplies runtime settings"| node_app
node_environment -.->|"supplies MAP_TOKEN"| node_mapbox
node_environment -.->|"supplies credentials"| node_cloudinary

click node_app "https://github.com/anujtambake936-ctrl/staywise/blob/main/app.js"
click node_middleware "https://github.com/anujtambake936-ctrl/staywise/blob/main/middleware.js"
click node_errors "https://github.com/anujtambake936-ctrl/staywise/blob/main/utils/wrapAsync.js"
click node_users "https://github.com/anujtambake936-ctrl/staywise/blob/main/models/user.js"
click node_listings "https://github.com/anujtambake936-ctrl/staywise/blob/main/models/listing.js"
click node_reviews "https://github.com/anujtambake936-ctrl/staywise/blob/main/models/review.js"
click node_payments "https://github.com/anujtambake936-ctrl/staywise/blob/main/models/payment.js"
click node_ejs "https://github.com/anujtambake936-ctrl/staywise/blob/main/views/layouts/boilerplate.ejs"
click node_browser "https://github.com/anujtambake936-ctrl/staywise/blob/main/public/js/map.js"
click node_cloudinary "https://github.com/anujtambake936-ctrl/staywise/blob/main/cloudConfig.js"
click node_seed "https://github.com/anujtambake936-ctrl/staywise/blob/main/init/index.js"
click node_seeddata "https://github.com/anujtambake936-ctrl/staywise/blob/main/init/data.js"
click node_environment "https://github.com/anujtambake936-ctrl/staywise/blob/main/.env.example"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_routes,node_controllers,node_middleware,node_errors toneBlue
class node_users,node_listings,node_reviews,node_payments toneAmber
class node_ejs,node_browser toneMint
class node_mongodb,node_mapbox,node_cloudinary,node_seed,node_seeddata,node_environment toneRose
```

## Components

### HTTP application

- [Express startup](https://github.com/anujtambake936-ctrl/staywise/blob/main/app.js): Node.js runtime · Composes middleware, routes, database access, sessions, static assets, and EJS. · `app.js`
- **Route modules**: Express routes · Declares listing, user, review, payment, and chat endpoints.
- **Controllers**: request actions · Implements business actions for each route area.
- [Request middleware](https://github.com/anujtambake936-ctrl/staywise/blob/main/middleware.js): auth and guards · Centralizes cross-cutting request behavior and authorization. · `middleware.js`
- [Async error handling](https://github.com/anujtambake936-ctrl/staywise/blob/main/utils/wrapAsync.js): error boundary · Normalizes asynchronous and application errors. · `utils/wrapAsync.js`

### Domain and persistence

- [Users and sessions](https://github.com/anujtambake936-ctrl/staywise/blob/main/models/user.js): identity model · Passport-backed registration, login, and authenticated sessions. · `models/user.js`
- [Listings](https://github.com/anujtambake936-ctrl/staywise/blob/main/models/listing.js): primary aggregate · Central accommodation content, browsing, editing, dashboards, and booking views. · `models/listing.js`
- [Reviews](https://github.com/anujtambake936-ctrl/staywise/blob/main/models/review.js): relational model · User feedback attached to listings. · `models/review.js`
- [Payments](https://github.com/anujtambake936-ctrl/staywise/blob/main/models/payment.js): payment records · Payment actions and booking history records. · `models/payment.js`

### Rendering and browser

- [EJS views](https://github.com/anujtambake936-ctrl/staywise/blob/main/views/layouts/boilerplate.ejs): server-rendered UI · Listing, payment, layout, navigation, and flash presentation. · `views/layouts/boilerplate.ejs`
- [Browser assets](https://github.com/anujtambake936-ctrl/staywise/blob/main/public/js/map.js): client JavaScript · Provides general client behavior and map display. · `public/js/map.js`

### External services and operations

- **MongoDB**: persistence backend · Mongoose database configured through DB_URL.
- **Mapbox**: map service · Map display using MAP_TOKEN.
- [Cloudinary](https://github.com/anujtambake936-ctrl/staywise/blob/main/cloudConfig.js): image storage · Stores uploaded listing images using environment credentials. · `cloudConfig.js`
- [Seed bootstrap](https://github.com/anujtambake936-ctrl/staywise/blob/main/init/index.js): initialization script · Loads bootstrap data outside normal application startup. · `init/index.js`
- [Seed data](https://github.com/anujtambake936-ctrl/staywise/blob/main/init/data.js): bootstrap content · `init/data.js`
- [Environment configuration](https://github.com/anujtambake936-ctrl/staywise/blob/main/.env.example): deployment secrets · Documents required database, session, map, and image-service variables. · `.env.example`

## Connections

- 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
