# thomas-de-oliveira/agentkit architecture

> Architecture diagram of the GitHub repository thomas-de-oliveira/agentkit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thomas-de-oliveira/agentkit
- Repository: https://github.com/thomas-de-oliveira/agentkit

## Overview

##### Project Type & Purpose
- This is a full-stack application aimed at helping developers experiment with and build production-grade Agent apps.
- The backend provides APIs for processing agents’ actions, mediating between multiple tools (SQL, PDF ingestion, summarization, visualization, etc.), and ensuring reliability via pre-configured action plans.
- The frontend is a React/Next.js chat interface that renders streamed results, interactive UIs (like conversation views, feedback components, and authentication), and connects to backend APIs.
- The overall design emphasizes modularity (pluggable tools, configurable agents), scalability (Docker deployment, asynchronous task handling with Celery/Redis), and a clear separation between UI and service layers.

##### Analysis of the File Structure
- Top Level: Directories like “backend” and “frontend” clearly indicate a split between server-side and client-side code.
- Backend:
- Contains a detailed “app” folder with subdirectories:
▪ “api” — versioned REST API endpoints (v1) for chat, SQL queries, statistics, etc.
▪ “services” — housing the “chat_agent” with a meta agent concept, tool libraries (including implementations for SQL, PDF, image generation, summarizer, etc.), and helper modules.
▪ “config” and “core” — configuration files and core modules like FastAPI configurations, Celery integration, and database sessions (SQLDatabaseExtended, vector DB ingestion).
▪ “db” and “models” — managing database interactions, including migrations and ORM models.
- Inclusion of alembic directories shows database migration handling.
- Dockerfile and poetry configuration files indicate containerization and dependency management.
- Frontend:
- Uses Next.js with “src” containing API clients, components (conversation view, code view, dashboards, etc.), hooks, state management with stores, and global theming (tailwind/daisyUI).
- Cypress and Jest configurations for testing UI behavior.
- Configuration files (.env, Dockerfile, etc.) ensuring smooth integration with the backend.
- Deployment & DevOps:
- Docker Compose files (for demo, development, and production) provide details about how the containers come together.
- GitHub Actions workflows and pre-commit hooks for linting, tests, and CI/CD pipelines.

a. Main Components:
- Client / Frontend: Next.js user interface with modules for chat, authentication, and interactive views.
- API Gateway: Next.js API routes (and also FastAPI endpoints if both ways are used) handling incoming requests.
- Backend Service (FastAPI):
- REST API layer for endpoints (chat, SQL, statistics).
- Agent Logic: The Meta Agent that selects and routes action plans.
- Tools & Services: The library of agent tools (SQL tool, PDF ingestion tool, summarizer, etc.) and parallel action execution.
- Task Queue: Celery (with Redis as the broker) for managing long-running or asynchronous operations.
- Database Layer: Database integrations (local Postgres with pgvector, Chinook sample database) and ORM models.
- External Integrations:
- OpenAI API for LLM functionalities.
- Possibly caching/monitoring services.
- Infrastructure:
- Docker & Docker Compose for container orchestration.
- CI/CD pipelines (GitHub Actions) for linting and testing.

b. Relationships & Interactions:
- The Frontend interacts with the Backend’s REST API endpoints via HTTP/HTTPS requests.
- The FastAPI backend receives requests and uses the Meta Agent to select the proper action plan and tools.
- Asynchronous tasks (managed via Celery and brokered through Redis) are used for long-running operations.
- The backend connects to the Database for persistent storage and query operations.
- Configuration files and environment variables set the operational parameters, and external API calls (e.g., to OpenAI) are integrated in the workflow.

c. Architectural Patterns & Design Principles:
- Separation of concerns: Clear division between frontend and backend.
- Modular design: The structure supports plugging in different “tools” that the agent can execute.
- Routing and constrained decision architecture: The use of a Meta Agent combined with pre-configured action plans ensures controlled flows.
- Asynchronous task management: Use of Celery and Redis to handle non-blocking operations.
- Layered Architecture: Controllers (FastAPI endpoints) -> Services (agent tools, meta agent, business logic) -> Data Access Layer (ORM and migration scripts).

d. Key Technologies, Frameworks, & Libraries:
- Frontend: Next.js 14, React, Tailwind CSS, daisyUI.
- Backend: Python (3.10+), FastAPI, sqlmodel/pydantic, LangChain integration.
- Messaging/Task queue: Celery with Redis.
- Database: PostgreSQL (with pgvector), Chinook sample database.
- Containerization: Docker and Docker Compose.
- CI/CD: GitHub Actions workflows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        A["Client / Frontend UI"]:::frontend
        B["API Gateway (Frontend API Routes)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Services"
        D["FastAPI Backend Service (Entry & Core)"]:::backend
        C["REST API Endpoints (FastAPI)"]:::backend
        E["Meta Agent Logic"]:::backend
        F["Agent Tools & Services"]:::backend
        G["Asynchronous Task Queue (Celery)"]:::async
        H["Database Layer"]:::db
        I["Configuration Files (Backend)"]:::config
        J["External Integration (LLM/OpenAI)"]:::external
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        K["Containerization (Docker & Compose)"]:::infra
        L["CI/CD Pipelines"]:::infra
    end

    %% Connections: Frontend to Backend Flow
    A -->|"HTTP request"| B
    B -->|"routes call"| D
    D -->|"invokes"| C
    C -->|"processes request"| E
    E -->|"triggers"| F
    F -->|"queries"| H
    F -->|"calls"| J
    D -->|"enqueues task"| G
    I -->|"configures"| D

    %% Infrastructure connections
    K -->|"deploys"| A
    K -->|"deploys"| D
    L -->|"automates"| K

    %% Click Events
    click A "https://github.com/thomas-de-oliveira/agentkit/tree/main/frontend/"
    click B "https://github.com/thomas-de-oliveira/agentkit/tree/main/frontend/src/pages/api"
    click C "https://github.com/thomas-de-oliveira/agentkit/tree/main/backend/app/app/api/v1/endpoints"
    click D "https://github.com/thomas-de-oliveira/agentkit/blob/main/backend/app/app/main.py"
    click E "https://github.com/thomas-de-oliveira/agentkit/blob/main/backend/app/app/services/chat_agent/meta_agent.py"
    click F "https://github.com/thomas-de-oliveira/agentkit/tree/main/backend/app/app/services/chat_agent/tools"
    click G "https://github.com/thomas-de-oliveira/agentkit/blob/main/backend/app/app/core/celery.py"
    click H "https://github.com/thomas-de-oliveira/agentkit/tree/main/backend/app/app/db"
    click I "https://github.com/thomas-de-oliveira/agentkit/tree/main/backend/app/app/config"
    click J "https://github.com/thomas-de-oliveira/agentkit/blob/main/backend/app/app/services/chat_agent/helpers/llm.py"
    click K "https://github.com/thomas-de-oliveira/agentkit/tree/main/backend/Dockerfile"
    click L "https://github.com/thomas-de-oliveira/agentkit/tree/main/.github/workflows"

    %% Styles
    classDef frontend fill:#d0e6f7,stroke:#1d7bb8,stroke-width:2px;
    classDef backend fill:#d1f7d0,stroke:#2f7a2f,stroke-width:2px;
    classDef async fill:#ffe6b3,stroke:#ff8c00,stroke-width:2px;
    classDef db fill:#fff4b3,stroke:#d2a200,stroke-width:2px;
    classDef config fill:#e6d1f7,stroke:#8b2f7b,stroke-width:2px;
    classDef infra fill:#e0e0e0,stroke:#808080,stroke-width:2px;
    classDef external fill:#f7d1d1,stroke:#b82f2f,stroke-width:2px;
```
