Core Engine
The heart of the AI Code Review platform is its background engine, built on Inngest. This architecture ensures that computationally expensive tasks like AST parsing, embedding generation, and AI analysis do not block the main application thread.
Event-Driven Workflow
Section titled “Event-Driven Workflow”The system reacts to events from GitHub and internal state changes.
Review Pipeline
Section titled “Review Pipeline”┌─────────┐ ┌─────────────┐ ┌─────────┐ ┌────────┐ ┌─────────┐│ GitHub │ ──► │ Webhook API │ ──► │ Inngest │ ──► │ Worker │ ──► │ GitHub │└─────────┘ └─────────────┘ └─────────┘ └────────┘ └─────────┘┌─────────┐ ┌────────────────┐ ┌────────────────┐│ PR Diff │───►│ Embedding │───►│ Vector Search │└─────────┘ │ Generation │ │ (pgvector) │ └────────────────┘ └────────────────┘ │ ▼┌────────────────┐ ┌────────────────┐ ┌────────────────┐│ Gemini Review │◄───│ Prompt Builder │◄───│ Relevant Code ││ Generation │ └────────────────┘ │ Context │└────────────────┘ └────────────────┘Worker Responsibilities
• Fetch PR Diff• Generate Query Embedding• Search Similar Code Chunks• Retrieve Context• Build Prompt• Generate AI Review• Save Review• Post GitHub CommentBackground Job Structure
Section titled “Background Job Structure”Jobs are organized into modular functions within the inngest/functions directory.
Directoryinngest/
- client.ts (Inngest client config)
Directoryfunctions/
- index.ts (Repository indexing logic)
- review.ts (PR analysis & AI review)
Indexing Engine
Section titled “Indexing Engine”When a repository is first connected, the index-repo function performs a full scan:
- Incremental Diff Analysis: Uses the GitHub API to identify changed files since the last indexed commit.
- AST Chunking: Employs Tree-sitter to parse source code into semantic chunks (functions, classes).
- Embedding Generation: Chunks are sent to the
gemini-embedding-001model to generate 768-dimensional vectors. - Vector Persistence: Chunks and their embeddings are stored in PostgreSQL using the
vectortype.
Review Engine
Section titled “Review Engine”Triggered on every PR, this function implements a RAG (Retrieval-Augmented Generation) pipeline:
- Context Retrieval: The PR diff is used as a query to find the most relevant chunks from the indexed repository.
- Prompt Engineering: A complex prompt is constructed combining the PR diff, retrieved context, and specific review instructions.
- AI Generation: Uses Gemini 2.0 Flash to generate a structured review, including a Mermaid sequence diagram of the changes.
- GitHub Integration: The final review is posted back to GitHub as a single, comprehensive comment.