# farvejfaru/hotel-booking-app architecture

> Architecture diagram of the GitHub repository farvejfaru/hotel-booking-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/farvejfaru/hotel-booking-app
- Repository: https://github.com/farvejfaru/hotel-booking-app

## Overview

##### Project type and purpose
- WanderLust is a full-stack CRUD web application:
- Backend: Node.js + Express.js
- Frontend: EJS templates + CSS served as static assets
- Database: MongoDB via Mongoose ODM
- Purpose: Allow users to view, create, edit, delete travel property listings.

##### File structure
- Top-level files
- app.js – app entry, Express server, routes, middleware
- package.json / package-lock.json – dependencies, scripts
- Directories
- init/ – database seeding scripts (data.js, index.js)
- models/ – Mongoose schema (listing.js)
- views/ – EJS templates
– layouts/ (boilerplate.ejs)
– includes/ (navbar.ejs, footer.ejs)
– listings/ (CRUD pages)
- public/ – static assets (CSS)
- Config files
- .gitignore, README.md

##### Extract architectural insights from README
- MVC pattern:
- Models (Mongoose)
- Views (EJS templates)
- Controllers / Routes (in app.js)
- Method-override middleware for PUT/DELETE
- Seed script to initialize the MongoDB dataset

##### Main components & interactions
a. Client (Browser)
– Sends HTTP requests for pages and form submissions
b. Express Server (app.js)
– Routing layer: defines GET/POST/PUT/DELETE for “/listings”
– Controller logic: calls model methods, picks views to render
– Middleware: body-parser, method-override, static file serving
c. View Layer
– EJS templates (layouts + partials + listing pages)
– CSS loaded from /public/css/style.css
d. Data Access Layer
– Mongoose model (models/listing.js)
– CRUD operations against MongoDB
e. Database
– MongoDB instance (local mongod)
f. Initialization Service
– init/index.js reads sample data (init/data.js) → populates DB

##### Architectural patterns & principles
- MVC separation: clean layering of Presentation, Business Logic, Data Access
- Single Express instance handles routing + middleware
- Reusable view components with EJS partials & layouts
- Seed/Init script separated from runtime code

##### Minimum elements
- Labels: “Client (Browser)”, “Express Server (app.js)”, “View Engine (EJS)”, “Model (Mongoose)”, “Database (MongoDB)”, “Init Service”

## Diagram (Mermaid)

```mermaid
graph TB
    Browser("Client (Browser)"):::external

    subgraph "Application Layer"
        Express("Express Server\n(app.js)"):::server
        subgraph Middleware
            BodyParser("body-parser"):::code
            MethodOverride("method-override"):::code
            StaticServe("static assets"):::code
        end
        Express --> BodyParser
        Express --> MethodOverride
        Express --> StaticServe
    end

    Browser -->|"GET/POST/PUT/DELETE /listings"| Express

    subgraph "View Layer"
        ViewEngine("EJS Engine"):::server
        Layout("boilerplate.ejs"):::code
        Nav("navbar.ejs"):::code
        Footer("footer.ejs"):::code
        IndexView("index.ejs"):::code
        ShowView("show.ejs"):::code
        NewView("new.ejs"):::code
        EditView("edit.ejs"):::code

        Express --> ViewEngine
        ViewEngine --> Layout
        ViewEngine --> Nav
        ViewEngine --> Footer
        ViewEngine --> IndexView
        ViewEngine --> ShowView
        ViewEngine --> NewView
        ViewEngine --> EditView
    end

    subgraph "Data Layer"
        Model("Listing Model\n(models/listing.js)"):::code
        Express -->|"CRUD: find()/create()/update()/delete()"| Model
    end

    DB("MongoDB"):::db
    Model -->|"Mongoose ODM"| DB

    StaticAsset("style.css"):::code
    StaticServe --> StaticAsset

    subgraph "Init Service"
        InitIndex("init/index.js"):::code
        InitData("init/data.js"):::code
        InitIndex --> InitData
        InitIndex -->|--write sample data-->| DB
    end

    subgraph "Config & Metadata"
        Pkg("package.json"):::config
        PkgLock("package-lock.json"):::config
        Readme("README.md"):::config
        Gitignore(".gitignore"):::config
    end

    classDef server fill:#bef,stroke:#000,stroke-width:1px
    classDef code fill:#afa,stroke:#000,stroke-width:1px
    classDef external fill:#fea,stroke:#000,stroke-width:1px
    classDef db fill:#fdb,stroke:#000,stroke-width:1px
    classDef config fill:#fca,stroke:#000,stroke-width:1px

    click Express "https://github.com/farvejfaru/hotel-booking-app/blob/main/app.js"
    click Model "https://github.com/farvejfaru/hotel-booking-app/blob/main/models/listing.js"
    click InitIndex "https://github.com/farvejfaru/hotel-booking-app/blob/main/init/index.js"
    click InitData "https://github.com/farvejfaru/hotel-booking-app/blob/main/init/data.js"
    click Layout "https://github.com/farvejfaru/hotel-booking-app/blob/main/views/layouts/boilerplate.ejs"
    click Nav "https://github.com/farvejfaru/hotel-booking-app/blob/main/views/includes/navbar.ejs"
    click Footer "https://github.com/farvejfaru/hotel-booking-app/blob/main/views/includes/footer.ejs"
    click IndexView "https://github.com/farvejfaru/hotel-booking-app/blob/main/views/listings/index.ejs"
    click ShowView "https://github.com/farvejfaru/hotel-booking-app/blob/main/views/listings/show.ejs"
    click NewView "https://github.com/farvejfaru/hotel-booking-app/blob/main/views/listings/new.ejs"
    click EditView "https://github.com/farvejfaru/hotel-booking-app/blob/main/views/listings/edit.ejs"
    click StaticAsset "https://github.com/farvejfaru/hotel-booking-app/blob/main/public/css/style.css"
    click Pkg "https://github.com/farvejfaru/hotel-booking-app/blob/main/package.json"
    click PkgLock "https://github.com/farvejfaru/hotel-booking-app/blob/main/package-lock.json"
    click Readme "https://github.com/farvejfaru/hotel-booking-app/blob/main/README.md"
    click Gitignore "https://github.com/farvejfaru/hotel-booking-app/blob/main/.gitignore"
```
