How muhammad-hashir-code/sugar-ai works
Sugar-AI is a FastAPI coding assistant with retrieval-augmented and direct/chat generation, code debugging, API-key quotas, OAuth access, and an admin web interface. The main workflow is request authentication and routing, optional document retrieval and prompt construction, model-provider generation, then an API response. Startup configures the selected backend, initializes the RAG agent and document index, and injects the agent into API routes. Provider implementations and web/auth capabilities are represented where the README or sampled source supports them; unsampled routes are not assigned speculative call relationships.
Main entry points: main.py Startup wiring · __init__.py Provider factory · ai.py RAG and generation · auth.py Authentication
Components 22
Application entry
- Startup wiring
main.py - Runtime settings
app/config.py - AI endpoints
app/routes/api.py
AI workflow
- RAG and generation
app/ai.py - Prompt templates
app/prompts.py - Document retrieval
app/ai.py
Model providers
- Provider factory
app/providers/__init__.py - Provider interface
app/providers/base.py - Hugging Face
app/providers/huggingface.py - Ollama backend
app/providers/ollama.py - Gemini backend
app/providers/gemini.py
Identity and access
- API key store
app/database.py - Authentication
app/auth.py - Login and key requests
app/routes/auth.py - Admin controls
app/routes/admin.py
Web experience
- Web pages
app/routes/web.py - Repository webhook
app/routes/webhook.py
Other components
- API client
- OpenAI-compatible API
- Ollama service
- Gemini service
- OAuth providers
Connections 26
- API client → AI endpoints: submits request
README.md - Startup wiring → Provider factory: creates provider
main.py - Startup wiring → RAG and generation: initializes agent
main.py - Startup wiring → Document retrieval: builds index
main.py - Startup wiring → AI endpoints: injects agent
main.py - Startup wiring → Runtime settings: reads settings
main.py - Startup wiring → Authentication: syncs keys
main.py - AI endpoints → Authentication: authenticates
app/routes/api.py - AI endpoints → RAG and generation: invokes workflows
app/routes/api.py - RAG and generation → Document retrieval: searches documents
app/ai.py - RAG and generation → Prompt templates: uses templates
app/ai.py - RAG and generation → Provider interface: generates responses
app/ai.py - Provider factory → Hugging Face: selects backend
app/providers/__init__.py - Provider factory → Ollama backend: selects backend
app/providers/__init__.py - Provider factory → Gemini backend: selects backend
app/providers/__init__.py - Provider factory → Provider interface: selects backend
app/providers/__init__.py - Provider interface → OpenAI-compatible API: calls completions
app/providers/base.py - Ollama backend → Ollama service: calls model service
- Gemini backend → Gemini service: calls model service
- Authentication → API key store: checks and syncs keys
app/auth.py - Login and key requests → API key store: reads and updates
app/routes/auth.py - Login and key requests → OAuth providers: starts OAuth
app/routes/auth.py - Admin controls → Authentication: uses authentication
app/routes/admin.py - Admin controls → API key store: manages keys
app/routes/admin.py - Web pages → Authentication: uses authentication
app/routes/web.py - Repository webhook → API client: accepts repository events