# petercat-ai/petercat architecture

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

- Interactive diagram: https://gitdiagram.com/petercat-ai/petercat
- Repository: https://github.com/petercat-ai/petercat

## Overview

##### Main Components Identification

a) Frontend Layer:
- Client (Next.js web application)
- Assistant (React component library)
- Extension (Browser extension)

b) Backend Layer:
- Server (FastAPI application)
- Agent System
- RAG (Retrieval-Augmented Generation) System

c) External Services:
- AWS Services (Lambda, S3, SQS, CloudFront)
- Supabase (Database)
- Auth0 (Authentication)
- LLM Services (OpenAI, Gemini)
- GitHub API

**┌─ Client Zone ─────────────┐  ┌─ External Services ─┐**
- Web Client              │  │ - Auth0            │
- Assistant Component     │  │ - GitHub           │
- Browser Extension       │  │ - LLM Providers    │
- ┘  └──────────────────────┘
- ↕                            ↕
**┌─ Server Zone ──────────────────────────────────────┐**
- ┌─ API Layer ─────────┐  ┌─ Agent System ────────┐ │
- FastAPI           │  │ - Bot Builder        │ │
- Auth Middleware   │  │ - QA Chat            │ │
- Rate Limiting     │  │ - Knowledge Base     │ │
- ┘  └────────────────────┘ │
- ┌─ Infrastructure ────────────────────────────────┐│
- AWS Lambda/S3/SQS                            ││
- Supabase Database                            ││
- ┘ │
- ┘

##### Connection Types

Different types of connections with distinct line styles:
- Double lines: Authentication flow

##### Key Features to Highlight

- Bot Creation Workflow
- Knowledge Base Construction
- Multi-platform Integration
- Authentication Flow
- Task Queue System
- RAG Pipeline

##### Additional Elements

Supporting elements:
- Version information
- Security boundaries
- Scaling components
- Data flow direction indicators

##### Implementation Details

- How the bot creation process flows from user input through the agent system
- Knowledge base construction pipeline (load -> split -> embed -> store)
- Integration points with GitHub (Apps, API)
- Authentication flow with Auth0
- Task distribution through AWS SQS
- Storage management with S3 and Supabase

##### Documentation

Annotations for:
- Environment configurations
- Service dependencies
- Scaling considerations
- Security measures
- Integration points

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white

    %% Frontend Layer
    subgraph Frontend
        Client["Next.js Client"]:::frontend
        Assistant["Assistant Component"]:::frontend
        Extension["Browser Extension"]:::frontend
    end

    %% Backend Layer
    subgraph Server
        subgraph APILayer
            FastAPI["FastAPI Server"]:::backend
            AuthMiddleware["Auth Middleware"]:::security
            RateLimit["Rate Limiting"]:::security
        end

        subgraph AgentSystem
            BotBuilder["Bot Builder"]:::backend
            QAChat["Chat System"]:::backend
            KnowledgeBase["Knowledge Base"]:::backend
        end

        subgraph RAGSystem
            RAGPipeline["RAG Pipeline"]:::backend
            RAGUtils["RAG Utils"]:::backend
        end
    end

    %% External Services
    subgraph ExternalServices
        Auth0["Auth0"]:::external
        GitHub["GitHub API"]:::external
        LLM["LLM Services"]:::external
    end

    %% Infrastructure
    subgraph Infrastructure
        AWS["AWS Services"]:::backend
        Supabase["Supabase DB"]:::database
    end

    %% Connections
    Client --> FastAPI
    Assistant --> FastAPI
    Extension --> FastAPI
    FastAPI --> AuthMiddleware
    AuthMiddleware --> Auth0
    FastAPI --> BotBuilder
    FastAPI --> QAChat
    BotBuilder --> RAGPipeline
    RAGPipeline --> RAGUtils
    RAGPipeline --> Supabase
    QAChat --> KnowledgeBase
    KnowledgeBase --> LLM
    FastAPI --> GitHub
    BotBuilder --> AWS
    RAGPipeline --> AWS

    %% Click Events
    click Client "https://github.com/petercat-ai/petercat/tree/main/client"
    click Assistant "https://github.com/petercat-ai/petercat/tree/main/assistant"
    click Extension "https://github.com/petercat-ai/petercat/tree/main/extension"
    click FastAPI "https://github.com/petercat-ai/petercat/tree/main/server"
    click BotBuilder "https://github.com/petercat-ai/petercat/blob/main/server/agent/bot/bot_builder.py"
    click RAGPipeline "https://github.com/petercat-ai/petercat/tree/main/server/rag"
    click RAGUtils "https://github.com/petercat-ai/petercat/tree/main/petercat_utils/rag_helper"
    click AuthMiddleware "https://github.com/petercat-ai/petercat/tree/main/server/auth"
    click Auth0 "https://github.com/petercat-ai/petercat/blob/main/server/auth/clients/auth0.py"
    click Supabase "https://github.com/petercat-ai/petercat/tree/main/server/core/dao"
    click AWS "https://github.com/petercat-ai/petercat/tree/main/server/aws"
    click LLM "https://github.com/petercat-ai/petercat/tree/main/server/agent/llm/clients"
    click GitHub "https://github.com/petercat-ai/petercat/tree/main/server/github_app"
    click QAChat "https://github.com/petercat-ai/petercat/tree/main/server/chat"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend"]:::backend
        External_L["External"]:::external
        Database_L["Database"]:::database
        Security_L["Security"]:::security
    end
```
