# igoswamik/yelpcamp architecture

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

- Interactive diagram: https://gitdiagram.com/igoswamik/yelpcamp
- Repository: https://github.com/igoswamik/yelpcamp

## Overview

##### Project type and purpose
- YelpCamp is a full‑stack, monolithic web application built with Node.js, Express.js, MongoDB, and EJS templates. It implements MVC and RESTful patterns, allowing users to sign up, create campgrounds, and post reviews. Images are stored on Cloudinary; the app is deployed on Heroku/AWS.

##### File structure
- Top level:
- app.js – entry point / Express server setup
- controllers/ – request handlers (campgrounds, reviews, users)
- routes/ – route definitions, mapping URLs to controllers
- models/ – Mongoose schemas for Campground, Review, User
- views/ – EJS templates (layouts, partials, pages)
- public/ – static assets (CSS, client‑side JS for maps & form validation)
- middleware.js – custom Express middleware (auth checks, error handling)
- utils/ – helper classes (ExpressError, catchAsync)
- cloudinary/ – Cloudinary configuration for image uploads
- seeds/ – seed scripts for populating the database
- schemas.js – JOI schemas for request validation

##### Insights from README
- Auth flow via Passport.js
- Data persistence in MongoDB hosted on AWS (EC2 or Atlas)
- Deployment on Heroku
- RESTful CRUD operations for campgrounds & reviews

##### Diagramming recommendations
- Components: use rectangles:
- Browser (client)
- Web Server (Express) – subdivided into middleware, routers, controllers, models
- MongoDB
- Cloudinary
- Deployment (Heroku Load Balancer)
- Frontend (blue)
- Backend (green)
- Database (orange)
- External Services (gray)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Layer
    Heroku["Load Balancer (Heroku)"]:::external

    %% Client Layer
    Client["Browser (Client)"]:::frontend

    %% Server Layer
    subgraph "Express Web Server"
        direction TB
        ExpressServer["Express Server<br>(app.js)"]:::backend
        Middleware["Middleware<br>(middleware.js)"]:::backend
        Validation["Validation Schemas<br>(schemas.js)"]:::backend
        subgraph "Routes Layer"
            direction TB
            CampRoutes["campgrounds.js"]:::backend
            RevRoutes["reviews.js"]:::backend
            UserRoutes["users.js"]:::backend
        end
        subgraph "Controllers Layer"
            direction TB
            CampCtrl["campgrounds.js"]:::backend
            RevCtrl["reviews.js"]:::backend
            UserCtrl["users.js"]:::backend
        end
        subgraph "Models Layer"
            direction TB
            CampModel["campground.js"]:::backend
            RevModel["review.js"]:::backend
            UserModel["user.js"]:::backend
        end
        subgraph "Utilities"
            direction TB
            ErrorUtil["ExpressError.js"]:::backend
            AsyncUtil["catchAsync.js"]:::backend
        end
        CloudConfig["Cloudinary Config<br>(index.js)"]:::external
    end

    %% Presentation Layer
    subgraph "Views (EJS Templates)"
        direction TB
        Layouts["Layouts<br>(boilerplate.ejs)"]:::frontend
        Partials["Partials<br>(flash, footer, navbar)"]:::frontend
        Pages["Pages<br>(home.ejs, about.ejs, error.ejs)"]:::frontend
        CampViews["Campgrounds Views"]:::frontend
        UserViews["User Views"]:::frontend
    end

    %% Static Assets
    subgraph "Public Assets"
        direction TB
        Styles["Stylesheets"]:::frontend
        Scripts["Client JS"]:::frontend
    end

    %% Seed Scripts
    Seeds["Seed Scripts"]:::backend

    %% Data Layer
    DB["MongoDB (AWS)"]:::database

    %% External Services
    Cloudinary["Cloudinary Service"]:::external

    %% Package Manifest
    Package["package.json"]:::backend

    %% Connections
    Client -->|"HTTP/S"| Heroku -->|routes request| ExpressServer
    ExpressServer --> Middleware --> Validation
    Middleware --> CampRoutes & RevRoutes & UserRoutes
    CampRoutes --> CampCtrl
    RevRoutes --> RevCtrl
    UserRoutes --> UserCtrl
    CampCtrl -->|"DB Query"| CampModel
    RevCtrl -->|"DB Query"| RevModel
    UserCtrl -->|"DB Query"| UserModel
    CampModel & RevModel & UserModel --> DB
    CampCtrl -->|"Upload"<br>Cloudinary SDK| CloudConfig --> Cloudinary
    ExpressServer --> Layouts & Partials & Pages & CampViews & UserViews
    Client --> Pages
    Client --> Styles & Scripts
    Seeds --> DB
    ExpressServer --> Package

    %% Click Events
    click ExpressServer "https://github.com/igoswamik/yelpcamp/blob/main/app.js"
    click Middleware "https://github.com/igoswamik/yelpcamp/blob/main/middleware.js"
    click Validation "https://github.com/igoswamik/yelpcamp/blob/main/schemas.js"
    click CampRoutes "https://github.com/igoswamik/yelpcamp/blob/main/routes/campgrounds.js"
    click RevRoutes "https://github.com/igoswamik/yelpcamp/blob/main/routes/reviews.js"
    click UserRoutes "https://github.com/igoswamik/yelpcamp/blob/main/routes/users.js"
    click CampCtrl "https://github.com/igoswamik/yelpcamp/blob/main/controllers/campgrounds.js"
    click RevCtrl "https://github.com/igoswamik/yelpcamp/blob/main/controllers/reviews.js"
    click UserCtrl "https://github.com/igoswamik/yelpcamp/blob/main/controllers/users.js"
    click CampModel "https://github.com/igoswamik/yelpcamp/blob/main/models/campground.js"
    click RevModel "https://github.com/igoswamik/yelpcamp/blob/main/models/review.js"
    click UserModel "https://github.com/igoswamik/yelpcamp/blob/main/models/user.js"
    click ErrorUtil "https://github.com/igoswamik/yelpcamp/blob/main/utils/ExpressError.js"
    click AsyncUtil "https://github.com/igoswamik/yelpcamp/blob/main/utils/catchAsync.js"
    click CloudConfig "https://github.com/igoswamik/yelpcamp/blob/main/cloudinary/index.js"
    click Layouts "https://github.com/igoswamik/yelpcamp/blob/main/views/layouts/boilerplate.ejs"
    click Partials "https://github.com/igoswamik/yelpcamp/tree/main/views/partials/"
    click Pages "https://github.com/igoswamik/yelpcamp/blob/main/views/home.ejs"
    click Styles "https://github.com/igoswamik/yelpcamp/tree/main/public/stylesheets/"
    click Scripts "https://github.com/igoswamik/yelpcamp/tree/main/public/javascripts/"
    click Seeds "https://github.com/igoswamik/yelpcamp/blob/main/seeds/index.js"
    click Package "https://github.com/igoswamik/yelpcamp/blob/main/package.json"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#004d40;
    classDef backend fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20;
    classDef database fill:#fff3e0,stroke:#ef6c00,color:#e65100;
    classDef external fill:#eceff1,stroke:#607d8b,color:#37474f;
```
