Delivered remotely for a business based in San Francisco, United States. Names withheld by agreement.
Project Overview
Off-the-shelf chat assistants routinely slow senior engineering teams down when applied to large proprietary codebases: unfamiliar with private monorepo conventions, they invent nonexistent helper signatures, ignore cross-module type contracts, and force engineers to verify every snippet manually. Worse, pasting proprietary source trees into unmanaged consumer endpoints creates immediate intellectual-property and credential-leakage exposure.
We engineered an enterprise AI coding assistant integrating a TypeScript developer workbench and editor client with a Python orchestration backend and governed LLM APIs. The platform indexes repositories structurally with Tree-sitter, tailors context retrieval separately for inline completions versus multi-file diffs, and validates generated changes against real language tooling before developers accept a patch.
Developer Tooling & Context Bottlenecks
Building a dependable coding companion for complex polyglot repositories exposed failure modes that general-purpose chatbot architectures miss:
- Broken chunk boundaries: Standard document splitters slice classes and type declarations arbitrarily, depriving the model of parameter shapes and return contracts when synthesizing callers.
- Competing latency expectations: Engineers expect ghost-text autocomplete to appear nearly instantaneously as they type, whereas deliberate multi-file migrations tolerate longer reasoning passes if accuracy is high.
- Hallucinated APIs and silent regressions: Unverified diffs often compile mentally in prose yet fail immediately on strict TypeScript compiler checks or Python type annotations.
- Shadow credential exposure: Local
.envvalues, test fixtures, and hardcoded tokens inside open editor tabs risk leaking into external model prompts without automated pre-egress scrubbing.
Architectural Strategy
We built the platform around a syntax-first context compiler paired with a dual-tier LLM API gateway. Rather than treating source files as flat text blobs, Python indexing workers parse repositories using Tree-sitter grammars to extract clean AST nodes—symbols, docstrings, import edges, and cross-file references—stored in PostgreSQL.
At inference time, the TypeScript client streams cursor coordinates, open-tab metadata, and git diff context to FastAPI. Lightweight Fill-In-the-Middle (FIM) requests assemble compact prefix/suffix windows plus immediate imported signatures cached in Redis, while complex refactorings trigger multi-hop symbol graph traversal and optional sandbox verification before returning structured unified diffs.
Core Capabilities
- AST-Driven Repository Indexing: Incremental Tree-sitter parsing tracks classes, functions, interfaces, and dependency edges across Python, TypeScript, and companion languages on every push or local save.
- Dual-Tier Completion & Diff Routing: Separates sub-second FIM inline code suggestions from multi-file conversational editing and test-generation workflows.
- Pre-Egress Secret & Policy Guardrails: Redacts high-entropy strings, private keys, and restricted file paths in Python prior to invoking external LLM APIs, backed by organization-scoped audit logs.
- Automated Patch Verification: Runs configured linters, type checkers, and targeted test commands on proposed diffs in isolated sandboxes, attaching diagnostics directly inside the TypeScript review UI.
- Unified Web & IDE Review Surface: TypeScript diff viewer and conversational workspace supporting side-by-side hunk inspection, selective patch application, and prompt-template governance.
Technical Architecture
TypeScript clients debounce editor keystrokes or submit structured refactoring prompts to FastAPI, attaching an explicit cancellation token so stale typing bursts abort immediately. Python resolves user repository ACLs, queries PostgreSQL and Redis for relevant AST definitions and imported contracts, scrubs sensitive patterns, and dispatches requests through a resilient LLM API router. For multi-file edits, generated patches route through an optional sandbox check before streaming validated diff hunks back to the client.
Flow: TypeScript IDE & Web Workbench → FastAPI Context Router (Cancellation & ACLs) → Tree-sitter AST Index + Redis Hot Snippet Cache → Pre-Egress Secret Scrubber → Tiered LLM API Gateway → Sandbox Type/Lint Verifier → Streamed Unified Diff
Separating the deterministic Python context engine from specific LLM vendor SDKs enables platform teams to swap frontier reasoning models or fast FIM endpoints centrally via configuration without pushing client updates to every engineer's workstation.
Technology Stack
| Category | Technology detail |
|---|---|
| Developer Client | TypeScript powering the web diff workbench and IDE language client |
| Orchestration Backend | Python and FastAPI managing context assembly, prompt routing, and auth |
| Code Parsing & AST | Tree-sitter grammars extracting symbol definitions, imports, and call graphs |
| Model Gateway | Multi-provider LLM API router supporting FIM completion and reasoning tiers |
| Metadata & Index DB | PostgreSQL with vector indexes storing symbol graphs and repo permissions |
| Context & Rate Cache | Redis caching hot AST snippets, token budgets, and debounce state |
| Verification Sandbox | Isolated runner executing linters, type checks, and unit test subsets on patches |
| Security & Telemetry | Pre-egress secret scanners and structured audit logs for compliance teams |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Maintaining fresh symbol context in massive monorepos | Combined baseline PostgreSQL AST indexes synced via git webhooks with ephemeral overlay parsing for unsaved client buffers; adds merge complexity while avoiding stale editor suggestions. |
| Controlling LLM API token costs during verbose multi-file sessions | Applied AST signature compression—sending full bodies for target files and interface/docstring stubs for distant dependencies; trades minor cross-file body detail for sharp token efficiency. |
| Preventing stale autocomplete calls from saturating upstream quotas | Enforced strict client debouncing paired with HTTP request-abort propagation into FastAPI and Redis concurrency limits; drops superseded prompts early to protect API capacity. |
| Avoiding unsafe execution when verifying AI-generated patches | Ran type checks and linters inside network-isolated ephemeral containers with read-only base mounts; adds container startup latency while isolating untrusted code generation. |
Security & Reliability
Enterprise engineering organizations require verifiable guarantees over how source code traverses third-party LLM APIs. Repository permissions synchronize from source-control providers so developers only retrieve AST snippets from repositories they are authorized to read, preventing cross-team leakage via shared semantic indexes.
Before any prompt exits FastAPI, a Python redaction layer strips matched credential patterns and honors repository .aiignore rules covering sensitive directories. Outbound LLM API traffic routes exclusively through contracted zero-retention enterprise endpoints, while Redis-backed circuit breakers gracefully fall back across secondary model deployments if a primary provider degrades.
Performance & Scale
Inline developer tooling lives or dies on perceived snappiness. The TypeScript client maintains a lightweight local cache of recent cursor contexts and cancels in-flight FIM requests the instant another keystroke arrives, preventing wasted GPU inference upstream. On the backend, Redis caches parsed file AST summaries and frequently imported internal SDK headers so context assembly resolves in memory without hitting disk.
For heavy batch workflows—such as migrating deprecated framework calls across dozens of services—asynchronous worker queues pace requests against per-provider rate budgets in Redis, ensuring background refactors never degrade interactive editor responsiveness.
Operational Outcomes
Integrating AST-aware context assembly with policy-controlled LLM APIs shifted AI coding adoption from ad-hoc personal scripts to a trusted team engineering layer:
- Higher first-pass code compatibility: Grounding prompts in real Tree-sitter symbol contracts sharply reduces invented imports and mismatched signatures across internal libraries.
- Confident enterprise governance: Pre-egress secret scrubbing,
.aiignoreenforcement, and zero-retention API routing satisfy security review boards without blocking developer velocity. - Streamlined review workflows: Sandbox-checked diffs highlight compiler and lint compliance upfront so engineers spend review cycles evaluating architecture rather than chasing syntax typos.
- Vendor-agnostic model agility: Platform administrators adopt stronger or faster LLM APIs behind a single Python gateway without disrupting developer client tooling.