Skip to content

Latest commit

 

History

History
62 lines (48 loc) · 3.28 KB

architecture-overview.md

File metadata and controls

62 lines (48 loc) · 3.28 KB

Architecture Documentation

Overview

Brompt is a client-side Single Page Application (SPA) built with Next.js. It focuses on privacy and efficiency, using local storage for data persistence and direct client-to-API communication for AI operations.

Core Principles

  1. Privacy First: No backend server for data storage. All user data (history, settings, drafts) lives in the browser's localStorage.
  2. Schema-Driven UI: The form engine dynamically renders components based on JSON schemas generated by the LLM.
  3. Client-Side Orchestration: The application logic resides entirely in the frontend, orchestrating the flow between the user and the LLM.
  4. Multi-Provider Support: Supports OpenAI, Anthropic, Gemini, Mistral, and Groq via Vercel AI SDK.

Tech Stack

  • Framework: Next.js 15 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • State Management: React Context + Hooks
  • AI Provider: Vercel AI SDK (supporting OpenAI, Anthropic, Gemini, Mistral, Groq)
  • Icons: Lucide React

Data Flow

  1. User Input (Seed): User provides an initial goal (e.g., "I want to write a blog post").
  2. LLM Processing (Analysis): The app sends this goal to the selected LLM provider.
  3. Schema Generation: The LLM returns a JSON schema defining the next set of questions (fields).
  4. Dynamic Rendering: PromptFormEngine parses the schema and renders appropriate UI components (Text, Select, Slider, etc.).
  5. User Response: User fills out the form.
  6. Loop: Steps 2-5 repeat for up to 10 rounds or until the user finishes.
  7. Final Generation: The app sends the entire conversation history to the LLM to generate the final optimized prompt.

Directory Structure

src/
├── app/                 # Next.js App Router pages
├── components/          # Shared UI components
├── contexts/            # Global state (History, Settings, Toast)
├── features/            # Feature-specific logic
├── lib/                 # Utilities & API providers
│   ├── llm/             # Provider Registry & Adapters
│   ├── crypto.ts        # Web Crypto helpers (AES‑GCM + PBKDF2)
│   └── storage.ts       # LocalStorage wrapper (typed)
├── components/settings/ # Settings subcomponents (ProviderSelect, ApiKeyField, SecuritySection, LanguageSelect)
└── locales/             # i18n JSON files

Key Components

  • PromptFormEngine: The heart of the application. Manages the conversation loop, state, and rendering of dynamic fields.
  • SettingsContext + useSettingsController: Global configuration, API keys, provider selection, encryption unlock/reset flows.
  • ProviderRegistry: Defines available LLM providers and models (src/lib/llm/registry.ts).
  • AISDKAdapter: Generic adapter for Vercel AI SDK providers.
  • HistoryContext: Manages persistence of past sessions in localStorage.
  • UnlockModal: Blocks UI until the user enters a valid passphrase when encrypted keys are detected.

Security Model

  • API keys are encrypted at rest in localStorage using AES‑GCM and PBKDF2 (Web Crypto API).
  • Passphrase is never persisted; decryption happens in memory at unlock.
  • Passphrase changes trigger atomic re‑encryption for all providers to maintain consistency.