Skip to content
ryan7626Public

About

AI browser extension that explains complex web forms field by field. Turborepo monorepo, Plasmo, Next.js API gateway.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

📄 Docu: Intelligent Form Assistant Extension

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.


🏗 System Architecture & Technical Highlights

1. Robust Monorepo Workspace (Turborepo + pnpm)

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.

2. Isolated React UI Injection (Shadow DOM)

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 FormOverlay and FieldHelpPopover) inside a Shadow DOM boundary to completely immunize them against CSS-bleeding from highly styled host websites.
  • Employs dynamic getBoundingClientRect telemetry tracking to surgically anchor floating popovers directly adjacent to <input>, <select>, and <textarea> nodes regardless of the viewport scroll position.

3. Serverless "Client-Hydrated" Context Architecture

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 FormContext summary 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-haiku or gpt-4o-mini) perfect awareness of the surrounding form environment with near-zero latency, while remaining entirely serverless-friendly on platforms like Vercel.

4. Strict Data Contracts & Bypassing LLM Hallucinations

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/shared Zod 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.parse across 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 AIProvider factory interface. By simply switching a .env variable, the exact same system prompts seamlessly multiplex across Google Gemini's REST API, OpenAI's SDK, or OpenRouter's proxy endpoint.

🚀 Getting Started Locally

Prerequisites

  • Node.js 18+ and pnpm installed natively.
  • A Chromium-based browser (Google Chrome, Edge, Brave).

1. Setup Environment Variables

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.development

2. Boot the Development Servers

Open 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 dev

Terminal 2: Boot the Plasmo HMR Extension Server

pnpm --filter extension dev

Plasmo 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.

About

AI browser extension that explains complex web forms field by field. Turborepo monorepo, Plasmo, Next.js API gateway.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages