# dhruvmoradiya69/deployment-mern-stack-hotel-booking-application architecture

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

- Interactive diagram: https://gitdiagram.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application
- Repository: https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application

## Overview

##### Project Type and Purpose
- Full-stack web application: React frontend (SPA), Node/Express backend, MongoDB database.
- Deployed locally via Docker Compose or in Kubernetes (Kind) clusters.
- Cloud-related provisioning via Terraform.
- Integrates external services: Cloudinary (image storage), Stripe (payments), JWT authentication.

##### File Structure
- Top-level ‘backend’ folder: Node/Express in TypeScript, structured by models, middleware, and routes (MVC pattern).
- Top-level ‘frontend’ folder: React + TypeScript, structured by pages, components, contexts, forms, layouts, with Nginx for static hosting.
- ‘docker-compose.yml’: multi-container setup for local dev (frontend, backend, MongoDB).
- ‘k8s’ folder: Kubernetes deployment/service YAMLs for all components plus Ingress.
- ‘terraform’ folder: scripts and Terraform configs to provision infrastructure (e.g., cloud VPCs, clusters).

##### README Insights
- Purpose: hotel booking with authentication, hotel management, image uploads, filtering, Stripe payments.
- Deployment options: Docker Compose and Kubernetes (Kind) with clear step-by-step commands.
- Environment variables outline external dependencies (MongoDB URI, JWT secret, Cloudinary, Stripe keys).

##### Main Components and Their Relationships
a. Presentation Layer (Frontend)
- User’s Web Browser
- Nginx (serving static React bundle)
- React SPA (AppContext, SearchContext, components, pages)
b. Application Layer (Backend)
- Node.js + Express server
- Middleware (Authentication)
- Routes/Controllers (auth, hotels, bookings, users, profiles)
- Models (User, Hotel)
c. Data Layer
- MongoDB (persistent storage via a StatefulSet/PVC in K8s or container in Compose)
d. External Services
- Cloudinary (image upload/storage)
- Stripe (payment gateway)
e. Orchestration/Infrastructure
- Docker Compose network
- Kubernetes cluster (Deployments, Services, Ingress)
- Terraform-managed cloud resources (optional)

Interactions:
- Browser → HTTP(S) → Nginx → serves React → API calls to Backend.
- Backend ↔ MongoDB (CRUD).
- Backend ↔ Cloudinary (upload/download images).
- Backend ↔ Stripe (create and confirm payments).
- Terraform provisions Kubernetes cluster, networking, secrets.

##### Architectural Patterns and Principles
- Backend follows MVC: models in `/models`, controllers in `/routes`, cross-cutting concerns in `/middleware`.
- Frontend uses component-based architecture with Context API for global/state management and form modules.
- Separation of concerns: distinct layers for presentation, business logic, and data.
- Infrastructure as Code: Terraform for provisioning; Kubernetes YAML for declarative deployments.

##### Essential Elements
- Components: Browser, Nginx, React, Express API, MongoDB, Cloudinary, Stripe, Docker/K8s, Terraform.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["User's Web Browser"]:::external
        Nginx["Nginx Static Server"]:::frontend
        React["React SPA"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        Express["Express API Server"]:::backend
        Routes["API Routes / Controllers"]:::backend
        Models["Data Models (Mongoose)"]:::backend
        Auth["Authentication Middleware"]:::backend
        Types["Shared Types"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Mongo["MongoDB"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary"]:::external
        Stripe["Stripe"]:::external
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        Compose["Docker Compose"]:::infra
        subgraph "Kubernetes Configs"
            direction TB
            K8sBackendDep["backend-deployment.yml"]:::infra
            K8sBackendSvc["backend-service.yml"]:::infra
            K8sFrontendDep["frontend-deployment.yml"]:::infra
            K8sFrontendSvc["frontend-service.yml"]:::infra
            K8sMongoDep["mongo-deployment.yml"]:::infra
            K8sMongoSvc["mongo-service.yml"]:::infra
            K8sMongoPV["mongo-pv.yml"]:::infra
            K8sMongoPVC["mongo-pvc.yml"]:::infra
            K8sNS["namespace.yml"]:::infra
            K8sSecret["secret.yml"]:::infra
            K8sIngress["ingress.yml"]:::infra
        end
        subgraph "Terraform Configs"
            direction TB
            TFMain["main.tf"]:::infra
            TFVar["variable.tf"]:::infra
            TFOutput["output.tf"]:::infra
            TFTF["terraform.tf"]:::infra
            InstallSh["install.sh"]:::infra
            SonarSh["sonar.sh"]:::infra
        end
    end

    %% Connections
    Browser -->|"HTTP(S)"| Nginx
    Nginx -->|serves bundle| React
    React -->|"REST API Calls"| Express
    Express -->|uses| Routes
    Express -->|uses| Models
    Express -->|uses| Auth
    Express -->|uses| Types
    Express -->|"CRUD"| Mongo
    Express -->|"Upload/Download"| Cloudinary
    Express -->|"Payments"| Stripe
    Compose -->|defines| Mongo
    Compose -->|network| Express
    Compose -->|network| React
    TFMain -->|provisions| K8sBackendDep
    TFMain -->|provisions| K8sFrontendDep
    TFMain -->|provisions| K8sMongoDep
    TFMain -->|provisions| K8sNS
    TFMain -->|provisions| K8sSecret

    %% Click events
    click React "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/tree/main/frontend/src"
    click Nginx "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/frontend/nginx.conf"
    click React "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/tree/main/frontend/Dockerfile"
    click Express "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/backend/src/index.ts"
    click Routes "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/tree/main/backend/src/routes"
    click Models "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/tree/main/backend/src/models"
    click Auth "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/backend/src/middleware/auth.ts"
    click Types "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/backend/src/shared/types.ts"
    click Compose "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/docker-compose.yml"
    click K8sBackendDep "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/backend-deployment.yml"
    click K8sBackendSvc "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/backend-service.yml"
    click K8sFrontendDep "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/frontend-deployment.yml"
    click K8sFrontendSvc "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/frontend-service.yml"
    click K8sMongoDep "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/mongo-deployment.yml"
    click K8sMongoSvc "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/mongo-service.yml"
    click K8sIngress "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/ingress.yml"
    click K8sMongoPV "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/mongo-pv.yml"
    click K8sMongoPVC "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/mongo-pvc.yml"
    click K8sNS "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/namespace.yml"
    click K8sSecret "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/k8s/secret.yml"
    click TFMain "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/terraform/main.tf"
    click TFVar "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/terraform/variable.tf"
    click TFOutput "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/terraform/output.tf"
    click TFTF "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/terraform/terraform.tf"
    click InstallSh "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/terraform/install.sh"
    click SonarSh "https://github.com/dhruvmoradiya69/deployment-mern-stack-hotel-booking-application/blob/main/terraform/sonar.sh"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef database fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#383d41,color:#383d41
    classDef infra fill:#f0f0f0,stroke:#999,color:#666
```
