# sfarrukh/rails-crud architecture

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

- Interactive diagram: https://gitdiagram.com/sfarrukh/rails-crud
- Repository: https://github.com/sfarrukh/rails-crud

## Overview

##### Project Type and Purpose
- This is a full-stack Ruby on Rails monolithic web application implementing an online rental store.
- Frontend: ERB views + CoffeeScript/JavaScript + CSS under app/assets.
- Backend: MVC Rails app (app/controllers, app/models).
- Persistence: MySQL (Sakila + custom tables).
- Real-time: ActionCable channels.
- Asynchronous jobs/mail: ActiveJob and ActionMailer.

##### File Structure
- Top-level rails conventions: app/, config/, db/, lib/, public/, test/, vendor/.
- app/ is subdivided into:
- assets: JS/Coffee, CSS, images.
- controllers: namespaced by ‘admin’, ‘staff’, ‘api’, ‘account’, plus public controllers.
- models: domain entities (Actor, Film, Customer, Rental, etc.).
- views: ERB templates aligned with controllers.
- channels: ActionCable WebSocket endpoints.
- jobs & mailers: background-job and email functionality.
- config/: routing (config/routes.rb), database config, environment setups, initializers.
- db/: migrations, schema, seeds.
- Public/API endpoints:
- Web UI for Public, Staff, Admin.
- JSON API under app/controllers/api.
- Tests mirror controllers/models via test/.

##### README for Architecture Insights
- Three user-roles/environments with separate login flows: public, staff, admin.
- Uses Sakila schema plus four custom tables (Admin, Staff, CustomerPaymentInfo, RentalPending).
- Domain relationships via ActiveRecord associations.

a. Main Components
- Users (three types): Public user, Staff user, Admin user.
- Client (Browser/SPA): Requests HTML pages, static assets, JSON API.
- Web Server Layer: NGINX (optional), Puma (Rails app server).
- Rails Monolith:
- Router (config/routes).
- Controller Layer (app/controllers + namespaces: public, admin, staff, api).
- View/Asset Pipeline (ERB, JS, CSS).
- Model Layer (ActiveRecord models).
- ActionCable Server (WebSocket channels).
- Background Job Processor (ActiveJob, e.g., Sidekiq or default inline).
- Mailer (ActionMailer).
- Database: MySQL with Sakila + custom tables.
- External Services: SMTP server for emails.

b. Relationships and Interactions
- Users → HTTP/WebSocket → Rails Router.
- Router → appropriate Controller namespace (public, staff, admin, api).
- Controllers ↔ Models (ActiveRecord ORM).
- Models → MySQL (CRUD operations, foreign-key relationships).
- Controllers → Views/JSON responses.
- Asset Pipeline serves JS/CSS.
- Controllers/jobs → ActionMailer → SMTP.
- Controllers/jobs → ActiveJob → job queue.
- Clients can open WebSocket connections to ActionCable channels.
- Admin/Staff UIs talk to JSON API via AJAX scripts in app/assets/javascripts.
- All traffic goes through Web Server → Puma app server → Rails app.

c. Architectural Patterns & Design Principles
- MVC (Model–View–Controller).
- Namespace-based routing (public, admin, staff, api).
- RESTful controllers plus JSON API endpoints.
- Asset Pipeline for static assets.
- ActiveRecord associations for relational mapping.
- ActionCable for real-time features.
- Background jobs for long-running tasks (mail, data processing).
- Three-tier separation: Presentation (views/assets), Application (controllers/models/jobs), Data (MySQL).

d. Key Technologies/Frameworks/Libraries
- Ruby on Rails (MVC, ActiveRecord, ActionCable, ActiveJob, ActionMailer).
- MySQL (Sakila schema + custom tables).
- Puma application server.
- Web server (NGINX or Apache).
- CoffeeScript/JavaScript for client-side logic.
- CSS/bootstrap for styling.
- Sidekiq (optional) or default ActiveJob adapter.
- SMTP/SendGrid (or other) for email.

##### Elements
- Clear labels for each component (e.g., “Puma Server”, “app/controllers/admin”, “MySQL (sakila + custom tables)”).
- Namespaces: public, api, admin, staff controllers.
- Major tables/entities if desired: Customer, Film, Rental, RentalPending, Admin, Staff.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients" 
        direction TB
        PB["Public Browser"]:::client
        SB["Staff Browser"]:::client
        AB["Admin Browser"]:::client
    end

    %% Web Server & App Server
    subgraph "Web Server Layer" 
        direction TB
        NG["NGINX"]:::server
        PM["Puma Server"]:::server
    end

    %% Rails Application
    subgraph "Rails Monolith" 
        direction TB
        RT["Router"]:::router
        subgraph "Controllers" 
            direction TB
            subgraph "Public Namespace"
                direction TB
                PC["PublicController"]:::controller
                RPC["RentalPendingsController"]:::controller
                CC["CheckoutController"]:::controller
                CartC["CartController"]:::controller
            end
            subgraph "Admin Namespace"
                direction TB
                AC["Admin::AccessController"]:::controller
                AActors["Admin::ActorsController"]:::controller
                AAddresses["Admin::AddressesController"]:::controller
                ACustomers["Admin::CustomersController"]:::controller
                AFilms["Admin::FilmsController"]:::controller
            end
            subgraph "Staff Namespace"
                direction TB
                SAccess["Staff::AccessController"]:::controller
                SActors["Staff::ActorsController"]:::controller
                SCustomers["Staff::CustomersController"]:::controller
                SFilms["Staff::FilmsController"]:::controller
                SOrders["Staff::OrdersController"]:::controller
            end
            subgraph "API Namespace"
                direction TB
                APActors["API::ActorsController"]:::controller
                APAddresses["API::AddressesController"]:::controller
                APCustomers["API::CustomersController"]:::controller
                APFilms["API::FilmsController"]:::controller
                APSearch["API::SearchController"]:::controller
            end
        end
        subgraph "Views & Asset Pipeline"
            direction TB
            VIEWS["ERB Views"]:::view
            JS["JavaScript/Coffee Scripts"]:::asset
            CSS["Stylesheets"]:::asset
        end
        subgraph "Models"
            direction TB
            Actor["Actor"]:::model
            Customer["Customer"]:::model
            Film["Film"]:::model
            Rental["Rental"]:::model
            RP["RentalPending"]:::model
            AdminM["Admin"]:::model
            StaffM["Staff"]:::model
        end
        subgraph "ActionCable Channels"
            direction TB
            ACxn["Connection"]:::channel
            AChan["Channel"]:::channel
        end
        subgraph "Background Jobs"
            direction TB
            Job["ApplicationJob"]:::job
        end
        subgraph "Mailers"
            direction TB
            Mail["ApplicationMailer"]:::mailer
        end
    end

    %% Database & External
    DB["MySQL (sakila + custom)"]:::database
    SMTP["SMTP Server"]:::external

    %% Connections
    PB -->|HTTP/HTTPS| NG --> PM --> RT
    SB -->|HTTP/HTTPS| NG
    AB -->|HTTP/HTTPS| NG
    RT -->|"routes to"| PC & RPC & CC & CartC & AC & AActors & AAddresses & ACustomers & AFilms & SAccess & SActors & SCustomers & SFilms & SOrders & APActors & APAddresses & APCustomers & APFilms & APSearch
    PC & RPC & CC & CartC & AC & AActors & AAddresses & ACustomers & AFilms & SAccess & SActors & SCustomers & SFilms & SOrders & APActors & APAddresses & APCustomers & APFilms & APSearch -->|"calls"| ModelInvoker[Models]
    ModelInvoker --> DB
    PC & RPC & CC & CartC --> VIEWS
    APActors & APAddresses & APCustomers & APFilms & APSearch -->|"JSON"| JS
    JS --> PB & SB & AB
    PC & RPC & CC & CartC --> JS & CSS
    PM --> ACxn
    PB & SB & AB -->|WebSocket subscribe| ACxn --> AChan
    PC & RPC & CC & CartC --> Job
    Job --> ModelInvoker
    PC & RPC & CC & CartC & Job --> Mail --> SMTP

    %% Click Events
    click RT "https://github.com/sfarrukh/rails-crud/blob/master/config/routes.rb"
    click PC "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/public_controller.rb"
    click RPC "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/rental_pendings_controller.rb"
    click CC "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/checkout_controller.rb"
    click CartC "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/cart_controller.rb"
    click AC "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/admin/access_controller.rb"
    click AActors "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/admin/actors_controller.rb"
    click AAddresses "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/admin/addresses_controller.rb"
    click ACustomers "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/admin/customers_controller.rb"
    click AFilms "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/admin/films_controller.rb"
    click SAccess "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/staff/access_controller.rb"
    click SActors "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/staff/actors_controller.rb"
    click SCustomers "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/staff/customers_controller.rb"
    click SFilms "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/staff/films_controller.rb"
    click SOrders "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/staff/orders_controller.rb"
    click APActors "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/api/actors_controller.rb"
    click APAddresses "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/api/addresses_controller.rb"
    click APCustomers "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/api/customers_controller.rb"
    click APFilms "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/api/films_controller.rb"
    click APSearch "https://github.com/sfarrukh/rails-crud/blob/master/app/controllers/api/search_controller.rb"
    click Actor "https://github.com/sfarrukh/rails-crud/blob/master/app/models/actor.rb"
    click Customer "https://github.com/sfarrukh/rails-crud/blob/master/app/models/customer.rb"
    click Film "https://github.com/sfarrukh/rails-crud/blob/master/app/models/film.rb"
    click Rental "https://github.com/sfarrukh/rails-crud/blob/master/app/models/rental.rb"
    click RP "https://github.com/sfarrukh/rails-crud/blob/master/app/models/rental_pending.rb"
    click AdminM "https://github.com/sfarrukh/rails-crud/blob/master/app/models/admin.rb"
    click StaffM "https://github.com/sfarrukh/rails-crud/blob/master/app/models/staff.rb"
    click Job "https://github.com/sfarrukh/rails-crud/blob/master/app/jobs/application_job.rb"
    click Mail "https://github.com/sfarrukh/rails-crud/blob/master/app/mailers/application_mailer.rb"
    click ACxn "https://github.com/sfarrukh/rails-crud/blob/master/app/channels/application_cable/connection.rb"
    click AChan "https://github.com/sfarrukh/rails-crud/blob/master/app/channels/application_cable/channel.rb"

    %% Styles
    classDef client fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef server fill:#FCF3CF,stroke:#7D6608,stroke-width:1px
    classDef router fill:#FADBD8,stroke:#922B21,stroke-width:1px
    classDef controller fill:#E8DAEF,stroke:#6C3483,stroke-width:1px
    classDef view fill:#D1F2EB,stroke:#0E6251,stroke-width:1px
    classDef asset fill:#FDEDEC,stroke:#C0392B,stroke-width:1px
    classDef model fill:#FEF9E7,stroke:#B7950B,stroke-width:1px
    classDef channel fill:#EAF2F8,stroke:#1A5276,stroke-width:1px
    classDef job fill:#F9EBEA,stroke:#922B21,stroke-width:1px
    classDef mailer fill:#EBF5FB,stroke:#1F618D,stroke-width:1px
    classDef database fill:#F4ECF7,stroke:#7D3C98,stroke-width:1px
    classDef external fill:#E8F8F5,stroke:#117A65,stroke-width:1px
```
