# hackclub/hcb architecture

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

- Interactive diagram: https://gitdiagram.com/hackclub/hcb
- Repository: https://github.com/hackclub/hcb

## Overview

This project is a comprehensive Ruby on Rails full‐stack web application built to power HCB – a fiscal sponsorship platform. Its purpose is to facilitate and manage financial transactions for hackathons, Hack Clubs, and other organizations using fiscal sponsorship. The system handles user interactions, API endpoints, financial transactions, background processing, and integrations with external services (like Stripe, Plaid, Twilio, and Google APIs).

- Frontend/UI Layer: Represent the Rails “views” (found under app/views) along with the asset pipeline (app/assets) and JavaScript controllers/components that deliver the user experience. This layer will interact with controllers for both traditional HTML pages and dynamic API responses.
- Web/API Layer: Show the Rails controllers which are organized in both the public and versioned API namespaces (such as app/controllers/api/v4 and api_controller.rb). Emphasize the RESTful endpoints that serve web and mobile clients.
- Business Logic Layer: Highlight the Models (in app/models) along with Service Objects (in app/services) and Concerns that implement the domain’s financial logic (e.g. handling sponsorship, donations, disbursements, invoice processing and reconciliation). This encapsulates the MVC “model” but also many service objects for tasks like transaction ingestion and external integration logic.
- Background Processing and Jobs: Represent the job system (in app/jobs) and integration with Sidekiq (via config/sidekiq.yml and initializers) used to process financial transactions, notifications, fee calculations, and integrations asynchronously.
- Data Storage Layer: Include the primary database (configured via config/database.yml and managed by numerous migration files in db/migrate). Show Postgres (or similar RDBMS) as the persistent store of users, transactions, events, and financial records.
- External Integrations: Identify all external systems the application communicates with:
– Payment/Gateway Systems: Stripe (including Stripe cards, top-ups, service fees), PayPal transfers.
– Banking and Financial Services: Plaid, bank accounts, ACH transfers, checks.
– Communication Providers: Twilio (for SMS and messaging), email delivery via mailers.
– Google Services: Google Suite integrations and domain management.
– Other external endpoints like Doorkeeper for OAuth and metrics/analytics systems.
- Infrastructure / Deployment: Briefly note the existence of Docker files, Codespaces support, CI/CD workflows on GitHub, and heroku.yml indicating deployment practices.

- How controllers delegate business logic to Models and Service Objects.
- Database as a central component that all layers (web, API, background jobs) interact with to store and retrieve persistent data.

##### Architectural patterns and design principles
- Use of RESTful API versioning – highlight the versioned API controllers.
- Asynchronous processing for long-running tasks (via Sidekiq jobs and various nightlies).
- Modular design with clear integration points to external financial and messaging systems.
- Containerization and infrastructure as code (Docker, dev containers, CI/CD workflows) that support repeatable deployments.

##### Final steps
- Keep the level of detail balanced – include major components and interactions without overloading every single file; focus on how the major subsystems connect.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global User
    U("User (Browser)"):::user

    %% Frontend/UI Layer
    subgraph "Frontend/UI Layer"
        FV("Rails Views"):::frontend
        FA("Asset Pipeline"):::frontend
        FJ("JavaScript Components"):::frontend
    end

    %% Web/API Layer
    subgraph "Web/API Layer"
        WC("Rails Controllers"):::api
        API("API Endpoints"):::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        M("ActiveRecord Models"):::business
        SO("Service Objects"):::business
    end

    %% Background Processing and Jobs
    subgraph "Background Processing and Jobs"
        BJ("Background Jobs"):::background
        SK("Sidekiq Integration"):::background
    end

    %% Data Storage Layer
    subgraph "Data Storage Layer"
        DB(("Postgres Database")):::database
        MIG("Migrations & DB Config"):::database
    end

    %% External Integrations
    subgraph "External Integrations"
        ST("Stripe Integration"):::external
        PL("Plaid Integration"):::external
        TW("Twilio Integration"):::external
        GA("Google API Integration"):::external
        DO("Doorkeeper Integration"):::external
    end

    %% Infrastructure / Deployment
    subgraph "Infrastructure / Deployment"
        DC("Docker/Dev Containers"):::infra
        HD("Heroku Deployment"):::infra
        DS("Deployment Scripts"):::infra
    end

    %% Connections for UI and API
    U -->|"HTTP_request"| FV
    FV -->|"loads"| FA
    FV -->|"initiates"| FJ
    FJ -->|"calls"| WC

    %% Web/API relationships
    WC -->|"handles"| API
    WC -->|"delegates to"| M
    WC -->|"delegates to"| SO
    WC -->|"enqueues"| BJ

    %% Business Logic interactions
    M -->|"reads/writes"| DB
    SO -->|"processes"| DB

    %% Background Processing interactions
    BJ -->|"updates"| DB
    BJ -->|"triggers"| ST
    BJ -->|"triggers"| PL
    BJ -->|"triggers"| TW

    %% API and Business Logic to External Integrations
    SO -->|"integrates"| ST
    SO -->|"integrates"| PL
    SO -->|"integrates"| GA
    SO -->|"integrates"| DO

    %% External Integrations Database feedback (e.g. webhook callbacks)
    ST -->|"webhook"| BJ
    PL -->|"webhook"| BJ

    %% Controllers accessing External Integrations directly
    WC -->|"sends SMS"| TW

    %% Infrastructure connections (Deployment supports all layers)
    DC ---|"deploys"| FV
    DC ---|"deploys"| WC
    DC ---|"deploys"| M
    HD ---|"hosts"| DB
    DS ---|"manages"| WC

    %% Click Events
    click FV "https://github.com/hackclub/hcb/tree/main/app/views"
    click FA "https://github.com/hackclub/hcb/tree/main/app/assets"
    click FJ "https://github.com/hackclub/hcb/tree/main/app/javascript"
    click WC "https://github.com/hackclub/hcb/tree/main/app/controllers"
    click API "https://github.com/hackclub/hcb/tree/main/app/controllers/api"
    click M "https://github.com/hackclub/hcb/tree/main/app/models"
    click SO "https://github.com/hackclub/hcb/tree/main/app/services"
    click BJ "https://github.com/hackclub/hcb/tree/main/app/jobs"
    click SK "https://github.com/hackclub/hcb/blob/main/config/initializers/sidekiq.rb"
    click MIG "https://github.com/hackclub/hcb/tree/main/db/migrate"
    click DB "https://github.com/hackclub/hcb/blob/main/config/database.yml"
    click ST "https://github.com/hackclub/hcb/blob/main/config/initializers/stripe.rb"
    click PL "https://github.com/hackclub/hcb/tree/main/app/services/partners/plaid"
    click TW "https://github.com/hackclub/hcb/blob/main/config/initializers/twilio.rb"
    click GA "https://github.com/hackclub/hcb/blob/main/config/initializers/google_apis.rb"
    click DO "https://github.com/hackclub/hcb/blob/main/config/initializers/doorkeeper.rb"
    click DC "https://github.com/hackclub/hcb/blob/main/.devcontainer"
    click HD "https://github.com/hackclub/hcb/blob/main/heroku.yml"
    click DS "https://github.com/hackclub/hcb/tree/main/Procfile"

    %% Style Definitions
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef api fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef business fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef background fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef database fill:#e2e3e5,stroke:#6c757d,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef infra fill:#fefefe,stroke:#333,stroke-width:2px,stroke-dasharray: 2 2;
    classDef user fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
```
