HomeCase studiesAST-Aware Enterprise AI Coding Assistant and Patch...

Case study · San Francisco, United States

AST-Aware Enterprise AI Coding Assistant and Patch Review Platform

Developer Productivity & IDE Tooling

Generic chat interfaces drop developers into endless copy-paste loops because they lack awareness of repository symbol graphs, internal frameworks, and security boundaries. We engineered an enterprise AI coding assistant combining a TypeScript IDE and web console with a Python context orchestration engine and multi-provider LLM APIs. The system builds incremental Tree-sitter symbol indexes, routes low-latency Fill-In-the-Middle completions separately from multi-file refactorings, and enforces secret scanning and compiler verification on generated diffs.

Industry
Developer Productivity & IDE Tooling
Solution
A repository-aware AI coding assistant pairing a TypeScript developer client with a Python AST indexing backend and policy-governed LLM API gateway.
Platforms
Web & API
Stack
Python · TypeScript · LLM APIs · FastAPI · Tree-sitter · PostgreSQL
Location
San Francisco, United States · delivered remotely
Role
Engineering, with the team behind for mobile and QA

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 .env values, 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, .aiignore enforcement, 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.

01 — Questions

asked about this kind of project

Why combine Tree-sitter AST parsing with semantic embeddings instead of relying purely on naive text-chunk RAG?

Splitting code every few hundred characters cuts functions in half and misses critical type definitions imported from other modules. Tree-sitter parses exact syntactic boundaries—classes, interfaces, signatures, and call sites—so retrieved context carries complete contracts rather than broken fragments.

How does the assistant keep inline autocomplete responsive while also supporting deep multi-file refactorings?

A Python router separates traffic by intent: keystroke Fill-In-the-Middle completions target fast lightweight models with aggressive client cancellation and tight context budgets, whereas multi-file architectural edits route to higher-reasoning LLM APIs with deeper symbol-graph retrieval.

How do you prevent proprietary API keys, credentials, or restricted repositories from leaking to external LLM APIs?

Every outbound prompt payload passes through deterministic regex and entropy-based secret redaction in Python before leaving the VPC, paired with repository ACL checks and zero-data-retention enterprise LLM API agreements.

How does the platform catch hallucinated imports or broken types before developers waste time reviewing bad suggestions?

Multi-file patch proposals flow through an ephemeral validation pipeline that applies diffs in an isolated sandbox and runs repository-configured type checkers and linters, surfacing verified compiler feedback or auto-correcting errors before presenting the diff.

How are incremental code changes synced without re-indexing entire monorepos on every commit?

Git webhook diffs and local TypeScript client file watchers send only modified file hashes to FastAPI. Tree-sitter re-parses changed files and updates affected symbol-graph edges in PostgreSQL rather than rebuilding the full repository index.

How does the backend avoid rate-limit failures across multiple external LLM providers?

The Python gateway tracks per-model token buckets in Redis and applies circuit breakers with automatic provider fallback across compatible endpoints when upstream latency or HTTP 429 errors spike.

03 — Similar project?

describe what is different about yours

Build yours.

Tell me what exists, what you need and the deadline. Fixed price for a defined scope, or $55/day (8–9 hours work) with a written plan first.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.