Docu is an advanced, AI-powered browser extension designed to analyze complex web forms (like tax documents, visas, or legal agreements) and provide secure, context-aware explanations of individual fields directly inside the host page's DOM.
Built with scalability, security, and developer experience in mind, this project leverages a modern Turborepo Monorepo architecture, splitting the extension client and a secure Next.js API Gateway into dedicated workspaces, stitched together by a strongly-typed shared schema library.
The repository is structured as a pnpm workspace orchestrated by Turborepo. This allows atomic commits, instant shared-package resolution, and parallelized local dev environments.
apps/extension: The React-based Chrome Extension frontend (compiled via Plasmo).apps/backend: The Next.js 14 API proxy handling LLM routing and authentication.packages/shared: A centralized TypeScript library containing exact Zod schemas shared perfectly across both the extension frontend and the API backend.
Utilizing the Plasmo Framework, the extension programmatically mounts independent React roots natively into host-page DOM trees.
- We deliberately encapsulate our interactive components (like the
FormOverlayandFieldHelpPopover) inside a Shadow DOM boundary to completely immunize them against CSS-bleeding from highly styled host websites. - Employs dynamic
getBoundingClientRecttelemetry tracking to surgically anchor floating popovers directly adjacent to<input>,<select>, and<textarea>nodes regardless of the viewport scroll position.
A massive challenge in extension-LLM pipelines is context retention across stateless, serverless API routes without ballooning the Token Context Window.
- The Solution: We bypassed fragile in-memory Node caching entirely. The extension's React state securely holds the heavily compressed
FormContextsummary payload. When a user queries a specific form field, the Extension actively hydrates the API request payload with this summary locally. - The Next.js API natively compiles this into a multi-layered System Prompt, seamlessly granting lightweight models (like
anthropic/claude-3.5-haikuorgpt-4o-mini) perfect awareness of the surrounding form environment with near-zero latency, while remaining entirely serverless-friendly on platforms like Vercel.
Generative models occasionally refuse instructions for safety reasons (e.g., encountering PII fields) or append verbose conversational prose ("Here is your JSON...").
- Zod Data Validation: Every extension payload and API response is aggressively validated against the
@docu/sharedZod schema repository. If a payload violates our typing strictness, it triggers a 400 Bad Request instantly. - Surgical JSON Substring Extraction: We built a custom structural parser over the LLM generation buffers. Instead of attempting a naive
JSON.parseacross hallucinated markdown backticks or LLM apologies, the backend intelligently searches and isolates the exact{...}payload boundaries, guaranteeing a flawless extraction pipeline across OpenAI, Gemini, and OpenRouter architectures. - Factory Provider Design Pattern: The AI SDK layer natively implements an
AIProviderfactory interface. By simply switching a.envvariable, the exact same system prompts seamlessly multiplex across Google Gemini's REST API, OpenAI's SDK, or OpenRouter's proxy endpoint.
- Node.js 18+ and
pnpminstalled natively. - A Chromium-based browser (Google Chrome, Edge, Brave).
Clone the .env.example templates in both applications:
# Backend Variables
cd apps/backend
cp .env.example .env.local
# Extension Variables
cd ../extension
cp .env.example .env.developmentOpen two separate terminal windows in the root directory to run the parallel environments natively:
Terminal 1: Boot the secure Next.js API Gateway proxy
pnpm --filter backend devTerminal 2: Boot the Plasmo HMR Extension Server
pnpm --filter extension devPlasmo will automatically bundle the extension and launch an isolated Chrome browser instance natively pre-loaded with the hot-reloading extension unpacked!
Navigate to any complex form online to instantly trigger the DOM heuristics.