# indentlabs/notebook architecture

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

- Interactive diagram: https://gitdiagram.com/indentlabs/notebook
- Repository: https://github.com/indentlabs/notebook

## Overview

##### Project type and purpose
- Notebook.ai is a full‐stack, monolithic Ruby on Rails web application providing both server‐rendered pages and a JSON API.
- Its goal is to help writers and roleplayers build and manage fictional universes via an interactive web interface, background processing (text analysis, machine learning hooks), and third‐party integrations (Stripe, PayPal, Slack, IBM Watson).

##### File structure
- Top‐level “app/” folder:
– app/controllers: Rails controllers including namespaced API controllers
– app/models: ActiveRecord models and concerns (business/domain logic)
– app/views: ERB templates for server‐rendered UI
– app/assets & app/javascript: asset‐pipeline (Sprockets) and Webpacker assets, JS components
– app/services: plain‐Ruby service objects encapsulating domain logic (e.g., document analysis, payment, autocomplete)
– app/jobs: background jobs (e.g., DocumentAnalysisJob)
- config/: Rails configuration, routes, cable (Action Cable), database, sidekiq/delayed_job, webpacker
- lib/: extensions, custom rake tasks
- bin/: startup scripts (rails server, delayed_job, webpack-dev-server)
- Dockerfile / docker-compose.yml: containerization
- spec/ & test/: automated tests
- README.rdoc: high‐level project description and deployment workflow

##### README for additional insights
- Confirms Rails stack, testing by `rails test`, deployment via staging/live with regression tests
- Emphasizes future extension areas: NLP services, ML name generators, knowledge graph

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        BROWSER["Web Browser / Mobile WebView"]:::user
        JS["JS/React Components"]:::user
        ASSETS["Sprockets Assets"]:::user
    end

    %% Web/Application Layer
    subgraph "Web/Application Layer"
        direction TB
        LB["Load Balancer (AWS ELB)"]:::infra
        PUMA["Puma + Rails"]:::core
        CTRL["Controllers"]:::core
        VIEWS["Views (ERB + API Docs)"]:::core
        MODELS["Models"]:::core
        SERVICES["Service Objects"]:::core
        AUTHZ["Authorizers"]:::core
    end

    %% Persistence & Data Services
    subgraph "Persistence & Data Services"
        direction TB
        PG["PostgreSQL"]:::data
        REDIS["Redis"]:::data
        STORAGE["ActiveStorage"]:::data
    end

    %% Background Processing
    subgraph "Background Processing"
        direction TB
        JOBS["Background Jobs (Sidekiq/DelayedJob)"]:::infra
        JOBCONF["Sidekiq Config"]:::infra
        BINS["Bin Scripts"]:::infra
    end

    %% Real-time / Pub-Sub
    subgraph "Real-time / Pub-Sub"
        direction TB
        ACTIONCABLE["Action Cable (WebSockets)"]:::core
    end

    %% External Integrations
    subgraph "External Integrations"
        direction TB
        STRIPE["Stripe & PayPal"]:::external
        SLACK["Slack & Discord"]:::external
        WATSON["IBM Watson"]:::external
        EMAIL["Email Service (SMTP)"]:::external
    end

    %% Infrastructure / DevOps
    subgraph "Infrastructure / DevOps"
        direction TB
        DOCKER["Docker / docker-compose"]:::infra
        CICD["CI/CD (GitHub Actions)"]:::infra
        PUMACONF["Puma Config"]:::infra
        WEBPACK["Webpack Config"]:::infra
    end

    %% Connections
    BROWSER -->|"HTTP(S)"| LB
    JS -->|"bundles via Webpacker"| PUMA
    ASSETS -->|"served by Rails"| PUMA

    LB --> PUMA
    PUMA --> CTRL
    CTRL --> MODELS
    CTRL --> SERVICES
    CTRL --> AUTHZ
    CTRL --> VIEWS
    MODELS --> PG
    SERVICES --> MODELS

    CTRL -->|"enqueue → Redis"| REDIS
    REDIS --> JOBS
    JOBS --> SERVICES
    SERVICES --> MODELS
    JOBS -->|"run via Bin Scripts"| BINS

    PUMA --> ACTIONCABLE
    ACTIONCABLE --> REDIS
    ACTIONCABLE --> BROWSER

    SERVICES --> STRIPE
    SERVICES --> SLACK
    SERVICES --> WATSON
    SERVICES --> EMAIL
    SERVICES --> STORAGE

    DOCKER --> PUMA
    DOCKER --> REDIS
    DOCKER --> PG

    CICD -->|"tests.yml"| CTRL
    CICD --> JOBS

    PUMACONF --- PUMA
    WEBPACK --- JS

    %% Click Events
    click JS "https://github.com/indentlabs/notebook/tree/master/app/javascript"
    click ASSETS "https://github.com/indentlabs/notebook/tree/master/app/assets"
    click CTRL "https://github.com/indentlabs/notebook/tree/master/app/controllers"
    click MODELS "https://github.com/indentlabs/notebook/tree/master/app/models"
    click VIEWS "https://github.com/indentlabs/notebook/tree/master/app/views"
    click SERVICES "https://github.com/indentlabs/notebook/tree/master/app/services"
    click AUTHZ "https://github.com/indentlabs/notebook/tree/master/app/authorizers"
    click PG "https://github.com/indentlabs/notebook/blob/master/config/database.yml"
    click REDIS "https://github.com/indentlabs/notebook/blob/master/config/sidekiq.yml"
    click STORAGE "https://github.com/indentlabs/notebook/blob/master/config/storage.yml"
    click JOBS "https://github.com/indentlabs/notebook/tree/master/app/jobs"
    click JOBCONF "https://github.com/indentlabs/notebook/blob/master/config/sidekiq.yml"
    click BINS "https://github.com/indentlabs/notebook/tree/master/bin"
    click ACTIONCABLE "https://github.com/indentlabs/notebook/blob/master/config/cable.yml"
    click STRIPE "https://github.com/indentlabs/notebook/blob/master/app/services/stripe_service.rb"
    click SLACK "https://github.com/indentlabs/notebook/blob/master/app/services/slack_service.rb"
    click WATSON "https://github.com/indentlabs/notebook/blob/master/app/services/documents/analysis/third_party/ibm_watson_service.rb"
    click EMAIL "https://github.com/indentlabs/notebook/tree/master/app/mailers"
    click DOCKER "https://github.com/indentlabs/notebook/tree/master/Dockerfile"
    click CICD "https://github.com/indentlabs/notebook/blob/master/.github/workflows/tests.yml"
    click PUMACONF "https://github.com/indentlabs/notebook/blob/master/config/puma.rb"
    click WEBPACK "https://github.com/indentlabs/notebook/blob/master/config/webpacker.yml"

    %% Styles
    classDef user fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef data fill:#FFD580,stroke:#333,stroke-width:1px
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px
```
