# apingali/fabric architecture

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

## Overview

##### Main Components
- CLI Interface: Represent the “cli” directory and associated Go files (cli.go, flags.go, output.go, etc.). This is the command‑line entry point that accepts user inputs, parameters, and flags.
- Patterns Repository: Show the “patterns” directory (with over a hundred subdirectories) that holds the markdown files describing AI prompts and workflows. This is a key resource that the CLI and other parts read to dispatch the “Patterns” regarding summarization, analysis, etc.
- Plugins System: Highlight the “plugins” directory and its subdirectories for AI integration (various vendor implementations, e.g., OpenAI, Anthropic, Azure, etc.), database connectors (in plugins/db), templating (in plugins/template), and additional tools. This modular design enables fabric’s extensibility.
- REST API: Include the “restapi” folder which provides API endpoints (chat, sessions, storage, contexts, etc.) that allow external applications – including the web UI – to interact with fabric’s core logic.
- Web Interface: Illustrate the “web” directory that contains the Svelte‑based frontend. Its structure (with directories for components, routes, interfaces, store, etc.) demonstrates that the web UI is a separate layer that talks to the REST API.
- Auxiliary Components: Represent the “nix” configurations, Dockerfile/docker‑compose, and container configurations. Although not part of the runtime architecture per se, these files are crucial for deployment, containerization, and environment reproducibility.

##### Relationships and Data Flow
- API Layer: The web UI communicates with the REST API to perform operations (chat, pattern retrieval, session management, etc.). Indicate clear REST endpoints that bridge user inputs with core functionalities.
- Pattern Processing Flow: Indicate that the CLI and REST API layer both reference the Patterns Repository. The engine reads markdown templates (from the “patterns” directory) and sends them to one or more AI providers via the Plugins system.
- Deployment: Optionally include Docker and Nix components to show that fabric is containerizable and has reproducible environments.

##### Architectural Patterns and Design Principles
- Modular, Extensible Design: Emphasize the loose coupling between the core engine and plugins (each plugin is organized by feature and vendor). This modular approach is a central design theme.
- Separation of Concerns: Illustrate that the CLI, API, and Web UI are separate concerns that interface with a common core. The Pattern Repository is also distinct and can be independently updated (as shown by update workflows in the .github folder).
- Configuration Driven: Include notes on environment configuration (Docker, devcontainer, flake.nix) which allow the project to run in a consistent environment.
- Workflow and Streaming: Highlight features such as “--stream” in CLI usage, which indicates real‑time processing or streaming data flows.

##### Relevant Technologies, Frameworks, and Libraries
- Go – the main programming language used across CLI, core, REST API, and plugins.
- Svelte, TypeScript, and related web tooling – used in the “web” directory for the front‑end.
- Docker and Nix – used for containerization and reproducible builds/configurations.
- GitHub Actions and Dockerfiles – for CI/CD and environment management.
- Markdown – used extensively for defining Patterns, which are the primary interfaces and prompts used by AI models.

##### Essential Elements
- Clear labels for every component and sub‑module (e.g., within plugins, group AI vendor implementations separately from database connectors).
- Annotations noting configuration files that support deployment (Docker, Nix, .devcontainer) and workflows (GitHub CI/CD files).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Users
    UserTerminal("User (Terminal)"):::user
    UserBrowser("User (Browser)"):::user

    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI("CLI Interface"):::presentation
        Web("Web Interface"):::presentation
    end

    %% Backend Services
    subgraph "Backend Services"
        REST("REST API"):::backend
        Core("Core Engine"):::backend
        Patterns("Patterns Repository"):::backend
    end

    %% Plugin/Integration Layer
    subgraph "Plugin/Integration Layer"
        Plugins("Plugins System"):::plugins
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Deployment("Deployment & Configurations"):::deployment
    end

    %% Data Flow - User Interactions
    UserTerminal -->|"triggers"| CLI
    UserBrowser  -->|"accesses"| Web

    %% CLI to Backend flow
    CLI -->|"invokes"| Core

    %% Web to REST API flow
    Web -->|"calls"| REST

    %% REST API flow
    REST -->|"processes"| Core

    %% Core Engine interactions with Repository and Plugins
    Core -->|"reads"| Patterns
    Core -->|"delegates"| Plugins
    REST -->|"delegates"| Plugins

    %% Deployment relationships
    CLI  -->|"deployed_on"| Deployment
    Web  -->|"deployed_on"| Deployment
    REST -->|"deployed_on"| Deployment
    Core -->|"deployed_on"| Deployment

    %% Click Events
    click CLI "https://github.com/apingali/fabric/tree/main/cli/"
    click Core "https://github.com/apingali/fabric/tree/main/core/"
    click Patterns "https://github.com/apingali/fabric/tree/main/patterns/"
    click Plugins "https://github.com/apingali/fabric/tree/main/plugins/"
    click REST "https://github.com/apingali/fabric/tree/main/restapi/"
    click Web "https://github.com/apingali/fabric/tree/main/web/"
    click Deployment "https://github.com/apingali/fabric/tree/main/.devcontainer/"

    %% Styles
    classDef presentation fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef backend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef plugins fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef deployment fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef user fill:#FFA07A,stroke:#333,stroke-width:2px;
```
