# bindk/remitano_prj architecture

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

- Interactive diagram: https://gitdiagram.com/bindk/remitano_prj
- Repository: https://github.com/bindk/remitano_prj

## Overview

##### Main Components
- Rails Server (Application Core)
- Controllers: Separate API controllers (e.g., app/controllers/api/v1) and standard controller endpoints for server-side rendering.
- Views: Server-rendered views (with embedded React components planned for future work).
- Models: Business logic, including User and YouTubeVideo models.
- Routes: Centralized in config/routes.rb.
- ActionCable (Real-time Notifications)
- WebSocket server enabling real-time notifications when a new video is shared (e.g., app/channels/video_notifications_channel.rb).
- Sidekiq (Background Jobs)
- Background processing for tasks such as video processing (e.g., app/jobs/process_video_job.rb).
- External Services:
- PostgreSQL Database: Used for data storage (configured via config/database.yml).
- Redis: Serves multiple roles – as the backend for ActionCable (for real-time messaging) and as the queue backend for Sidekiq (configured in config/sidekiq.yml).
- Asset Pipeline & JavaScript: Server-side asset management (including Tailwind CSS and potential future React integration found in the app/assets and app/javascript directories).
- Deployment Infrastructure:
- Docker: Highlight containerization (Dockerfile and docker-related configurations).
- Dokku/Heroku-like Deployment: Note the deployment steps mentioned in the README for environments like Dokku.

##### Relationships and Interactions
- Frontend (server-rendered views and API endpoints) communicates directly with the Rails server.
- The Rails server interacts with the PostgreSQL database for CRUD operations.
- When a user shares a video:
- The controller invokes a service (e.g., app/services/youtube_video_extractor.rb) to extract OpenGraph metadata.
- The video is saved via the models.
- The background job (ProcessVideoJob) is enqueued and processed by Sidekiq using Redis.
- After successful processing, a notification is broadcasted over ActionCable to connected users.
- Asset compilation and JavaScript management take place using tools configured in app/assets and app/javascript, ensuring the frontend assets are properly built and served.

##### Architectural Patterns & Principles
- MVC Pattern: The standard Rails structure divides responsibilities among models, views, and controllers.
- Background Processing: Use of Sidekiq for offloading processing tasks and improving responsiveness.
- Real-time Communication: Leverage ActionCable to provide real-time notifications.
- API Layer Separation: There is a clear REST API structure (under app/controllers/api/v1) that distinguishes API logic from traditional server-rendered endpoints.
- Modularization: Services (app/services) encapsulate specific logic such as YouTube metadata extraction.

##### Relevant Technologies, Frameworks, and Libraries
- Ruby on Rails (version info from README)
- PostgreSQL for the database
- Redis for caching, ActionCable, and Sidekiq
- Sidekiq as the background job processor
- Tailwind CSS for styling (as observed in assets)
- ActionCable (for WebSockets)
- Devise (for authentication as seen from config/initializers/devise.rb)
- Docker and Dokku for deployments

##### Elements
- For example, from the client to the Rails server (authentication, video sharing requests) and from the Rails server to PostgreSQL and Redis.
- Asynchronous communication from Sidekiq, triggered by certain actions, and then the real-time notifications sent via ActionCable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client (Browser)"):::client

    subgraph "Rails Server"
        subgraph "Controllers"
            StdCtrl("Standard Controllers"):::rails
            ApiCtrl("API Controllers"):::rails
        end
        Views("Views"):::rails
        Models("Models"):::rails
        Routes("Routes"):::rails
    end

    subgraph "ActionCable"
        AC("Channel Server"):::rails
        AC_JS("JavaScript Channel"):::rails
    end

    subgraph "Sidekiq"
        SK_JOB("Process Video Job"):::rails
        SK_CONF("Sidekiq Configuration"):::rails
    end

    subgraph "External Services"
        PG("PostgreSQL Database"):::external
        Redis("Redis"):::external
    end

    subgraph "Asset Pipeline & JavaScript"
        ASSETS("Assets"):::asset
        JS("JavaScript"):::asset
    end

    subgraph "Modular Services"
        YT("YouTube Metadata Extraction"):::rails
        SR("Service Result Handling"):::rails
    end

    subgraph "Deployment Infrastructure"
        DEP_DOCKER("Docker"):::rails
        DEP_DOKKU("Deployment Config"):::rails
    end

    %% Connections
    Client -->|"HTTP"| StdCtrl
    Client -->|"HTTP"| ApiCtrl

    Routes -->|"routes"| StdCtrl
    Routes -->|"routes"| ApiCtrl

    StdCtrl -->|"render"| Views
    ApiCtrl -->|"process_video"| YT

    YT -->|"result"| SR
    SR -->|"save"| Models
    Models -->|"CRUD"| PG

    ApiCtrl -->|"enqueue_job"| SK_JOB
    SK_JOB -->|"uses"| Redis
    SK_JOB -->|"broadcast"| AC
    AC -->|"notify"| Client

    Views -->|"assets"| ASSETS
    Views -->|"assets"| JS

    StdCtrl -->|"deploy"| DEP_DOCKER
    ApiCtrl -->|"deploy"| DEP_DOKKU

    %% Styling Arrow Links
    %% Arrows indices:
    %% 0: Client-->StdCtrl
    %% 1: Client-->ApiCtrl
    %% 2: Routes-->StdCtrl
    %% 3: Routes-->ApiCtrl
    %% 4: StdCtrl-->Views
    %% 5: ApiCtrl-->YT
    %% 6: YT-->SR
    %% 7: SR-->Models
    %% 8: Models-->PG
    %% 9: ApiCtrl-->SK_JOB (dashed)
    %% 10: SK_JOB-->Redis (dashed)
    %% 11: SK_JOB-->AC (dashed)
    %% 12: AC-->Client (dashed)
    %% 13: Views-->ASSETS
    %% 14: Views-->JS
    %% 15: StdCtrl-->DEP_DOCKER
    %% 16: ApiCtrl-->DEP_DOKKU

    linkStyle 0 stroke:#FFA500,stroke-width:2px;
    linkStyle 1 stroke:#FFA500,stroke-width:2px;
    linkStyle 2 stroke:#FFA500,stroke-width:2px;
    linkStyle 3 stroke:#FFA500,stroke-width:2px;
    linkStyle 4 stroke:#FFA500,stroke-width:2px;
    linkStyle 5 stroke:#FFA500,stroke-width:2px;
    linkStyle 6 stroke:#FFA500,stroke-width:2px;
    linkStyle 7 stroke:#FFA500,stroke-width:2px;
    linkStyle 8 stroke:#FFA500,stroke-width:2px;
    linkStyle 13 stroke:#FFA500,stroke-width:2px;
    linkStyle 14 stroke:#FFA500,stroke-width:2px;
    linkStyle 15 stroke:#FFA500,stroke-width:2px;
    linkStyle 16 stroke:#FFA500,stroke-width:2px;
    linkStyle 9 stroke:#FFA500,stroke-width:2px,stroke-dasharray: 5 5;
    linkStyle 10 stroke:#FFA500,stroke-width:2px,stroke-dasharray: 5 5;
    linkStyle 11 stroke:#FFA500,stroke-width:2px,stroke-dasharray: 5 5;
    linkStyle 12 stroke:#FFA500,stroke-width:2px,stroke-dasharray: 5 5;

    %% Click events
    click StdCtrl "https://github.com/bindk/remitano_prj/tree/main/app/controllers"
    click ApiCtrl "https://github.com/bindk/remitano_prj/tree/main/app/controllers/api/v1"
    click Views "https://github.com/bindk/remitano_prj/tree/main/app/views"
    click Models "https://github.com/bindk/remitano_prj/tree/main/app/models"
    click Routes "https://github.com/bindk/remitano_prj/blob/main/config/routes.rb"
    click AC "https://github.com/bindk/remitano_prj/blob/main/app/channels/video_notifications_channel.rb"
    click AC_JS "https://github.com/bindk/remitano_prj/blob/main/app/javascript/channels/video_notifications_channel.js"
    click SK_JOB "https://github.com/bindk/remitano_prj/blob/main/app/jobs/process_video_job.rb"
    click SK_CONF "https://github.com/bindk/remitano_prj/blob/main/config/sidekiq.yml"
    click PG "https://github.com/bindk/remitano_prj/blob/main/config/database.yml"
    click Redis "https://github.com/bindk/remitano_prj/blob/main/config/cable.yml"
    click ASSETS "https://github.com/bindk/remitano_prj/tree/main/app/assets"
    click JS "https://github.com/bindk/remitano_prj/tree/main/app/javascript"
    click YT "https://github.com/bindk/remitano_prj/blob/main/app/services/youtube_video_extractor.rb"
    click SR "https://github.com/bindk/remitano_prj/blob/main/app/services/service_result.rb"
    click DEP_DOCKER "https://github.com/bindk/remitano_prj/tree/main/Dockerfile"
    click DEP_DOKKU "https://github.com/bindk/remitano_prj/blob/main/Procfile.dev"

    %% Classes
    classDef rails fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef external fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef asset fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef client fill:#FFB6C1,stroke:#000,stroke-width:2px;
    
    class Client client;
    class StdCtrl,ApiCtrl,Views,Models,Routes,AC,AC_JS,SK_JOB,SK_CONF,YT,SR,DEP_DOCKER,DEP_DOKKU rails;
    class PG,Redis external;
    class ASSETS,JS asset;
```
