# mohanishkhatri/rails-app-dockerization architecture

> Architecture diagram of the GitHub repository mohanishkhatri/rails-app-dockerization, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohanishkhatri/rails-app-dockerization
- Repository: https://github.com/mohanishkhatri/rails-app-dockerization

## Overview

##### Project Type and Purpose
- This is a full-stack Ruby on Rails web application that has been containerized with Docker.
- It uses MySQL as its persistent datastore, Nginx as a reverse proxy and load balancer, BIND9 for internal DNS resolution, NFS for shared storage, and GitHub Actions for CI/CD and automated backups.

##### Top-Level Architecture Overview
- VM1 (Ubuntu Server) runs Docker and hosts all application-related containers.
- Rails application containers (three replicas)
- MySQL database container
- Nginx reverse proxy/load-balancer container
- BIND9 DNS container
- VM2 (Ubuntu Server) acts as an NFS server providing:
- Persistent volume for MySQL data
- Shared file storage for uploaded images
- Backup storage

##### Main Components and Their Interactions
A. Client Tier
- Web browser or API client
- Connects to “myrailsapp.com” over HTTP/HTTPS
B. DNS Layer
- BIND9 container on VM1 resolves “myrailsapp.com” → internal IP of Nginx
C. Load-Balancing & Reverse-Proxy Layer
- Nginx container listens on port 80/443
- Performs SSL termination (self-signed certs)
- Applies rate limiting (limit_req_zone)
- Uses ip_hash for sticky sessions
- Proxies requests to Rails app containers
D. Application Tier
- Three Rails containers (myapp-web-1…3) on a custom Docker network
- Each runs Puma web server, Serves ERB views, Stimulus controllers, ActionCable channels
- Connects to MySQL over network
- Reads/writes uploads to mounted NFS directory
E. Data Tier
- MySQL container with volume “mysql_data” mounted at /var/lib/mysql
- Uses NFS share on VM2 (no_root_squash) for persistence
F. Shared Storage
- NFS server on VM2 exports:
– /storage/mysql_data → MySQL data
– /storage/app_images → Rails uploads (mounted at /app/storage)
G. CI/CD & Backup
- GitHub Actions workflow builds Docker image and pushes to Docker Hub
- VM1 pulls latest image on deploy
- Cron-based backup script runs daily, backs up code and DB dumps to NFS backup-storage

##### Architectural Patterns and Design Principles
- MVC pattern in Rails (app/models, app/views, app/controllers)
- Micro-services via Docker containers (single-purpose containers)
- Layered architecture (DNS → Proxy → App → DB)
- Infrastructure as code: Dockerfiles, docker-compose.yml, Nginx configs, bind9 exports, UFW rules, fstab
- Persistence decoupled from containers via volumes and NFS
- Fault isolation: multiple Rails app replicas behind load balancer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients" 
        Browser["Web Browser / API Client"]:::external
    end

    %% VM1 Docker Host
    subgraph "VM1: Docker Host" 
        subgraph "DNS Layer"
            BIND9["BIND9 DNS (UDP/TCP 53)"]:::container
        end
        subgraph "Load Balancer / Reverse Proxy"
            Nginx["Nginx HTTP/HTTPS (80/443)"]:::container
        end
        subgraph "Application Tier"
            Rails1["myapp-web-1 Puma (3000)"]:::container
            Rails2["myapp-web-2 Puma (3000)"]:::container
            Rails3["myapp-web-3 Puma (3000)"]:::container
        end
        subgraph "Data Tier"
            MySQL[(MySQL 3306)]:::storage
        end
        BackupScript["backup.sh Cron Backup"]:::container
    end

    %% VM2 NFS Server
    subgraph "VM2: NFS Server"
        NFSMySQL[(/storage/mysql_data)]:::storage
        NFSUploads[(/storage/app_images)]:::storage
        NFSBackup[(Backup Storage)]:::storage
    end

    %% CI/CD & Registry
    subgraph "CI/CD & Registry"
        GitHubActions[/"GitHub Actions"/]:::external
        DockerHub[/"Docker Hub"/]:::external
    end

    %% Connections
    Browser -->|"DNS Query"| BIND9
    Browser -->|"HTTP/HTTPS"| Nginx
    BIND9 --> Nginx
    Nginx -->|"HTTP/HTTPS"| Rails1
    Nginx -->|"HTTP/HTTPS"| Rails2
    Nginx -->|"HTTP/HTTPS"| Rails3
    Rails1 -->|"DB Queries (TCP 3306)"| MySQL
    Rails2 -->|"DB Queries (TCP 3306)"| MySQL
    Rails3 -->|"DB Queries (TCP 3306)"| MySQL
    Rails1 -->|"Read/Write NFS"| NFSUploads
    Rails2 -->|"Read/Write NFS"| NFSUploads
    Rails3 -->|"Read/Write NFS"| NFSUploads
    MySQL -->|"NFS Persistence"| NFSMySQL
    BackupScript -->|"Store Backups"| NFSBackup
    GitHubActions -->|"Build Image"| DockerHub
    DockerHub -->|"Pull Images"| Nginx
    DockerHub -->|"Pull Images"| Rails1
    DockerHub -->|"Pull Images"| MySQL

    %% Click Events
    click Rails1 "https://github.com/mohanishkhatri/rails-app-dockerization/tree/main/app/"
    click Rails2 "https://github.com/mohanishkhatri/rails-app-dockerization/tree/main/app/"
    click Rails3 "https://github.com/mohanishkhatri/rails-app-dockerization/tree/main/app/"
    click MySQL "https://github.com/mohanishkhatri/rails-app-dockerization/blob/main/docker-compose.yml"
    click Nginx "https://github.com/mohanishkhatri/rails-app-dockerization/blob/main/nginx/nginx.conf"
    click BIND9 "https://github.com/mohanishkhatri/rails-app-dockerization/blob/main/bind9-setup/named.conf"
    click GitHubActions "https://github.com/mohanishkhatri/rails-app-dockerization/blob/main/.github/workflows/docker-image.yml"
    click BackupScript "https://github.com/mohanishkhatri/rails-app-dockerization/blob/main/backup.sh"

    %% Styles
    classDef container fill:#a2d2ff,stroke:#023e8a,stroke-width:1px
    classDef storage fill:#caffbf,stroke:#2b9348,stroke-width:1px
    classDef external fill:#ffafcc,stroke:#9d0208,stroke-width:1px
```
