# colifeinc/108sharing architecture

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

- Interactive diagram: https://gitdiagram.com/colifeinc/108sharing
- Repository: https://github.com/colifeinc/108sharing

## Overview

##### Project Type and Purpose
- 108Sharing is a full-stack web application built with Ruby on Rails (Rails 6) on the backend and a dedicated frontend directory that houses React/TypeScript components.
- The application supports both a traditional server-rendered interface with Rails views and an API layer (with endpoints under /api and /admin/api) for client-side communication.
- It integrates essential external services such as Stripe for payments, Redis for caching and background job management (via Sidekiq), and likely third-party OAuth (Facebook, Google, Twitter) for social logins.

##### Analyzing the File Structure
- The “app” directory contains Rails MVC components: controllers (including separated admin and API controllers), models (with concerns and business logic), views (for user, admin, and mailers), jobs for background processing, mailers, and policies.
- The “frontend” directory contains a rich collection of React components (atoms, molecules, organisms, pages, layouts) indicating a modern component-based UI for client-side rendering and leveraging TypeScript.
- The “config” directory hosts environment settings, database configurations, initializers (including for Sidekiq and Stripe), and routes, which are central to understanding how requests are handled.
- Docker files (Dockerfile, docker-compose.yml) and deployment scripts (Makefile, Procfile, CI/CD configurations in .circleci and .github) indicate containerized deployment strategies.

##### Architectural Patterns Highlighted
- The application follows the standard Rails MVC pattern, enhanced with:
- An API layer for mobile or SPA clients.
- A separate frontend build (possibly using Webpack and Yarn) suggesting a decoupled or hybrid approach (server-side rendering plus client-side enhancements).
- Background processing with Sidekiq (via jobs and the Redis configuration).
- The design also includes aspects like service objects (in app/services) for orchestrating business logic, serialization (app/serializers) to format JSON responses, and policies (app/policies) to enforce authorization.

a. Main Components:
- Client/Browser: Users interact via web browsers which render both server-generated pages and run dynamic React components.
- Frontend (React/TypeScript): Responsible for rich client-side UI and consuming Rails APIs.
- Rails Web Server: Handles HTTP requests routed via Rails controllers (including traditional HTML and JSON API responses). It includes the MVC layers (views, controllers, models).
- Database (PostgreSQL): Stores persistent data (managed via ActiveRecord, migrations, seeds).
- Redis: Employed for caching, ActionCable (for WebSocket connections), and background job processing with Sidekiq.
- External Services: Stripe for payments, OAuth providers for authentication, and possibly image processing (Imagemagick) for assets.
- Background Jobs: Managed by Sidekiq (using code under app/jobs) for asynchronous tasks.
- Developer & CI/CD Infrastructure: Docker containers (Dockerfile, docker-compose), CI configurations (.github, .circleci) that orchestrate deployment and testing.

b. Relationships & Data Flow:
- User requests enter via the browser to the Rails web server, which routes some requests to server-rendered pages and others to API endpoints.
- The React frontend may be served via a separate webpack bundle or integrated assets and makes AJAX calls to the API.
- Rails communicates with the PostgreSQL database for CRUD operations.
- Redis is used for caching and as the backing store for Sidekiq and ActionCable, with background jobs (e.g., reservation reminders, notifications) enqueued.
- External API calls (e.g., Stripe payments, OAuth token validations) occur via dedicated service classes in app/services.
- The admin subsystem (with endpoints in /admin and /admin/api) provides a backend UI for administrators.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface Layer
    subgraph "User Interface Layer"
        Browser("Web Browser – Client"):::ui
        Frontend("React Frontend"):::ui
    end

    %% Application Layer
    subgraph "Application Layer"
        Rails("Rails Web Server"):::backend
        Controllers("Rails Controllers"):::backend
        Models("Rails Models"):::backend
        Views("Rails Views"):::backend
        subgraph "API Endpoints"
            API_User("User API Endpoints"):::backend
            API_Admin("Admin API Endpoints"):::backend
        end
        Service("Business Services"):::backend
        subgraph "Background Processing"
            Jobs("Background Jobs (Sidekiq)"):::backend
            SidekiqConfig("Sidekiq Config"):::backend
            SidekiqYml("Sidekiq YML"):::backend
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        Database("PostgreSQL DB"):::data
        Redis("Redis / Sidekiq"):::data
        subgraph "External Services Integration"
            StripeIntegration("Stripe Integration"):::external
            StripeService("Stripe Service"):::external
            StripeEvents("Stripe Events"):::external
            OAuthProviders("OAuth Providers"):::external
        end
    end

    %% Deployment & CI/CD Environment
    subgraph "Deployment & CI/CD Environment"
        Dockerfile("Dockerfile"):::deploy
        DockerCompose("Docker Compose"):::deploy
        CICD("CI/CD Pipelines"):::deploy
        GitHubCI("GitHub Workflows"):::deploy
        Procfile("Procfile"):::deploy
        ProcfileDev("Procfile.dev"):::deploy
        Makefile("Makefile"):::deploy
    end

    %% Connections between layers
    Browser -->|"requests"| Rails
    Browser -->|"loads"| Frontend
    Frontend -->|"AJAXcalls"| API_User
    Frontend -->|"AJAXcalls"| API_Admin

    Rails -->|"handles"| Controllers
    Controllers -->|"accesses"| Models
    Controllers -->|"renders"| Views
    Rails -->|"routes to"| API_User
    Rails -->|"routes to"| API_Admin
    Rails -->|"DBops"| Database
    Rails -->|"cache/jobs"| Redis
    Rails -->|"enqueues"| Jobs
    Jobs -->|"processed via"| Redis
    Rails -->|"calls"| StripeIntegration
    Rails -->|"calls"| OAuthProviders

    %% Deployment connections
    Dockerfile -->|"deploys"| Rails
    Dockerfile -->|"deploys"| Frontend
    DockerCompose -->|"orchestrates"| Rails
    DockerCompose -->|"orchestrates"| Frontend
    CICD -->|"triggers deploy"| Rails
    CICD -->|"triggers deploy"| Frontend

    %% Additional internal service interactions
    Service -->|"utilizes"| StripeService
    Service -->|"utilizes"| StripeEvents

    %% Click events for Rails MVC components
    click Controllers "https://github.com/colifeinc/108sharing/tree/master/app/controllers"
    click Views "https://github.com/colifeinc/108sharing/tree/master/app/views"
    click Models "https://github.com/colifeinc/108sharing/tree/master/app/models"

    %% Click events for API endpoints
    click API_User "https://github.com/colifeinc/108sharing/tree/master/app/controllers/api"
    click API_Admin "https://github.com/colifeinc/108sharing/tree/master/app/controllers/admin/api"

    %% Click event for Frontend
    click Frontend "https://github.com/colifeinc/108sharing/tree/master/frontend"

    %% Click events for Background Processing
    click Jobs "https://github.com/colifeinc/108sharing/tree/master/app/jobs"
    click SidekiqConfig "https://github.com/colifeinc/108sharing/blob/master/config/initializers/sidekiq.rb"
    click SidekiqYml "https://github.com/colifeinc/108sharing/blob/master/config/sidekiq.yml"

    %% Click events for External Services Integration
    click StripeIntegration "https://github.com/colifeinc/108sharing/blob/master/config/initializers/stripe.rb"
    click StripeService "https://github.com/colifeinc/108sharing/blob/master/app/services/stripe_charge_service.rb"
    click StripeEvents "https://github.com/colifeinc/108sharing/tree/master/app/services/stripe_event/"
    click OAuthProviders "https://github.com/colifeinc/108sharing/tree/master/app/services/o_auth_policy"

    %% Click event for Database
    click Database "https://github.com/colifeinc/108sharing/tree/master/db"

    %% Click events for Deployment & CI/CD
    click Dockerfile "https://github.com/colifeinc/108sharing/tree/master/Dockerfile"
    click DockerCompose "https://github.com/colifeinc/108sharing/blob/master/docker-compose.yml"
    click CICD "https://github.com/colifeinc/108sharing/tree/master/.circleci/"
    click GitHubCI "https://github.com/colifeinc/108sharing/tree/master/.github/workflows/"
    click Procfile "https://github.com/colifeinc/108sharing/tree/master/Procfile"
    click ProcfileDev "https://github.com/colifeinc/108sharing/blob/master/Procfile.dev"
    click Makefile "https://github.com/colifeinc/108sharing/tree/master/Makefile"

    %% Class definitions for styling
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef data fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef deploy fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
