# sergiy17/classes_scheduler architecture

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

- Interactive diagram: https://gitdiagram.com/sergiy17/classes_scheduler
- Repository: https://github.com/sergiy17/classes_scheduler

## Overview

##### Main Components
a. Client Layer
- Browser / PWA (HTML/ERB views, Stimulus controllers via Importmap)
- PDF viewer (or PDF download endpoint)
b. Web/Application Layer
- HTTP server: Puma → Rack → Rails router (config/routes.rb)
- Controllers (app/controllers/*)
- Views & Assets (app/views, app/assets, app/javascript)
- Service objects (app/services/schedule_pdf_service.rb)
- Serializers (app/serializers/*.rb)
c. Business/Data Layer
- Models / ActiveRecord (app/models/*.rb)
- Database: PostgreSQL (config/database.yml)
- Associations: Student ↔ Section (via student_section), Teacher, Classroom, Subject
d. Background Processing
- ActiveJob (app/jobs) → queue adapter (config/queue.yml)
- Recurring jobs (config/recurring.yml)
e. Real-Time / WebSockets
- ActionCable (config/cable.yml)
f. Storage & Caching
- File storage for PDF, ActiveStorage if enabled (config/storage.yml)
- Cache store (config/cache.yml)
g. Mailers
- ActionMailer (app/mailers) for notifications
h. External/DevOps
- Redis (if used for cache or as queue backend)
- SMTP provider
- Docker container (Dockerfile + .kamal deployment hooks)
- CI/CD (GitHub Actions: .github/workflows/ci.yml)

##### Relationships & Data-Flows
- Within Rails, show the request entering the Router and going to the StudentsController (for /students/:id or /students/:id/schedule_pdf).
- Controller calls:
- ActiveRecord models to read/write DB → PostgreSQL
- schedule_pdf_service to assemble schedule PDF → file storage → response to client
- Optionally queues jobs via ActiveJob → Queue backend → Workers → Models/Services
- For PWA features, show service-worker fetching assets from the same Rails app.
- For WebSockets, show client ↔ ActionCable server ↔ Rails channels.
- For mailers, show ApplicationMailer sending via SMTP.

##### Architectural Patterns & Principles
- MVC pattern: clear separation of Controllers, Views, Models
- Service-object pattern for complex business logic (PDF generation)
- Importmap + Stimulus for progressive enhancement on the front end
- ActiveJob for asynchronous processing and scheduled tasks
- Single monolithic codebase, but logically modularized via directories (controllers, models, services, serializers)
- Use of Rails initializers (config/initializers) for cross-cutting concerns (CSP, inflections, asset compilation)

##### Final Checklist of Elements
- Clear component grouping: Client, Web, MVC, Services, Data, Jobs, External
- Labels for all major frameworks & technologies (Ruby 3.x, Rails 7, Stimulus/Importmap, Puma, PostgreSQL, Redis, Docker)
- A small note on deployment: Docker container managed by Kamal, CI via GitHub Actions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Manifest["manifest.json.erb"]:::internal
        ServiceWorker["service-worker.js"]:::internal
        Stimulus["Stimulus Controllers"]:::internal
        Stylesheet["application.css"]:::internal
        Browser["Browser (PWA)"]:::external
        PDFViewer["PDF Viewer"]:::external
    end

    %% Web Layer
    subgraph "Web Layer"
        Puma["Puma"]:::internal
        Rack["Rack"]:::internal
        ConfigRU["config.ru"]:::internal
        Router["Rails Router"]:::internal
    end

    %% MVC Layer
    subgraph "MVC Layer"
        ApplicationController["ApplicationController"]:::internal
        StudentsController["StudentsController"]:::internal
        ViewsLayoutsApp["application.html.erb"]:::internal
        ViewsLayoutsMailerHTML["mailer.html.erb"]:::internal
        ViewsLayoutsMailerText["mailer.text.erb"]:::internal
        OtherViews["Other View Templates"]:::internal
        ModelsGroup["ActiveRecord Models"]:::internal
    end

    %% Service Layer
    subgraph "Service Layer"
        PDFService["SchedulePdfService"]:::internal
        Serializers["Serializers"]:::internal
    end

    %% Data & Infrastructure
    subgraph "Data & Infrastructure"
        Postgres["PostgreSQL"]:::external
        Redis["Redis"]:::external
        Storage["File Storage/ActiveStorage"]:::external
        Cache["Cache Store"]:::external
        SMTP["SMTP Provider"]:::external
    end

    %% Background Jobs
    subgraph "Background Processing"
        ActiveJob["ActiveJob"]:::jobs
        QueueAdapter["Queue Adapter"]:::jobs
        RecurringJobs["Recurring Jobs"]:::jobs
        Workers["Workers"]:::jobs
    end

    %% Real-Time
    subgraph "Real-Time/WebSockets"
        ActionCable["ActionCable"]:::internal
    end

    %% DevOps & Deployment
    subgraph "DevOps & Deployment"
        Docker["Docker Container"]:::external
        KamalHooks[".kamal Hooks"]:::external
        CICD["GitHub Actions CI"]:::external
    end

    %% Connections
    Browser -->|HTTP Request| Puma
    Puma --> Rack
    Rack --> ConfigRU
    ConfigRU --> Router
    Router -->|Route to| StudentsController
    Router -->|Route to| ApplicationController
    StudentsController -->|renders| ViewsLayoutsApp
    StudentsController -->|renders| OtherViews
    StudentsController -->|calls| PDFService
    StudentsController -->|uses| ModelsGroup
    ApplicationController -->|uses| ModelsGroup
    ViewsLayoutsApp --> Stylesheet
    ViewsLayoutsApp --> Stimulus
    ViewsLayoutsApp --> Manifest
    ServiceWorker --> Browser
    Browser -->|fetch SW/assets| ServiceWorker
    Browser -->|view PDF| PDFViewer
    PDFService -->|generate| Storage
    Storage -->|serve PDF| Browser
    ModelsGroup -->|read/write| Postgres
    StudentsController -->|enqueue| ActiveJob
    ActiveJob --> QueueAdapter
    QueueAdapter --> Workers
    RecurringJobs --> ActiveJob
    Workers --> PDFService
    Browser <-->|WebSocket| ActionCable
    StudentsController -->|send mail| SMTP
    ModelsGroup --> Cache
    ModelsGroup --> Redis
    Docker --> Router
    Docker --> Postgres
    CICD --> Docker
    CICD --> KamalHooks

    %% Click Events
    click Manifest "https://github.com/sergiy17/classes_scheduler/blob/main/app/views/pwa/manifest.json.erb"
    click ServiceWorker "https://github.com/sergiy17/classes_scheduler/blob/main/app/views/pwa/service-worker.js"
    click Stimulus "https://github.com/sergiy17/classes_scheduler/tree/main/app/javascript/controllers"
    click Stylesheet "https://github.com/sergiy17/classes_scheduler/blob/main/app/assets/stylesheets/application.css"
    click ConfigRU "https://github.com/sergiy17/classes_scheduler/blob/main/config.ru"
    click Router "https://github.com/sergiy17/classes_scheduler/blob/main/config/routes.rb"
    click ApplicationController "https://github.com/sergiy17/classes_scheduler/blob/main/app/controllers/application_controller.rb"
    click StudentsController "https://github.com/sergiy17/classes_scheduler/blob/main/app/controllers/students_controller.rb"
    click ViewsLayoutsApp "https://github.com/sergiy17/classes_scheduler/blob/main/app/views/layouts/application.html.erb"
    click ViewsLayoutsMailerHTML "https://github.com/sergiy17/classes_scheduler/blob/main/app/views/layouts/mailer.html.erb"
    click ViewsLayoutsMailerText "https://github.com/sergiy17/classes_scheduler/blob/main/app/views/layouts/mailer.text.erb"
    click OtherViews "https://github.com/sergiy17/classes_scheduler/tree/main/app/views"
    click PDFService "https://github.com/sergiy17/classes_scheduler/blob/main/app/services/schedule_pdf_service.rb"
    click Serializers "https://github.com/sergiy17/classes_scheduler/tree/main/app/serializers"
    click ModelsGroup "https://github.com/sergiy17/classes_scheduler/tree/main/app/models"
    click Postgres "https://github.com/sergiy17/classes_scheduler/blob/main/config/database.yml"
    click ActiveJob "https://github.com/sergiy17/classes_scheduler/blob/main/app/jobs/application_job.rb"
    click QueueAdapter "https://github.com/sergiy17/classes_scheduler/blob/main/config/queue.yml"
    click RecurringJobs "https://github.com/sergiy17/classes_scheduler/blob/main/config/recurring.yml"
    click ActionCable "https://github.com/sergiy17/classes_scheduler/blob/main/config/cable.yml"
    click Storage "https://github.com/sergiy17/classes_scheduler/blob/main/config/storage.yml"
    click Cache "https://github.com/sergiy17/classes_scheduler/blob/main/config/cache.yml"
    click SMTP "https://github.com/sergiy17/classes_scheduler/blob/main/app/mailers/application_mailer.rb"
    click Docker "https://github.com/sergiy17/classes_scheduler/tree/main/Dockerfile"
    click KamalHooks "https://github.com/sergiy17/classes_scheduler/tree/main/.kamal/"
    click CICD "https://github.com/sergiy17/classes_scheduler/blob/main/.github/workflows/ci.yml"

    %% Styles
    classDef internal fill:#cfe2f3,stroke:#2b579a,color:#073763;
    classDef external fill:#d9ead3,stroke:#6aa84f,color:#274e13;
    classDef jobs fill:#f9cb9c,stroke:#e69138,color:#783f04;
```
