# g4rkk/buddhism architecture

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

- Interactive diagram: https://gitdiagram.com/g4rkk/buddhism
- Repository: https://github.com/g4rkk/buddhism

## Overview

##### Main Components
- Client (Browser/User Interface): Represents the web clients that interact with the application.
- Web Server / Rails Application: The core backend using Rails’ MVC structure.
- Controllers (e.g., Users, Books, Buddhist Sites, Meditation Guides, etc.)
- Models (ActiveRecord models for Users, Books, MeditationGuides, etc.)
- Views (ERB templates, layouts, partials)
- Frontend JavaScript Layer: Includes Stimulus controllers, channels for real-time updates, and assets (Tailwind CSS, JavaScript bundles).
- Real-Time Communication Component: ActionCable channels powered by Rails and backed by Redis (e.g., chat functionality for community features).
- Background Job Processing: Sidekiq integrated with Redis for sending reminders via SMS (using Twilio, LINE APIs) and handling notifications.
- Storage and File Handling: ActiveStorage for image uploads (books, guides) and media content (audio for meditation guides).
- External Service Integrations:
- Authentication via Devise (user registration and login)
- Third-party APIs like Google Maps API and Geocoder for location-based features (finding Buddhist sites, nearby friends, and community mapping).
- AWS Personalize for personalized content recommendations.
- Messaging APIs (Twilio, and/or LINE Messaging API) for notifications.
- Database: The relational database (managed via ActiveRecord) for storing users, meditation records, Buddhist scriptures, etc.

##### Relationships and Interactions
- The Client interacts with the Rails Application via HTTP requests, receiving rendered views and dynamic content updates.
- The Rails Controllers process requests, utilizing Models (data logic) and Views (presentation) following the MVC flow.
- JavaScript controllers (Stimulus) handle dynamic UI interactions on the client side, sending asynchronous requests as needed.
- Background jobs (managed by Sidekiq) operate asynchronously. Indicate that certain user actions (like setting reminders) trigger Sidekiq jobs that communicate with external messaging services.
- File uploads are managed by ActiveStorage; add a component for the File Storage layer that stores images and audio files.

##### Architectural Patterns/Design Principles
- Real-Time and Asynchronous Processing: Understand that ActionCable (using Redis) and Sidekiq (with background processing) are important for responsiveness.
- Service-Oriented/Integration Points: External services are integral, so their connections must be clearly labeled.
- Separation of Concerns: Frontend assets managed by Webpacker/Yarn, backend business logic in Ruby, and background/real-time functionality in dedicated service components.

##### Relevant Technologies and Frameworks
- Ruby on Rails, Devise, ActiveRecord, Stimulus, ActionCable, ActiveStorage, Sidekiq, Tailwind CSS.
- External APIs: Google Maps API, AWS Personalize, Twilio/LINE Messaging API.
- Data stores: Primary relational database and Redis (for ActionCable and Sidekiq).

##### Be Detail-Oriented
- Separate the system into as many detailed components as possible so that each function (user management, media handling, real-time chat, notifications, geolocation) is clearly represented.
- Direction of data flow and dependency relationships among the components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        A["Client (Browser)"]:::client
        subgraph "Frontend Assets"
            E["Stimulus Controllers"]:::frontend
            F["Webpack Assets"]:::frontend
            F2["Frontend Stylesheets"]:::frontend
        end
    end

    %% Rails Application
    subgraph "Rails Application"
        B["Controllers"]:::backend
        C["Models"]:::backend
        D["Views"]:::backend
        M["Authentication (Devise)"]:::external
    end

    %% Server Side Components
    subgraph "Server Side"
        G["Real-Time Server (ActionCable)"]:::realtime
        H["Background Job Processor (Sidekiq)"]:::background
        I["ActiveStorage"]:::storage
        I2["CarrierWave"]:::storage
        N["Database (ActiveRecord)"]:::database
    end

    %% External Services Subgraph
    subgraph "External Services"
        J["Google Maps API"]:::external
        K["AWS Personalize"]:::external
        L["Messaging API (Twilio/LINE)"]:::external
    end

    %% Connections between layers

    %% Client to Rails Application
    A -->|"HTTPRequest"| B
    B -->|"UsesLogic"| C
    B -->|"Renders"| D
    D -->|"DeliversHTML/JS"| A

    %% Client loads Frontend Assets
    A -->|"LoadsStimulus"| E
    A -->|"LoadsAssets"| F
    A -->|"LoadsStyles"| F2

    %% Rails Application interactions
    B -->|"RealTimeChat"| G
    B -->|"TriggersAsyncJob"| H
    B -->|"FileUploads"| I
    B -->|"BookUploads"| I2
    C -->|"Queries"| N

    %% External Integrations
    B -->|"Geolocation"| J
    B -->|"ContentRec"| K
    H -->|"SendsNotifications"| L

    %% Authentication flow
    A -->|"UserAuthDevise"| M
    M -->|"AuthProcessing"| B

    %% Real-Time Updates to Client
    G -->|"WebSocketUpdates"| A

    %% Click Events
    click D "https://github.com/g4rkk/buddhism/tree/main/app/views"
    click E "https://github.com/g4rkk/buddhism/tree/main/app/javascript/controllers"
    click F "https://github.com/g4rkk/buddhism/blob/main/app/javascript/application.js"
    click F2 "https://github.com/g4rkk/buddhism/tree/main/app/javascript/stylesheets"
    click B "https://github.com/g4rkk/buddhism/tree/main/app/controllers"
    click C "https://github.com/g4rkk/buddhism/tree/main/app/models"
    click M "https://github.com/g4rkk/buddhism/blob/main/app/controllers/users/omniauth_callbacks_controller.rb"
    click G "https://github.com/g4rkk/buddhism/tree/main/app/channels"
    click H "https://github.com/g4rkk/buddhism/tree/main/app/jobs"
    click I "https://github.com/g4rkk/buddhism/blob/main/config/storage.yml"
    click I2 "https://github.com/g4rkk/buddhism/blob/main/app/uploaders/book_uploader.rb"
    click N "https://github.com/g4rkk/buddhism/tree/main/db/migrate"

    %% Style Classes
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef frontend fill:#87CEEB,stroke:#000,stroke-width:2px;
    classDef realtime fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef background fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef storage fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#FFCC99,stroke:#000,stroke-width:2px;
    classDef database fill:#F08080,stroke:#000,stroke-width:2px;
```
