# manvitha-kopela/sugar-ai architecture

> Architecture diagram of the GitHub repository manvitha-kopela/sugar-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/manvitha-kopela/sugar-ai
- Repository: https://github.com/manvitha-kopela/sugar-ai

## Overview

Sugar-AI is a FastAPI coding assistant. Users submit questions or code to API endpoints; the API delegates RAG, direct-prompt, chat, or debugging work to an initialized agent and returns generated answers. The app also supports API-key and OAuth access, key requests and administration, plus an optional repository-update webhook. The graph preserves the documented endpoint modes and provider choices; some routes and provider implementations were not sampled, so only documented or indexed relationships are shown.

Main entry points: [`main.py`](https://github.com/manvitha-kopela/sugar-ai/blob/main/main.py) (Startup initialization), [`app/ai.py`](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/ai.py) (RAG and generation), [`app/providers/base.py`](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/base.py) (Provider interface), [`app/providers/__init__.py`](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/__init__.py) (Provider factory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web and access"]
  node_api["Assistant API<br/>[api.py]"]
  node_admin["Admin routes<br/>[admin.py]"]
  node_authroutes["Login and keys<br/>[auth.py]"]
  node_webpages["Web pages<br/>[web.py]"]
  node_templates["HTML templates"]
  node_access["API-key and OAuth access<br/>[auth.py]"]
  node_webhook["Repository webhook<br/>[webhook.py]"]
end

subgraph group_assistant["Assistant workflow"]
  node_agent["RAG and generation<br/>[ai.py]"]
  node_retrieval[("Document retrieval<br/>[ai.py]")]
  node_prompts["Prompt templates<br/>[prompts.py]"]
  node_docs["Sugar documentation"]
end

subgraph group_providers["Model providers"]
  node_factory["Provider factory<br/>[__init__.py]"]
  node_providerbase["Provider interface<br/>[base.py]"]
  node_huggingface["Hugging Face<br/>[huggingface.py]"]
  node_ollama["Ollama<br/>[ollama.py]"]
  node_gemini["Gemini<br/>[gemini.py]"]
end

subgraph group_platform["Application platform"]
  node_database[("API-key database<br/>[database.py]")]
  node_config["Runtime settings<br/>[config.py]"]
  node_application["FastAPI application<br/>[__init__.py]"]
  node_startup["Startup initialization<br/>[main.py]"]
end

node_user(("API user"))
node_browser(("Browser user"))
node_github(("GitHub webhook"))
node_openai["OpenAI-compatible API"]

node_user -->|"submits requests"| node_api
node_api -->|"runs workflows"| node_agent
node_agent -->|"retrieves documents"| node_retrieval
node_retrieval -.->|"indexes documentation"| node_docs
node_agent -->|"uses templates"| node_prompts
node_agent -->|"generates with"| node_providerbase
node_startup -->|"creates app"| node_application
node_startup -->|"selects provider"| node_factory
node_startup -->|"initializes agent"| node_agent
node_startup -->|"loads keys"| node_database
node_startup -->|"reads settings"| node_config
node_startup -->|"injects agent"| node_api
node_factory -->|"creates provider"| node_huggingface
node_factory -->|"creates provider"| node_ollama
node_factory -->|"creates provider"| node_gemini
node_huggingface -->|"implements interface"| node_providerbase
node_ollama -->|"implements interface"| node_providerbase
node_gemini -->|"implements interface"| node_providerbase
node_providerbase -->|"calls completions"| node_openai
node_browser -.->|"opens pages"| node_webpages
node_webpages -->|"renders pages"| node_templates
node_browser -.->|"uses login forms"| node_authroutes
node_authroutes -->|"uses OAuth helpers"| node_access
node_access -->|"queries keys"| node_database
node_admin -->|"manages keys"| node_database
node_api -->|"verifies keys"| node_access
node_application -->|"sets up OAuth"| node_access
node_application -->|"creates tables"| node_database
node_github -->|"posts updates"| node_webhook

click node_api "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/api.py"
click node_admin "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/admin.py"
click node_authroutes "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/auth.py"
click node_webpages "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/web.py"
click node_templates "https://github.com/manvitha-kopela/sugar-ai/tree/main/templates"
click node_access "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/auth.py"
click node_webhook "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/webhook.py"
click node_agent "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/ai.py"
click node_retrieval "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/ai.py"
click node_prompts "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/prompts.py"
click node_docs "https://github.com/manvitha-kopela/sugar-ai/tree/main/docs"
click node_factory "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/__init__.py"
click node_providerbase "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/base.py"
click node_huggingface "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/huggingface.py"
click node_ollama "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/ollama.py"
click node_gemini "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/gemini.py"
click node_database "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/database.py"
click node_config "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/config.py"
click node_application "https://github.com/manvitha-kopela/sugar-ai/blob/main/app/__init__.py"
click node_startup "https://github.com/manvitha-kopela/sugar-ai/blob/main/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_admin,node_authroutes,node_webpages,node_templates,node_access,node_webhook,node_user,node_browser toneBlue
class node_agent,node_retrieval,node_prompts,node_docs toneAmber
class node_factory,node_providerbase,node_huggingface,node_ollama,node_gemini,node_github,node_openai toneMint
class node_database,node_config,node_application,node_startup toneRose
```

## Components

### Web and access

- [Assistant API](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/api.py): `app/routes/api.py`
- [Admin routes](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/admin.py): `app/routes/admin.py`
- [Login and keys](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/auth.py): `app/routes/auth.py`
- [Web pages](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/web.py): `app/routes/web.py`
- [HTML templates](https://github.com/manvitha-kopela/sugar-ai/tree/main/templates): `templates`
- [API-key and OAuth access](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/auth.py): `app/auth.py`
- [Repository webhook](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/routes/webhook.py): `app/routes/webhook.py`

### Assistant workflow

- [RAG and generation](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/ai.py): `app/ai.py`
- [Document retrieval](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/ai.py): `app/ai.py`
- [Prompt templates](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/prompts.py): `app/prompts.py`
- [Sugar documentation](https://github.com/manvitha-kopela/sugar-ai/tree/main/docs): `docs`

### Model providers

- [Provider factory](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/__init__.py): `app/providers/__init__.py`
- [Provider interface](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/base.py): `app/providers/base.py`
- [Hugging Face](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/huggingface.py): `app/providers/huggingface.py`
- [Ollama](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/ollama.py): `app/providers/ollama.py`
- [Gemini](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/providers/gemini.py): `app/providers/gemini.py`

### Application platform

- [API-key database](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/database.py): `app/database.py`
- [Runtime settings](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/config.py): `app/config.py`
- [FastAPI application](https://github.com/manvitha-kopela/sugar-ai/blob/main/app/__init__.py): `app/__init__.py`
- [Startup initialization](https://github.com/manvitha-kopela/sugar-ai/blob/main/main.py): `main.py`

### Other components

- **API user**
- **Browser user**
- **GitHub webhook**
- **OpenAI-compatible API**

## Connections

- API user → Assistant API: submits requests (evidence: `README.md`)
- Assistant API → RAG and generation: runs workflows (evidence: `app/routes/api.py`)
- RAG and generation → Document retrieval: retrieves documents (evidence: `app/ai.py`)
- Document retrieval → Sugar documentation: indexes documentation (evidence: `README.md`)
- RAG and generation → Prompt templates: uses templates (evidence: `app/ai.py`)
- RAG and generation → Provider interface: generates with (evidence: `app/ai.py`)
- Startup initialization → FastAPI application: creates app (evidence: `main.py`)
- Startup initialization → Provider factory: selects provider (evidence: `main.py`)
- Startup initialization → RAG and generation: initializes agent (evidence: `main.py`)
- Startup initialization → API-key database: loads keys (evidence: `main.py`)
- Startup initialization → Runtime settings: reads settings (evidence: `main.py`)
- Startup initialization → Assistant API: injects agent (evidence: `main.py`)
- Provider factory → Hugging Face: creates provider (evidence: `app/providers/__init__.py`)
- Provider factory → Ollama: creates provider (evidence: `app/providers/__init__.py`)
- Provider factory → Gemini: creates provider (evidence: `app/providers/__init__.py`)
- Hugging Face → Provider interface: implements interface (evidence: `app/providers/huggingface.py`)
- Ollama → Provider interface: implements interface (evidence: `app/providers/ollama.py`)
- Gemini → Provider interface: implements interface (evidence: `app/providers/gemini.py`)
- Provider interface → OpenAI-compatible API: calls completions (evidence: `app/providers/base.py`)
- Browser user → Web pages: opens pages (evidence: `README.md`)
- Web pages → HTML templates: renders pages (evidence: `app/routes/web.py`)
- Browser user → Login and keys: uses login forms (evidence: `README.md`)
- Login and keys → API-key and OAuth access: uses OAuth helpers (evidence: `app/routes/auth.py`)
- API-key and OAuth access → API-key database: queries keys (evidence: `app/auth.py`)
- Admin routes → API-key database: manages keys (evidence: `app/routes/admin.py`)
- Assistant API → API-key and OAuth access: verifies keys (evidence: `app/routes/api.py`)
- FastAPI application → API-key and OAuth access: sets up OAuth (evidence: `app/__init__.py`)
- FastAPI application → API-key database: creates tables (evidence: `app/__init__.py`)
- GitHub webhook → Repository webhook: posts updates (evidence: `app/routes/webhook.py`)
