# ruvnet/reflective-engineer architecture

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

- Interactive diagram: https://gitdiagram.com/ruvnet/reflective-engineer
- Repository: https://github.com/ruvnet/reflective-engineer

## Overview

##### Project Type and Purpose
- This project is a full-stack web application built as a development environment for AI agents.
- It leverages advanced prompting techniques, memory systems, and an extensive template library to help users create and deploy intelligent, context-aware AI agents.
- Key functionalities highlighted in the README include sophisticated prompting systems (e.g., chain of thought, tree of thoughts), multiple memory systems, template editing, live previews, and deployment options.

##### Analyzing the File Structure
- Top-Level Files and Directories:
- Configuration and deployment files (Dockerfile, fly.toml, .github/workflows) point to containerized and cloud deployment options.
- Frontend components are stored in directories like “src”, “public”, and “src/components” with a heavy use of React (TSX files).
- Service files in “src/services” (agentService, langchainService, settingsService, etc.) indicate business logic and API integrations.
- Templates in Markdown under “public/templates” and “src/templates” suggest a core Template Engine powering the AI agents.
- Testing is integrated via “jest.config.js” and “src/test” setups.
- Architectural Patterns:
- A clear separation between Presentation (UI components/pages) and Business Logic (services, template engine, memory systems) is evidenced.
- Likely a component-based approach (React) combined with modular service layers (e.g., language chain service, storage, deployment).

##### Elements
a. Main Components:
- User Interface (Frontend)
- Components (React TSX files, UI library components under “src/components/ui”)
- Pages (user navigation views like Agents, Templates, Documentation, etc.)
- Template Editor and Live Preview interfaces.
- Core Engine / Business Logic
- Template Engine: Manages agent templates (Markdown files in “public/templates” and “src/templates”).
- Memory Systems: Implements various memory mechanisms (Buffer, Conversation, Entity, etc. as noted in README).
- Chain Manager: Coordinates prompt chains (sequential chains, router chains, API chains, etc.)
- Service Layer: Contains modules like agentService, langchainService, settingsService, toolService.
- External Integrations
- LangChain: The core framework for agent behavior.
- OpenAI (and possibly other AI providers) for language model services.
- Vector Stores and external APIs (for retrieval, QA, and structured output).
- Deployment and DevOps
- Docker & Fly deployment files for containerization and cloud deployment.
- CI/CD workflows from GitHub Actions.
- Testing and Development Tools
- Automated testing (jest configuration, tests in “src/test”).
- Development utilities (configuration via sample.env, build scripts, etc.)

b. Relationships and Interactions:
- Data flow from the front-end UI (user interactions in pages/components) to the backend service layer.
- How the Template Engine feeds agent configurations into the Chain Manager.
- Deployment pipelines (CI/CD, Docker, Cloud deployment) which manage versioning and environment configurations.

c. Important Architectural Patterns:
- Separation of Concerns: Clearly delineate the UI, service logic, and integration layers.
- Modular Design: Each service (agent, template, memory, tool integration) is treated as a separate module/component.
- Extensibility: The template-based structure, along with clearly defined integration points, supports adding new agent types, prompting systems, or memory models.

d. Relevant Technologies and Frameworks:
- UI and Frontend: React with TypeScript, Tailwind CSS, and a component-based UI library.
- Build and Configuration: Vite, ESLint, PostCSS.
- Backend/Services: Node.js modules for handling external integrations, API calls, and data management.
- AI and Integration: LangChain, OpenAI’s API, vector-based memory and retrieval services.
- Testing: Jest and associated test configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer - User Interface"
        A["UI Components"]:::frontend
        B["UI Pages & Navigation"]:::frontend
    end

    %% Business Logic / API Layer
    subgraph "Business Logic / API Layer"
        subgraph "Template Engine"
            U["Public Templates"]:::business
            V["Internal Templates"]:::business
        end
        D["Memory Systems"]:::business
        E["Chain Manager"]:::business
        subgraph "Service Layer"
            F["Agent Service"]:::business
            G["LangChain Service"]:::business
            H["LangGraph Service"]:::business
            I["OpenRouter Service"]:::business
            J["Template Service"]:::business
            K["Settings Service"]:::business
            L["Tool Service"]:::business
            M["Storage Service"]:::business
        end
    end

    %% External Integrations
    subgraph "External Integrations"
        N["LangChain Integration"]:::integration
        O["OpenAI_&_External_APIs"]:::integration
        P["Vector_Stores"]:::integration
    end

    %% Deployment and CI/CD
    subgraph "Deployment and CI/CD"
        Q["Containerization"]:::deployment
        R["CI/CD Workflows"]:::deployment
    end

    %% Testing & Development Tools
    subgraph "Testing & Development Tools"
        X["Jest Config"]:::testing
        Y["Test Directory"]:::testing
    end

    %% Flow Connections
    %% Presentation to Business Logic
    B -->|"request_template"| U
    %% Template Engine feeds into Chain Manager
    U -->|"feeds"| E
    V -->|"feeds"| E
    %% Chain Manager interactions
    E -->|"calls"| F
    E -->|"calls"| G
    E -->|"calls"| H
    E -->|"calls"| I
    E -->|"updates"| D
    %% Template Service interactions
    U -->|"manages"| J
    V -->|"manages"| J
    %% Service Layer internal connections
    F -->|"configures"| K
    F -->|"calls"| L
    F -->|"stores_data"| M
    %% External Integrations from Chain Manager
    E -->|"calls"| N
    E -->|"calls"| O
    E -->|"calls"| P
    %% Deployment pipelines deploy presentation and business logic
    R -->|"deploys"| A
    R -->|"deploys"| E
    %% Testing validates Presentation and Business Logic
    X -->|"tests"| A
    X -->|"tests"| E
    Y -->|"tests"| A
    Y -->|"tests"| E

    %% Click Events
    click A "https://github.com/ruvnet/reflective-engineer/tree/main/src/components"
    click B "https://github.com/ruvnet/reflective-engineer/tree/main/src/pages"
    click U "https://github.com/ruvnet/reflective-engineer/tree/main/public/templates"
    click V "https://github.com/ruvnet/reflective-engineer/tree/main/src/templates"
    click F "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/agentService.ts"
    click G "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/langchainService.ts"
    click H "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/langGraphService.ts"
    click I "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/openRouterService.ts"
    click J "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/templateService.ts"
    click K "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/settingsService.ts"
    click L "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/toolService.ts"
    click M "https://github.com/ruvnet/reflective-engineer/blob/main/src/services/storageService.ts"
    click N "https://github.com/ruvnet/reflective-engineer/blob/main/langchain.js"
    click Q "https://github.com/ruvnet/reflective-engineer/tree/main/Dockerfile"
    click R "https://github.com/ruvnet/reflective-engineer/tree/main/.github/workflows"
    click X "https://github.com/ruvnet/reflective-engineer/blob/main/jest.config.js"
    click Y "https://github.com/ruvnet/reflective-engineer/tree/main/src/test"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef business fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef integration fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef deployment fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef testing fill:#D8BFD8,stroke:#000,stroke-width:1px;
```
