# g-o-u-t-a-m/airbnb architecture

> Architecture diagram of the GitHub repository g-o-u-t-a-m/airbnb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/g-o-u-t-a-m/airbnb
- Repository: https://github.com/g-o-u-t-a-m/airbnb

## Overview

#### Purpose and Runtime

This is a server-rendered Node.js/Express marketplace-style listings application. It manages listings, reviews, and user accounts, rendering EJS pages rather than exposing a standalone frontend API. The main process starts in `app.js`; package/runtime dependencies are declared in `package.json`.

#### Application Composition

`app.js` assembles the Express application: middleware, sessions/flash messaging, authentication integration, static assets, view engine/layout support, route mounting, and centralized error rendering. Deployment configuration is separated into `cloudConfig.js`, indicating environment-specific database or hosted-service setup.

Key paths:
- `app.js`
- `cloudConfig.js`
- `views/layouts/boilerplate.ejs`

#### Domain Persistence Model

MongoDB/Mongoose-style domain models define the core persisted graph:
- Listings are the primary resource in `models/listing.js`.
- Reviews belong to listings and are modeled in `models/review.js`.
- Users/credentials and identity data are modeled in `models/user.js`.

The listing-review-user relationship is the application’s central ownership and authorization boundary.

Key paths:
- `models/listing.js`
- `models/review.js`
- `models/user.js`

#### Request Routing and Controllers

Routes partition the HTTP surface by resource, then delegate request handling to controllers:
- Listing creation, browsing, editing, deletion, and detail pages flow from `routes/listing.js` to `controllers/listings.js`.
- Nested or listing-associated review operations flow from `routes/review.js` to `controllers/reviews.js`.
- Signup, login, and logout flow from `routes/user.js` to `controllers/users.js`.

This keeps URL/resource definitions separate from persistence and rendering decisions.

Key paths:
- `routes/listing.js`
- `routes/review.js`
- `routes/user.js`
- `controllers/listings.js`
- `controllers/reviews.js`
- `controllers/users.js`

#### Validation, Authentication, and Authorization Boundary

Request validation schemas are centralized in `schema.js`. Cross-cutting guards live in `middleware.js`, which is the likely enforcement point for login requirements, ownership checks, review permissions, and validation before controllers mutate data. User authentication is connected to the user model and session-aware app setup.

Key paths:
- `middleware.js`
- `schema.js`
- `models/user.js`

#### Server-Rendered UI Flow

Controllers render EJS templates for listing and account flows. Shared layout, navigation, footer, and flash-message partials provide application-wide UI composition. Browser styling and small client-side behavior are served from `public`.

Key paths:
- `views/listings/index.ejs`
- `views/listings/show.ejs`
- `views/users/login.ejs`
- `views/includes/navbar.ejs`
- `public/css/style.css`

#### Error Handling and Seed Data

Async route/controller failures are funneled through `utils/wrapAsync.js`; typed application errors use `utils/expressError.js` and are rendered through `views/error.ejs`. Initial database content is supplied by the initialization scripts, enabling a repeatable development dataset.

Key paths:
- `utils/wrapAsync.js`
- `utils/expressError.js`
- `views/error.ejs`
- `init/index.js`
- `init/data.js`

Main entry points: [`app.js`](https://github.com/g-o-u-t-a-m/airbnb/blob/main/app.js) (Express app), [`middleware.js`](https://github.com/g-o-u-t-a-m/airbnb/blob/main/middleware.js) (Guards & validation), [`models/listing.js`](https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/listing.js) (Listing model), [`models/user.js`](https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/user.js) (User model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_app["Express app<br/>[app.js]"]
  node_cloud_config["Cloud configuration<br/>deployment config<br/>[cloudConfig.js]"]
end

subgraph group_http["HTTP handling"]
  node_listing_routes["Listing routes<br/>route module<br/>[listing.js]"]
  node_review_routes["Review routes<br/>route module<br/>[review.js]"]
  node_user_routes["User routes<br/>route module<br/>[user.js]"]
  node_middleware["Guards &amp; validation<br/>middleware<br/>[middleware.js]"]
  node_schemas["Validation schemas<br/>[schema.js]"]
  node_listing_controller["Listing controller<br/>[listings.js]"]
  node_review_controller["Review controller<br/>[reviews.js]"]
  node_user_controller["User controller<br/>[users.js]"]
end

subgraph group_domain["Domain &amp; persistence"]
  node_listing[("Listing model<br/>Mongoose model<br/>[listing.js]")]
  node_review[("Review model<br/>Mongoose model<br/>[review.js]")]
  node_user[("User model<br/>Mongoose auth model<br/>[user.js]")]
  node_database[("MongoDB<br/>database")]
  node_seed["Seed data<br/>initialization<br/>[index.js]"]
end

subgraph group_ui["Server-rendered UI"]
  node_layout["Shared layout<br/>EJS layout<br/>[boilerplate.ejs]"]
  node_listing_views["Listing pages<br/>EJS views<br/>[index.ejs]"]
  node_login_view["Login page<br/>EJS view<br/>[login.ejs]"]
  node_error_flow["Async error rendering<br/>error pipeline<br/>[wrapAsync.js]"]
  node_error_view["Error page<br/>EJS view<br/>[error.ejs]"]
end

node_cloud_config -.->|"configures"| node_app
node_app -->|"mounts"| node_listing_routes
node_app -->|"mounts"| node_review_routes
node_app -->|"mounts"| node_user_routes
node_app -->|"uses view layout"| node_layout
node_app -->|"centralizes failures"| node_error_flow
node_listing_routes -->|"applies guards"| node_middleware
node_review_routes -->|"applies guards"| node_middleware
node_user_routes -->|"delegates"| node_user_controller
node_listing_routes -->|"delegates"| node_listing_controller
node_review_routes -->|"delegates"| node_review_controller
node_middleware -->|"validates with"| node_schemas
node_middleware -->|"authenticates"| node_user
node_listing_controller -->|"manages"| node_listing
node_review_controller -->|"manages"| node_review
node_user_controller -->|"manages"| node_user
node_review -->|"belongs to"| node_listing
node_listing -->|"owned by"| node_user
node_listing -->|"persists to"| node_database
node_review -->|"persists to"| node_database
node_user -->|"persists to"| node_database
node_listing_controller -->|"renders"| node_listing_views
node_user_controller -->|"renders"| node_login_view
node_listing_views -->|"composes with"| node_layout
node_login_view -->|"composes with"| node_layout
node_error_flow -->|"renders"| node_error_view
node_seed -.->|"initializes"| node_database

click node_app "https://github.com/g-o-u-t-a-m/airbnb/blob/main/app.js"
click node_cloud_config "https://github.com/g-o-u-t-a-m/airbnb/blob/main/cloudConfig.js"
click node_listing_routes "https://github.com/g-o-u-t-a-m/airbnb/blob/main/routes/listing.js"
click node_review_routes "https://github.com/g-o-u-t-a-m/airbnb/blob/main/routes/review.js"
click node_user_routes "https://github.com/g-o-u-t-a-m/airbnb/blob/main/routes/user.js"
click node_middleware "https://github.com/g-o-u-t-a-m/airbnb/blob/main/middleware.js"
click node_schemas "https://github.com/g-o-u-t-a-m/airbnb/blob/main/schema.js"
click node_listing_controller "https://github.com/g-o-u-t-a-m/airbnb/blob/main/controllers/listings.js"
click node_review_controller "https://github.com/g-o-u-t-a-m/airbnb/blob/main/controllers/reviews.js"
click node_user_controller "https://github.com/g-o-u-t-a-m/airbnb/blob/main/controllers/users.js"
click node_listing "https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/listing.js"
click node_review "https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/review.js"
click node_user "https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/user.js"
click node_layout "https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/layouts/boilerplate.ejs"
click node_listing_views "https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/listings/index.ejs"
click node_login_view "https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/users/login.ejs"
click node_error_flow "https://github.com/g-o-u-t-a-m/airbnb/blob/main/utils/wrapAsync.js"
click node_error_view "https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/error.ejs"
click node_seed "https://github.com/g-o-u-t-a-m/airbnb/blob/main/init/index.js"

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_cloud_config toneBlue
class node_listing_routes,node_review_routes,node_user_routes,node_middleware,node_schemas,node_listing_controller,node_review_controller,node_user_controller toneAmber
class node_listing,node_review,node_user,node_database,node_seed toneMint
class node_layout,node_listing_views,node_login_view,node_error_flow,node_error_view toneRose
```

## Components

### Runtime

- [Express app](https://github.com/g-o-u-t-a-m/airbnb/blob/main/app.js): application · Composes middleware, sessions, routes, views, and error handling. · `app.js`
- [Cloud configuration](https://github.com/g-o-u-t-a-m/airbnb/blob/main/cloudConfig.js): deployment config · `cloudConfig.js`

### HTTP handling

- [Listing routes](https://github.com/g-o-u-t-a-m/airbnb/blob/main/routes/listing.js): route module · `routes/listing.js`
- [Review routes](https://github.com/g-o-u-t-a-m/airbnb/blob/main/routes/review.js): route module · Nested listing review endpoints. · `routes/review.js`
- [User routes](https://github.com/g-o-u-t-a-m/airbnb/blob/main/routes/user.js): route module · `routes/user.js`
- [Guards & validation](https://github.com/g-o-u-t-a-m/airbnb/blob/main/middleware.js): middleware · Enforces login, ownership, review permissions, and request validation. · `middleware.js`
- [Validation schemas](https://github.com/g-o-u-t-a-m/airbnb/blob/main/schema.js): validation · `schema.js`
- [Listing controller](https://github.com/g-o-u-t-a-m/airbnb/blob/main/controllers/listings.js): controller · `controllers/listings.js`
- [Review controller](https://github.com/g-o-u-t-a-m/airbnb/blob/main/controllers/reviews.js): controller · `controllers/reviews.js`
- [User controller](https://github.com/g-o-u-t-a-m/airbnb/blob/main/controllers/users.js): controller · `controllers/users.js`

### Domain & persistence

- [Listing model](https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/listing.js): Mongoose model · Primary marketplace resource. · `models/listing.js`
- [Review model](https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/review.js): Mongoose model · Belongs to a listing. · `models/review.js`
- [User model](https://github.com/g-o-u-t-a-m/airbnb/blob/main/models/user.js): Mongoose auth model · Credentials and identity data. · `models/user.js`
- **MongoDB**: database
- [Seed data](https://github.com/g-o-u-t-a-m/airbnb/blob/main/init/index.js): initialization · Supplies repeatable development content. · `init/index.js`

### Server-rendered UI

- [Shared layout](https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/layouts/boilerplate.ejs): EJS layout · Application-wide page composition. · `views/layouts/boilerplate.ejs`
- [Listing pages](https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/listings/index.ejs): EJS views · Index and detail rendering. · `views/listings/index.ejs`
- [Login page](https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/users/login.ejs): EJS view · `views/users/login.ejs`
- [Async error rendering](https://github.com/g-o-u-t-a-m/airbnb/blob/main/utils/wrapAsync.js): error pipeline · Wraps async failures and renders typed application errors. · `utils/wrapAsync.js`
- [Error page](https://github.com/g-o-u-t-a-m/airbnb/blob/main/views/error.ejs): EJS view · `views/error.ejs`

## Connections

- Cloud configuration → Express app: configures
- Express app → Listing routes: mounts
- Express app → Review routes: mounts
- Express app → User routes: mounts
- Express app → Shared layout: uses view layout
- Express app → Async error rendering: centralizes failures
- Listing routes → Guards & validation: applies guards
- Review routes → Guards & validation: applies guards
- User routes → User controller: delegates
- Listing routes → Listing controller: delegates
- Review routes → Review controller: delegates
- Guards & validation → Validation schemas: validates with
- Guards & validation → User model: authenticates
- Listing controller → Listing model: manages
- Review controller → Review model: manages
- User controller → User model: manages
- Review model → Listing model: belongs to
- Listing model → User model: owned by
- Listing model → MongoDB: persists to
- Review model → MongoDB: persists to
- User model → MongoDB: persists to
- Listing controller → Listing pages: renders
- User controller → Login page: renders
- Listing pages → Shared layout: composes with
- Login page → Shared layout: composes with
- Async error rendering → Error page: renders
- Seed data → MongoDB: initializes
