How sweepai/sweep works
Project Type and Purpose
• Sweep is a multi-component AI coding assistant. It provides:
• A core Python library (sweepai/) implementing agents, handlers, CLI commands, and a lightweight web API for GitHub events and health checks.
• A Next.js-based frontend (sweep_chat/) for interactive chat in the browser.
• A published JetBrains plugin that wraps these services for in-IDE assistance.
• Documentation and SDK layers under docs/ and docs/sdk/.
Top-Level Architecture Components
a. Core Python Service
• sweepai/cli.py: Command-line interface entry point.
• sweepai/web/health.py, sweepai/web/events.py: FastAPI (or similar) endpoints for GitHub webhooks and health checks.
• sweepai/handlers/: Event handlers for GitHub events (PR comments, merges, checks).
• sweepai/core/, sweepai/agents/: Agent logic, prompt orchestration, context pruning, vector DB integration (sweepai/core/vector_db.py).
• sweepai/utils/: Shared utilities (OpenAI, Anthropic, GitHub clients, streaming, logging).
• External dependencies: OpenAI API, Anthropic API, Cohere, JIRA, Redis vector store.
b. Frontend Chat UI
• sweep_chat/: Next.js app
• app/ folder: Routes for chat pages and API proxies (app/api/auth, etc.).
• components/: UI primitives, chat components, code editors, loaders.
• lib/: Shared authentication, streaming helpers, constants.
• public/: Static assets.
• E2E test harness: Cypress configuration under sweep_chat/cypress/.
• Authentication: NextAuth integration for user sessions.
c. Documentation and SDK
• docs/: Static site files (MDX) and React components to power the documentation portal.
• docs/sdk/: A Python SDK publishing wrapper over core services (PyPI packaging).
d. Deployment and Operations
• Dockerfile + docker-compose.yml
• bin/ scripts for install, deploy, redeploy on server.
• GitHub Actions workflows for testing, linting, and PyPI publishing.
Relationships & Data Flow
• The JetBrains plugin and CLI both call the core Python service (via HTTP or direct imports) to process requests.
• The core service:
1. Receives a request (CLI command or GitHub webhook).
2. The handler selects an agent, constructs prompts, consults the vector DB, and invokes LLM APIs.
3. Returns suggestions or posts comments back to GitHub via its API.
• The Next.js frontend communicates with the core service through REST or WebSocket endpoints (streaming code suggestions).
• Redis (vector_db) sits alongside the core service for embedding storage and retrieval.
Architectural Patterns & Principles
• Modular layering: CLI, handlers, core logic, utilities all separated by responsibility.
• Event-driven design: GitHub webhooks → handlers → agents.
• Adapter pattern for LLM providers (openai_proxy, anthropic_client, cohere_utils).
• Single-page application for UI, decoupled from backend.
• Dockerized micro-deployments.
• Rounded rectangles for services