# mr-aicoder/repopilot architecture

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

- Interactive diagram: https://gitdiagram.com/mr-aicoder/repopilot
- Repository: https://github.com/mr-aicoder/repopilot

## Overview

##### Project type and purpose
- RepoPilot is a monolithic, single-page web application built with Streamlit.
- Its purpose is to provide an AI-powered assistant for interacting with GitHub repositories: loading a repo, performing semantic search over its contents (RAG), visualizing file trees, debugging code, and generating snippets.
- It integrates with external services: GitHub REST API for repo content, a Groq LLM API for chat and code generation, and a Chroma vector store (backed by sqlite3) for embedding-based retrieval.

##### File structure
- Top-level files:
- .devcontainer/devcontainer.json – VS Code dev container configuration (development environment).
- README.md – project overview, feature list, installation & deployment steps.
- app.py – the entire Streamlit application (UI + backend logic).
- requirements.txt – Python dependencies (Streamlit, LangChain, Chroma, sentence-transformers, etc.).
- No separate “frontend” or “backend” directories—everything lives in app.py.
- Configuration and secrets are managed via .env (GROQ_API_KEY, GITHUB_TOKEN) and Streamlit Cloud secrets.

##### README for additional insights
- System components described:
- Streamlit UI (two columns: chat/repo overview & debugging/generation).
- Vector store using Chroma (with sqlite3 workaround).
- LLM calls to Groq.
- GitHub repository fetch & semantic chunking (LangChain embeddings).
- Deployment notes emphasize pysqlite3 hack for Streamlit Cloud.

a. Main components
- Client Browser (user)
- Streamlit App (app.py)
- UI Layer: two-column layout
- Controller/Business Logic:
· GitHub Integration Module
· Document Loader + Chunking
· Embeddings & Vector Store (Chroma + sqlite3)
· Query Handler for semantic search
· Debugging / Code Generation Handler
- Service Adapters:
· Groq LLM API
· GitHub REST API
- Vector Store (Chroma DB backed by sqlite3)
- External Services:
- Groq API
- GitHub API
- Development Environment (.devcontainer)
- .env / Secrets Store

b. Relationships & interactions
1. User interacts with the Streamlit UI via browser.
2. Streamlit UI invokes functions in app.py.
3. On “Load Repo”:
– App retrieves files from GitHub API → LangChain document loader → chunks → embeddings → stored in Chroma.
4. On “Ask Question”:
– Query Handler performs semantic search on Chroma → returns top chunks → sends prompt + context to Groq LLM API → receives response → displays in UI.
5. On “Debug / Generate Code”:
– Takes error snippet or request → context lookup in vector store or file tree → crafts prompt → calls Groq API → displays solution.
6. App persists vector store in sqlite3 via pysqlite3 shim.

c. Architectural patterns & design principles
- Monolithic single-process server (Streamlit) with clear logical separation inside a single file.
- Retrieval-Augmented Generation (RAG) pattern: Combine vector store search with LLM.
- Adapter pattern for external services (GitHub, Groq).
- Two-column UI pattern for parallel workflows (overview vs debugging).

d. Key technologies & libraries
- Streamlit – web UI framework
- LangChain – document loading, embeddings orchestration
- sentence-transformers – embedding models
- Chroma – vector database
- Groq API – LLM
- GitHub REST API – repository retrieval
- pysqlite3 – sqlite backend workaround

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client"
        Browser["Client Browser"]:::client
    end

    subgraph "Server: Streamlit App"
        UI["Streamlit UI Layer"]:::ui
        Controller["Controller & Business Logic"]:::logic

        subgraph "Modules"
            GHInt["GitHub Integration Module"]:::logic
            DocLoad["Document Loader & Chunking"]:::logic
            EmbStore["Embeddings & Vector Store"]:::logic
            QueryHandler["Semantic Query Handler"]:::logic
            DebugHandler["Debugging / Code Generation Handler"]:::logic
        end

        subgraph "Service Adapters"
            GroqAdapter["Groq LLM API Adapter"]:::external
            GitHubAdapter["GitHub REST API Adapter"]:::external
        end
    end

    VectorStore[("Chroma Vector Store\n(sqlite3)")]:::db
    GroqAPI(("Groq LLM API")):::cloud
    GitHubAPI(("GitHub REST API")):::cloud
    Env["Env & Config (.env, Secrets)"]:::config
    DevEnv["Development Environment\n(.devcontainer/devcontainer.json)"]:::config
    Docs["README.md\nrequirements.txt"]:::docs

    Browser -->|"interacts with"| UI
    UI -->|"triggers"| Controller

    Controller --> GHInt
    Controller --> DocLoad
    Controller --> QueryHandler
    Controller --> DebugHandler

    GHInt -->|"uses"| GitHubAdapter
    GitHubAdapter -->|"calls"| GitHubAPI

    DocLoad --> EmbStore
    EmbStore --> VectorStore

    QueryHandler --> VectorStore
    QueryHandler -->|"prompts"| GroqAdapter
    GroqAdapter -->|"requests"| GroqAPI

    DebugHandler --> VectorStore
    DebugHandler -->|"requests"| GroqAdapter

    Env -.-> UI
    Env -.-> Controller

    DevEnv -.-> Controller
    Docs -.-> Controller

    click UI "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click Controller "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click GHInt "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click DocLoad "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click EmbStore "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click QueryHandler "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click DebugHandler "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click GroqAdapter "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click GitHubAdapter "https://github.com/mr-aicoder/repopilot/blob/main/app.py"
    click DevEnv "https://github.com/mr-aicoder/repopilot/blob/main/.devcontainer/devcontainer.json"
    click Docs "https://github.com/mr-aicoder/repopilot/blob/main/README.md"
    click Docs "https://github.com/mr-aicoder/repopilot/blob/main/requirements.txt"

    classDef client fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef ui fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef logic fill:#A9DFBF,stroke:#145A32,color:#1B2631
    classDef external fill:#F9E79F,stroke:#7D6608,color:#1B2631
    classDef db fill:#D2B4DE,stroke:#512E5F,color:#1B2631
    classDef cloud fill:#F5B7B1,stroke:#943126,color:#1B2631
    classDef config fill:#FAD7A0,stroke:#B9770E,color:#1B2631
    classDef docs fill:#E5E8E8,stroke:#566573,color:#1B2631
```
