# billymohajeri/final-group-capstone-backend architecture

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

- Interactive diagram: https://gitdiagram.com/billymohajeri/final-group-capstone-backend
- Repository: https://github.com/billymohajeri/final-group-capstone-backend

## Overview

##### Project Type and Purpose
- This is a full-stack booking application split into two repos:
– Backend: Ruby on Rails API (monolithic MVC with ActionCable, ActiveJob, ActionMailer)
– Frontend: React + Redux single-page app

##### File Structure (Backend)
- app/controllers/api/*: JSON-only endpoints for users, rooms, reservations, sessions
- app/models: ActiveRecord models (User, Room, Reservation)
- app/channels: WebSocket channels via ActionCable for real-time updates
- app/jobs & app/mailers: Background jobs (ActiveJob) and email delivery (ActionMailer)
- config/storage.yml: ActiveStorage configuration (local or cloud file store)
- config/cable.yml: ActionCable setup
- config/routes.rb: API namespace and routing
- Rakefile, bin/puma.sh, config/puma.rb: Puma web server entrypoint
- swagger/v1/swagger.yaml + rswag_* initializers: API documentation

##### Key Components
a. Client (React + Redux SPA)
b. API Server (Rails monolith)
– HTTP layer: Puma web server
– Controllers (API namespace)
– Models (ActiveRecord → PostgreSQL)
– ActionCable (WebSocket server)
– ActiveJob queue (async tasks)
– ActionMailer (email service)
– ActiveStorage (file uploads)
c. Database (PostgreSQL)
d. External Services
– SMTP/Email provider
– (Optional) Cloud storage if ActiveStorage uses S3
– Reverse proxy or load balancer (e.g., Nginx)
– Swagger UI served under /api-docs

##### Relationships & Data Flows
- SPA ↔ HTTP(s) ↔ Rails Controllers → JSON
- Controllers ↔ Models → SQL ↔ PostgreSQL
- Controllers → ActionCable → WebSocket → SPA (real-time updates)
- Controllers/Jobs → ActiveJob → (local/Redis) queue → perform background tasks
- Jobs → ActionMailer → SMTP provider → User email
- Controllers → ActiveStorage → file system or S3
- Rails ↔ Swagger UI for interactive docs

##### Architectural Patterns & Design Principles
- Monolithic MVC API-only backend
- RESTful JSON endpoints under /api namespace
- CQRS-like separation: Controllers handle requests; models encapsulate persistence
- Event-driven components: ActionCable channels for real-time
- Background processing via ActiveJob adapter
- Externalized configuration (credentials.yml.enc, storage.yml)

##### Essential Elements
- Annotations for frameworks/tech: React, Redux, Ruby on Rails, Puma, PostgreSQL, ActionCable, ActiveJob, ActionMailer, ActiveStorage

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["React + Redux SPA"]:::frontend
    ReverseProxy["Nginx/Load Balancer"]:::external
    Client -- "HTTP/HTTPS" --> ReverseProxy
    ReverseProxy -- "Forward Requests" --> Puma

    subgraph "Rails API Server"
        direction TB
        Puma["Puma Web Server"]:::backend

        subgraph "Routing"
            direction TB
            Routes["config/routes.rb"]:::backend
        end

        subgraph "Controllers"
            direction TB
            AppController["ApplicationController"]:::backend
            UsersController["UsersController"]:::backend
            RoomsController["RoomsController"]:::backend
            ReservationsController["ReservationsController"]:::backend
            SessionsController["SessionsController"]:::backend
        end

        subgraph "Models"
            direction TB
            UserModel["User (app/models/user.rb)"]:::backend
            RoomModel["Room (app/models/room.rb)"]:::backend
            ReservationModel["Reservation (app/models/reservation.rb)"]:::backend
            Migrations["db/migrate/"]:::backend
            Schema["db/schema.rb"]:::backend
        end

        subgraph "ActionCable"
            direction TB
            ACChannel["application_cable/channel.rb"]:::backend
            ACConnection["application_cable/connection.rb"]:::backend
            CableConfig["config/cable.yml"]:::backend
        end

        subgraph "ActiveJob"
            direction TB
            Jobs["app/jobs/application_job.rb"]:::backend
        end

        subgraph "ActionMailer"
            direction TB
            Mailer["app/mailers/application_mailer.rb"]:::backend
            MailerHTML["mailer.html.erb"]:::backend
            MailerText["mailer.text.erb"]:::backend
        end

        subgraph "ActiveStorage"
            direction TB
            StorageConfig["config/storage.yml"]:::backend
            StorageDir["storage/"]:::backend
        end

        subgraph "Swagger UI"
            direction TB
            SwaggerSpec["swagger/v1/swagger.yaml"]:::backend
            RswagAPI["config/initializers/rswag_api.rb"]:::backend
            RswagUI["config/initializers/rswag_ui.rb"]:::backend
        end

        Puma --> Routes
        Routes --> AppController
        AppController --> UsersController
        AppController --> RoomsController
        AppController --> ReservationsController
        AppController --> SessionsController

        UsersController --> UserModel
        RoomsController --> RoomModel
        ReservationsController --> ReservationModel
        SessionsController --> UserModel

        ReservationsController --> Jobs
        Jobs --> Mailer
        Mailer --> MailerHTML
        Mailer --> MailerText

        AppController --> ACChannel
        ACChannel --> ACConnection

        AppController --> StorageConfig
        StorageConfig --> StorageDir

        AppController --> SwaggerSpec
        SwaggerSpec --> RswagAPI
        SwaggerSpec --> RswagUI
    end

    UserModel --> PostgreSQL
    RoomModel --> PostgreSQL
    ReservationModel --> PostgreSQL
    Migrations --> PostgreSQL
    Schema --> PostgreSQL

    PostgreSQL["PostgreSQL"]:::db

    ACConnection -->|WebSocket| Client
    Mailer --> SMTP
    StorageDir --> CloudStorage

    SMTP["SMTP/Email Provider"]:::external
    CloudStorage["S3/Local Storage"]:::external

    classDef frontend fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef backend fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef external fill:#FFFF99,stroke:#333,stroke-width:1px;

    click Puma "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/config/puma.rb"
    click Routes "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/config/routes.rb"
    click AppController "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/controllers/application_controller.rb"
    click UsersController "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/controllers/users_controller.rb"
    click RoomsController "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/controllers/rooms_controller.rb"
    click ReservationsController "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/controllers/reservations_controller.rb"
    click SessionsController "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/controllers/sessions_controller.rb"
    click UserModel "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/models/user.rb"
    click RoomModel "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/models/room.rb"
    click ReservationModel "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/models/reservation.rb"
    click Migrations "https://github.com/billymohajeri/final-group-capstone-backend/tree/main/db/migrate/"
    click Schema "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/db/schema.rb"
    click ACChannel "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/channels/application_cable/channel.rb"
    click ACConnection "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/channels/application_cable/connection.rb"
    click CableConfig "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/config/cable.yml"
    click Jobs "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/jobs/application_job.rb"
    click Mailer "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/mailers/application_mailer.rb"
    click MailerHTML "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/views/layouts/mailer.html.erb"
    click MailerText "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/app/views/layouts/mailer.text.erb"
    click StorageConfig "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/config/storage.yml"
    click StorageDir "https://github.com/billymohajeri/final-group-capstone-backend/tree/main/storage/"
    click SwaggerSpec "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/swagger/v1/swagger.yaml"
    click RswagAPI "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/config/initializers/rswag_api.rb"
    click RswagUI "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/config/initializers/rswag_ui.rb"
    click PostgreSQL "https://github.com/billymohajeri/final-group-capstone-backend/blob/main/config/database.yml"
```
