# smallcloudai/refact architecture

> Architecture diagram of the GitHub repository smallcloudai/refact, 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/smallcloudai/refact
- Repository: https://github.com/smallcloudai/refact

## Overview

##### Major Components
- GUI / Frontend – Located in “refact-agent/gui”, which is a full-featured frontend built with components in TypeScript/React (or similar frameworks) using modern tooling (Vite, ESLint, Prettier) and integrating with the engine.
- Server – In “refact-server”, you see Dockerfiles, API routes, webgui middleware, and data pipelines. This layer serves the self-hosted containerized backend, offering REST endpoints, integration with databases (PostgreSQL, MySQL) and external APIs.
- Documentation & DevOps – The “docs” folder (built with Astro, storybook files, Docker Compose scripts) and GitHub workflows show CI/CD and documentation generation.
- Data Pipeline and Integration Modules – Within “refact-server/refact_data_pipeline” and “refact_known_models” are modules that process and filter data, manage model pipelines, and ensure integrations with external LLM providers. They are key for RAG (Retrieval-Augmented Generation) and support the Bring Your Own Key (BYOK) feature.
- Self-Hosting and Orchestration – Under “refact-server/self_hosting_machinery” there’s another layer responsible for finetuning, inference, watchdog scripts, and model hosting.

##### Relationships and Data Flow
- The GUI communicates with the server layer via APIs (provided by web endpoints in “refact-server/refact_webgui” and REST routers in “refact-agent/engine/src/http/routers/v1”).
- The engine interacts with integrations (like GitHub, GitLab, Docker, databases) to fetch code context and execute tasks. It also uses its modules for AST parsing, LSP capabilities, and tool execution.
- The server orchestrates deployments, handles authentication, and also manages data pipelines for processing model input and output.
- CI/CD pipelines (GitHub workflows/scripts) ensure that changes in these components are built and deployed correctly.

##### Architectural Patterns and Design Principles
- Modular structure: Each major functionality is neatly organized in its own folder (e.g., “engine”, “gui”, “server”) following separation of concerns.
- Microservices-like design: The agent engine and the server are somewhat decoupled, communicating through well-defined API interfaces.
- Integration through plugins: The system’s design allows for external tool integrations (e.g., IDE chat plugins, Docker containers, database connectors) as seen in the “integrations” directories.
- Use of containerization: With Dockerfiles present in both docs and server folders, containerization is a key deployment strategy.
- Extensibility: With a dedicated “plugins” guide and clear folder structures for integrations, the system has been architected with extension points.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        GUI["GUI / Frontend<br/>(TypeScript/React)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Server["Server (Backend Orchestration & API)<br/>(REST, Docker)"]:::backend
        Engine["Core Agent Engine<br/>(Rust & Python)"]:::backend
    end

    %% Integration Layer
    subgraph "Integration Layer"
        DataPipeline["Data Pipeline & Integration Modules<br/>(refact_data_pipeline, refact_known_models)"]:::integration
        SelfHosting["Self-Hosting and Orchestration<br/>(Model Hosting, Finetuning)"]:::integration
    end

    %% DevOps and Documentation
    subgraph "DevOps / Documentation"
        DevOps["Documentation & DevOps (CI/CD)<br/>(Astro, GitHub Workflows)"]:::devops
    end

    %% External Services
    ExternalServices["External Services<br/>(GitHub, GitLab, Docker, DBs, LLM APIs)"]:::external

    %% Plugin & Configuration Note
    BYOK["BYOK & Plugin Architecture"]:::note

    %% Connections
    GUI -->|"APIcalls"| Server
    Server -->|"RoutesRequest"| Engine
    Engine -->|"CallsIntegrations"| ExternalServices
    Server -->|"ManagesPipeline"| DataPipeline
    Server -->|"TriggersDeployments"| SelfHosting
    Engine -->|"Uses(AST&LSP)"| BYOK

    DevOps -->|"CI/CD"| GUI
    DevOps -->|"CI/CD"| Server
    DevOps -->|"CI/CD"| Engine
    DevOps -->|"CI/CD"| DataPipeline
    DevOps -->|"CI/CD"| SelfHosting

    %% Classes for styling
    classDef frontend fill:#A2D5F2,stroke:#333,stroke-width:2px;
    classDef backend fill:#F2A2A2,stroke:#333,stroke-width:2px;
    classDef integration fill:#A2F2A2,stroke:#333,stroke-width:2px;
    classDef devops fill:#F2E2A2,stroke:#333,stroke-width:2px;
    classDef external fill:#E2A2F2,stroke:#333,stroke-width:2px;
    classDef note fill:#D3D3D3,stroke:#333,stroke-dasharray: 5 5,stroke-width:2px;

    %% Click Events
    click Engine "https://github.com/smallcloudai/refact/tree/main/refact-agent/engine"
    click GUI "https://github.com/smallcloudai/refact/tree/main/refact-agent/gui"
    click Server "https://github.com/smallcloudai/refact/tree/main/refact-server"
    click DevOps "https://github.com/smallcloudai/refact/tree/main/docs"
    click DevOps "https://github.com/smallcloudai/refact/tree/main/.github/workflows"
    click DataPipeline "https://github.com/smallcloudai/refact/tree/main/refact-server/refact_data_pipeline"
    click DataPipeline "https://github.com/smallcloudai/refact/tree/main/refact-server/refact_known_models"
    click SelfHosting "https://github.com/smallcloudai/refact/tree/main/refact-server/self_hosting_machinery"
```
