Sourcebot Documentation

repository·main·Indexed 23 days ago

https://github.com/sourcebot-dev/sourcebot

A self-hosted codebase intelligence tool providing natural language querying (Ask Sourcebot), advanced code search via Zoekt, and IDE-like navigation across multiple repositories. Supports various code hosts including GitHub, GitLab, Bitbucket, and Azure DevOps, and integrates with multiple AI providers such as OpenAI, Anthropic, and Google Gemini. Includes documentation on deployment via Docker Compose, configuration using config.json, and a setup wizard via npx setup-sourcebot.

Tokens
103.9K
Snippets
157
Records
597
Agent score
87%

What's inside Sourcebot

  1. Overview of Sourcebot features

    main

    Sourcebot is a self-hosted tool for codebase understanding with the following core capabilities:

    • Ask Sourcebot: Natural language interface to ask complex questions about your code. It uses code search and navigation to provide answers with inline citations and navigable snippets.
    • Code Search: Fast search across repositories and branches supporting regular expressions, filters (repo/language), and boolean logic.
    • Code Navigation: IDE-level navigation including 'goto definition' and 'find references' across all indexed repositories.
    • Built-in File Explorer: A modern UI for exploring files with syntax highlighting, a file tree, and integrated code navigation.
  2. Understand Sources and References in Sourcebot Chat

    main

    Sourcebot chat uses two distinct concepts to ground LLM responses in the codebase:

    1. source: An artifact from the codebase (such as a file or a specific commit) used to provide context to the LLM.
    2. references: Citations or pointers to a source included in the LLM's response, allowing developers to verify the LLM's reasoning.

    Sources are attached to a chat thread via:

    • Manual @ mentions: A developer explicitly mentions a source in a prompt (e.g., "what does @auth.ts do?").
    • LLM Tool Calls: The LLM invokes a tool (e.g., readFile) during its response generation.

    References are embedded in the LLM response using a specific pattern (e.g., @file:{auth.ts:12-24}) which is then parsed and rendered via a remark plugin. Note that reference resolution is performed on a best-effort basis due to the non-deterministic nature of LLMs.

  3. Understand API and MCP Analytics metrics

    main

    API metrics track usage from non-web sources, including MCP integrations and direct API access.

    API Active Users

    Shows unique users interacting via non-web sources:

    • Any: Users who used either MCP or the API.
    • MCP: Users from IDE extensions and other MCP clients.
    • API: Users from direct HTTP API access (e.g., via API keys), excluding web app and MCP traffic.

    API Requests

    Total request counts for:

    • MCP: Code searches, file reads, tree listings, repo listings, and Ask chats from MCP clients.
    • API: Direct HTTP API requests, excluding web app and MCP traffic.
  4. Understand the Sourcebot architecture

    main

    Sourcebot is distributed as a single Docker container that manages multiple services via supervisord. The architecture consists of the following core components:

    • Web Server: A Next.js application providing the Sourcebot UI.
    • Backend Worker: A Node.js process responsible for incremental synchronization with code hosts (e.g., GitHub, GitLab) and asynchronous repository indexing.
    • Zoekt: A trigram indexing code search engine used for high-performance code search.
    • Postgres: A transactional database for business-logic data.
    • Redis Job Queue: An in-memory store using BullMQ to manage asynchronous work queues.
    • .sourcebot/ cache: A file-system cache used for persistent data storage.
  5. Understand Global Analytics metrics

    main

    Global analytics track usage across all Sourcebot interfaces (Web App, MCP, and API).

    • Active Users: The number of unique users who performed any tracked action, such as code searches, navigations, Ask chats, file views, and tree browsing.

    Note: Web repo listings are excluded from these metrics to reduce noise from passive page loads.

  6. Understand Web App Analytics metrics

    main

    Web App metrics track interactions specifically within the Sourcebot web interface.

    Web Active Users

    Shows unique users broken down by activity type:

    • All: Users who performed any web action (code searches, navigations, Ask chats, or file views), excluding repo listings.
    • Search: Users who performed code searches.
    • Ask: Users who created Ask chat sessions.

    Web Activity

    Total event counts for:

    • Code Searches: Searches performed in the web search bar.
    • Ask Chats: Conversations created through the web interface.
    • Navigations: "Go to Definition" and "Find All References" actions in the code viewer.
  7. Understand Sourcebot authentication implementation

    main

    Sourcebot uses Auth.js as its underlying authentication framework.

    Key details:

    • Providers: Supports various providers including credentials, Google, GitHub, etc.
    • Mechanism: Uses JSON Web Tokens (JWT) to provide secure and reliable user authentication information.
    • Data Privacy: Authentication data (emails, passwords, etc.) and your code remain within your deployment. If using credential login, passwords are encrypted at rest and in transit.
  8. Understand the (app) route group layout guards

    main

    The (app) route group contains routes that require authentication and membership (e.g., /search, /chat, /settings). The layout in this group acts as a gate and app shell, executing the following checks in order:

    1. Org existence: Validates the single-tenant org via SINGLE_TENANT_ORG_ID. Returns 404 if missing.
    2. Authentication: Redirects to /login (or GCP IAP auth) if the user is not logged in and anonymous access is disabled.
    3. Membership: If logged in but not a member, renders JoinOrganizationCard or SubmitJoinRequest/PendingApprovalCard based on org settings.
    4. Onboarding: Wraps children in OnboardGuard if onboarding is incomplete.
    5. SSO account linking: Renders ConnectAccountsCard if required SSO providers are not linked.
    6. Mobile splash screen: Shows an unsupported screen on mobile devices.

    Note on RBAC: The layout does not perform Role-Based Access Control (e.g., checking OWNER vs MEMBER). Use the authenticatedPage HOC with the minRole option for role-specific page access.

  9. Use Code Search features in Sourcebot

    main

    Sourcebot provides a high-performance code search engine that supports searching across multiple repositories and branches. Key capabilities include:

    • Regex support: Use regular expressions for precise code matching.
    • Query language: Use a rich query language to scope searches to specific files, repositories, languages, or symbol definitions.
    • Branch search: Search across specific lists of branches.
    • Filtering: Use the filter panel to narrow results by repository or programming language.
    • Scalability: Powered by trigram indexing to handle massive codebases efficiently.
    • Syntax Highlighting: Supports over 100+ languages.
  10. Understand the Sourcebot Monorepo Structure

    main

    Sourcebot is a Yarn 4 monorepo. Application code is located in packages/, and the Zoekt search engine is vendored in vendor/zoekt with binaries in bin/.

    Package Map

    PackageDescription
    packages/webNext.js application containing UI, API routes, auth, and the Ask agent. Core features are in src/features/, Enterprise (EE) features in src/ee/features/.
    packages/backendThe worker (Express + BullMQ) responsible for syncing connections, cloning repositories, and driving Zoekt indexing.
    packages/dbPrisma schema, migrations, and client.
    packages/schemasGenerated types and validators for the declarative config file.
    packages/queryLanguageParser for the search query language.
    packages/sharedCross-package utilities (entitlements, logger, env handling).
    packages/setupWizardThe setup-sourcebot CLI installer (available via npm).