# vigneshdevhub/campx architecture

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

- Interactive diagram: https://gitdiagram.com/vigneshdevhub/campx
- Repository: https://github.com/vigneshdevhub/campx

## Overview

##### Main Components

a. Client-Side Layer:
- Static Assets (public folder)
- JavaScript modules
- CSS stylesheets
- Views (EJS templates)
- Layouts
- Partials
- User pages
- Campground pages

b. Server-Side Layer:
- Express.js Application (app.js)
- Route Handlers
- Controllers
- Middleware
- Authentication System

c. External Services:
- MongoDB Atlas (Database)
- Cloudinary (Media Storage)
- Mapbox (Maps Integration)

##### Component Relationships

- Client Browser → Express.js Server
- Express.js Server → Route Handlers
- Route Handlers → Controllers
- Controllers → Models
- Models → MongoDB Atlas
- Media Upload Flow → Cloudinary
- Location Services → Mapbox

##### Architectural Pattern Representation

The project follows an MVC (Model-View-Controller) pattern:
- Models: /models directory (campground.js, review.js, user.js)
- Views: /views directory (EJS templates)
- Controllers: /controllers directory (campgrounds.js, reviews.js, users.js)

**[Client Browser]**
- ↕
**[Frontend Layer]**
- Static Assets
- EJS Templates
- ↕
**[Express.js Server]**
- Routes
- Middleware
- Controllers
- ↕
**[Business Logic Layer]**
- Models
- Utils
- Schemas
- ↕
**[External Services]**
- MongoDB Atlas
- Cloudinary
- Mapbox

##### Important Flows to Highlight

a. Authentication Flow:
- User Registration/Login → Users Controller → User Model → MongoDB

b. Campground Operations:
- CRUD Operations → Campgrounds Controller → Campground Model → MongoDB
- Image Upload → Cloudinary Integration
- Location Data → Mapbox Integration

c. Review System:
- Review Creation → Reviews Controller → Review Model → MongoDB

##### Additional Elements

Supporting components:
- Error Handling (utils/ExpressError.js)
- Async Operations (utils/catchAsync.js)
- Data Validation (schemas.js)
- Security Middleware (middleware.js)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Browser["Web Browser"]
        StaticAssets["Static Assets"]:::static
        Views["Views/Templates"]:::views
        JavaScript["JavaScript Modules"]:::js
        CSS["CSS Stylesheets"]:::css
    end

    subgraph Server["Server Layer"]
        Express["Express.js Server"]:::express
        Routes["Route Handlers"]:::routes
        Controllers["Controllers"]:::controllers
        MW["Middleware"]:::middleware
    end

    subgraph Logic["Business Logic Layer"]
        Models["Data Models"]:::models
        Validation["Data Validation"]:::validation
        ErrorHandling["Error Handling"]:::utils
        AsyncOps["Async Operations"]:::utils
    end

    subgraph External["External Services"]
        MongoDB[(MongoDB Atlas)]
        Cloudinary["Cloudinary Storage"]:::cloud
        Mapbox["Mapbox Services"]:::map
    end

    %% Relationships
    Browser --> StaticAssets
    Browser --> Views
    Browser --> JavaScript
    Browser --> CSS
    
    StaticAssets --> Express
    Views --> Express
    
    Express --> Routes
    Routes --> Controllers
    Controllers --> Models
    
    Models --> MongoDB
    Controllers --> Cloudinary
    Controllers --> Mapbox
    
    MW --> Routes
    Validation --> Controllers
    ErrorHandling --> Controllers
    AsyncOps --> Controllers

    %% Click Events
    click Express "https://github.com/VigneshDevHub/CampX/blob/main/app.js"
    click StaticAssets "https://github.com/VigneshDevHub/CampX/tree/main/public"
    click JavaScript "https://github.com/VigneshDevHub/CampX/tree/main/public/javascripts"
    click CSS "https://github.com/VigneshDevHub/CampX/tree/main/public/stylesheets"
    click Views "https://github.com/VigneshDevHub/CampX/tree/main/views"
    click Routes "https://github.com/VigneshDevHub/CampX/tree/main/routes"
    click Controllers "https://github.com/VigneshDevHub/CampX/tree/main/controllers"
    click MW "https://github.com/VigneshDevHub/CampX/blob/main/middleware.js"
    click Models "https://github.com/VigneshDevHub/CampX/tree/main/models"
    click Validation "https://github.com/VigneshDevHub/CampX/blob/main/schemas.js"
    click ErrorHandling "https://github.com/VigneshDevHub/CampX/blob/main/utils/ExpressError.js"
    click AsyncOps "https://github.com/VigneshDevHub/CampX/blob/main/utils/catchAsync.js"
    click Cloudinary "https://github.com/VigneshDevHub/CampX/blob/main/cloudinary/index.js"
    click Mapbox "https://github.com/VigneshDevHub/CampX/blob/main/public/javascripts/showPageMap.js"

    %% Styling
    classDef static fill:#a8d5e5
    classDef views fill:#95b8d1
    classDef js fill:#b8e0d2
    classDef css fill:#d6eadf
    classDef express fill:#2d6a4f
    classDef routes fill:#40916c
    classDef controllers fill:#52b788
    classDef middleware fill:#74c69d
    classDef models fill:#95d5b2
    classDef validation fill:#b7e4c7
    classDef utils fill:#d8f3dc
    classDef cloud fill:#ffb703
    classDef map fill:#fb8500

    %% Legend
    subgraph Legend
        L1["Client Components"]:::static
        L2["Server Components"]:::express
        L3["Business Logic"]:::models
        L4["External Services"]:::cloud
    end
```
