# i-dot-ai/redbox architecture

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

- Interactive diagram: https://gitdiagram.com/i-dot-ai/redbox
- Repository: https://github.com/i-dot-ai/redbox

## Overview

- a Django web application (found in the “django_app” directory) that provides the front end (built with modern JS tooling, Parcel, and custom web components) and the web server/API for user interactions,
- and a separate core AI library (found in “redbox-core”) that encapsulates the logic for working with GenAI, including chat, summarisation, LangChain/ Langgraph integration, and AI settings.

##### Main components
– User Interface / Frontend:
◦ Represents the client side (web browser) that interacts with the application.
◦ Includes static assets built by Parcel, custom web components (e.g., chat controllers, document upload components), and CSS/JS bundled in “django_app/frontend”.
– Django Backend Application:
◦ Acts as the server-side layer.
◦ Contains “redbox_app” with views, API endpoints, authentication, and management commands.
◦ Uses Django templates (for pages like chats, sign-ups, accessibility statements, etc.) and integrates static assets.
– Redbox-Core AI Library:
◦ Encapsulated in “redbox-core” and responsible for all AI functionality such as processing chat requests, summarisation, and handling dynamic AI settings (set per request).
◦ This component integrates with external AI services (LLMs such as GPT-4, as mentioned) and also likely uses LangChain/Langgraph.
– Data Storage and Infrastructure:
◦ Although not shown explicitly within the Django app code, the infrastructure folder (with AWS terraform files) indicates a deployed environment that includes services such as RDS/Postgres, S3 for object storage, and possibly Elasticsearch as noted in “data/elastic-dumps”.
◦ There is also a “queue” folder for task queuing and the use of django-q for scheduled tasks.
– Containerization and Deployment:
◦ The Dockerfiles (in both “django_app” and “redbox-core”), docker-compose.yml, and GitHub workflow files indicate that containerisation (using Docker/ECS) is a key part of the deployment pipeline.
◦ Deployment components include CI/CD pipelines, AWS infrastructure definitions (infrastructure/aws), and scheduled tasks managed via docker-compose and terraform.

– Begin at the Browser/User:
– Django Backend:
◦ Internally, show a module break-down of the Django app:
▪ “redbox_app” for views and endpoints.
▪ “frontend” for static asset delivery.
▪ “tests” and “management commands” for scheduled tasks (django-q).
– AI Core:
◦ Use directed lines to indicate calls from Django to redbox-core (e.g., when a chat message is received, summarisation is requested, etc.).
◦ Annotate that dynamic AI settings are passed in per-request and that redbox-core uses LangChain/LangGraph.
– Data and External Services:
◦ Represent a “Database” (likely PostgreSQL, given the AWS RDS Terraform files) connected to the Django Backend.
◦ Optionally, show “Object Storage” (S3) for static file storage and “Search/Elastic” components (referencing the elastic-dumps directory) if relevant.
– Infrastructure / Deployment Flow:
◦ Add ancillary blocks for “Container Registry (ECR)” and “Deployment Orchestration (AWS ECS/Load Balancer)” to capture the deployment flow.
◦ Include CI/CD components (represented by GitHub Actions workflows) and configuration for tasks (terraform, Docker).

##### Architectural patterns and design principles
– Separation of concerns: The division between the Django web frontend/backend and the AI engine in redbox-core.
– Containerisation: Use of Docker for both Django and core library, implying encapsulated environments.
– Micro-modularity: Even though the application is not microservices-based in a classical sense, the redbox-core library is a distinct module that can be independently tested and evolved.
– Scalability and External Integration: AWS infrastructure elements indicate that the system is designed to scale and interact with external managed services (RDS, S3, etc.).

▪ For example, use blue for frontends, green for business logic (Django & redbox-core), and grey for external systems.
– Make sure to include any supporting elements such as testing pipelines (e.g., GitHub workflows) since they impact the runtime integration and deployment lifecycle.

- The separation between the web-facing Django app and the underlying GenAI processing in redbox-core.
- The interactions via API calls and scheduled tasks.
- Deployment components that outline how containerization, cloud infrastructure, and CI/CD pipelines come together.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface
    subgraph "User Interface"
        UI["User Browser"]:::frontend
        FE["Static Assets (Parcel, Web Components)"]:::frontend
    end

    %% Django Backend Application
    subgraph "Django Backend Application"
        Django["Django Application"]:::backend
        RedboxApp["redbox_app (views, endpoints, templates, management)"]:::backend
        Manage["manage.py"]:::backend
    end

    %% Redbox-Core AI Library
    subgraph "Redbox-Core AI Library"
        AICore["redbox-core (GenAI, Chat, Summarisation, LangChain)"]:::ai
    end

    %% Data Storage and Infrastructure
    subgraph "Data Storage and Infrastructure"
        Database["PostgreSQL (AWS RDS)"]:::data
        ObjectStore["Object Storage (S3)"]:::data
        Elastic["Elastic Dumps (Search)"]:::data
        Queue["Task Queue (django-q)"]:::data
    end

    %% Containerization and Deployment
    subgraph "Containerization and Deployment"
        DockerDjango["Django Dockerfile"]:::deployment
        DockerCore["redbox-core Dockerfile"]:::deployment
        DockerLit["lit_ssr Dockerfile"]:::deployment
        Compose["docker-compose.yml"]:::deployment
        CICD["CI/CD Pipelines (.github/workflows)"]:::deployment
        AWSInfra["AWS Infrastructure (Terraform)"]:::deployment
    end

    %% Connections
    UI -->|"HTTP/HTTPS"| Django
    FE -->|"Delivers static assets"| Django
    Django -->|"API calls"| AICore
    AICore -->|"Processed data"| Django
    Django -->|"DB operations"| Database
    Django -->|"Static file access"| ObjectStore
    Django -->|"Schedules tasks"| Queue

    %% Deployment Relationships (illustrative)
    DockerDjango -.-> Django
    DockerCore -.-> AICore
    DockerLit -.-> FE
    Compose -.-> DockerDjango
    Compose -.-> DockerCore
    Compose -.-> DockerLit
    CICD -.-> AWSInfra

    %% Click Events
    click FE "https://github.com/i-dot-ai/redbox/tree/main/django_app/frontend"
    click RedboxApp "https://github.com/i-dot-ai/redbox/tree/main/django_app/redbox_app"
    click Manage "https://github.com/i-dot-ai/redbox/blob/main/django_app/manage.py"
    click AICore "https://github.com/i-dot-ai/redbox/tree/main/redbox-core"
    click AWSInfra "https://github.com/i-dot-ai/redbox/tree/main/infrastructure/aws"
    click Elastic "https://github.com/i-dot-ai/redbox/tree/main/data/elastic-dumps"
    click ObjectStore "https://github.com/i-dot-ai/redbox/tree/main/data/objectstore"
    click Queue "https://github.com/i-dot-ai/redbox/tree/main/data/queue"
    click DockerDjango "https://github.com/i-dot-ai/redbox/tree/main/django_app/Dockerfile"
    click DockerCore "https://github.com/i-dot-ai/redbox/tree/main/redbox-core/Dockerfile"
    click DockerLit "https://github.com/i-dot-ai/redbox/tree/main/lit_ssr/Dockerfile"
    click Compose "https://github.com/i-dot-ai/redbox/blob/main/docker-compose.yml"
    click CICD "https://github.com/i-dot-ai/redbox/tree/main/.github/workflows"

    %% Styles
    classDef frontend fill:#bbd2ff,stroke:#1f78c1,stroke-width:2px;
    classDef backend fill:#c6e2b3,stroke:#28a745,stroke-width:2px;
    classDef ai fill:#d7bde2,stroke:#8e44ad,stroke-width:2px;
    classDef data fill:#f0f0f0,stroke:#6c757d,stroke-width:2px;
    classDef deployment fill:#ffe5b4,stroke:#ff8c00,stroke-width:2px;
```
