Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:Read Frog is an open-source, AI-powered browser extension for language learning. It is built using the WXT framework, which provides a modern structure for developing Manifest V3 compatible extensions. The architecture emphasizes modularity through a system of entrypoints, a reactive UI built with React and Jotai, and a clear separation of concerns between background services, content scripts, and user interfaces.
The project follows SOLID design principles, preferring pure functions, immutability, and clear boundaries. It leverages a rich tech stack including TypeScript, TailwindCSS, and the Vercel AI SDK to provide features like immersive translation and article analysis.
Sources: CLAUDE.md:5-18, README.md:5-7
Tech Stack
The project utilizes a modern web development stack tailored for browser extension development.
| Category | Technology | Description |
|---|---|---|
| Framework | WXT | A modern browser extension framework that simplifies development for Manifest V3. |
| UI | React 19, TailwindCSS 4, Radix UI, shadcn/ui | For building the user interface components across the extension (popup, options, content scripts). |
| Language | TypeScript | Provides static typing for the entire codebase. |
| State Mgmt | Jotai | A primitive and flexible state management library for React, used with a custom storage adapter for syncing with browser.storage. |
| AI Integration | Vercel AI SDK, @ai-sdk/* packages | Integrates with over 20 AI providers (OpenAI, DeepSeek, etc.) for translation and analysis features. |
| Build System | Vite (via WXT), Nx | WXT uses a Vite-based bundler. Nx is used for managing build, test, and linting tasks. |
| Testing | Vitest, Testing Library | For unit and component testing. |
| i18n | @wxt-dev/i18n | Manages internationalization using YML locale files. |
Sources: CLAUDE.md:80-88, package.json:20-99, nx.json
Extension Structure
The extension's structure is organized around WXT's concept of "entrypoints," which are distinct parts of the extension like the background script, content scripts, and UI pages.
Sources: CLAUDE.md:104-106
This diagram shows how the manifest.json defines the various entrypoints, and how the background script often coordinates activities between them.
Entrypoint Responsibilities
| Entrypoint | Path | Responsibility |
|---|---|---|
| Background | src/entrypoints/background/ | The central service worker. Handles extension lifecycle, message routing, manages translation queues, config backups, and coordinates between different parts of the extension. |
| Host Content Script | src/entrypoints/host.content/ | Injected into web pages. Manages the main article reading and analysis UI, including page translation triggers and creating the shadow DOM for UI components. |
| Side Content Script | src/entrypoints/side.content/ | Manages the side panel interface where article analysis and explanations are displayed. |
| Selection Content | src/entrypoints/selection.content/ | Handles the UI for the selection translation popup. |
| Guide Content | src/entrypoints/guide.content/ | Displays the onboarding guide overlay for new users. |
| Popup | src/entrypoints/popup/ | The main UI shown when the user clicks the extension icon in the browser toolbar. |
| Options | src/entrypoints/options/ | The multi-page settings interface, allowing users to configure API keys, translation behavior, and other preferences. It is configured to open in a new tab. |
Sources: CLAUDE.md:107-119, src/entrypoints/host.content/index.tsx, src/entrypoints/options/index.html:7
Core Feature: Article Reading Flow
The "Read Article" feature is a central part of the application. It involves extracting content from a webpage, sending it to an AI for analysis and summarization, and then generating detailed explanations for each sentence.
This sequence diagram illustrates the high-level flow when a user initiates the "Read" action.
Key Stages
-
Initiation: The user clicks the "Read" button in the side panel UI. This action triggers the
readArticlemutation from theuseReadArticlehook.
Sources: src/entrypoints/side.content/components/side-content/metadata.tsx:43-47 -
Content Extraction: The
useReadArticlehook first ensures fresh content is available by fetching it via areact-querycall (fetchQuerywithqueryKey: ['extractContent']).
Sources: src/hooks/read/read.tsx:219-222 -
Content Analysis: The extracted paragraphs are sent to an AI model via the
useAnalyzeContenthook. A system prompt (getAnalyzePrompt) instructs the AI to summarize the content, determine if it's an article, and detect the language. The response is validated against thearticleAnalysisSchema.
Sources: src/hooks/read/read.tsx:45-63 -
Content Explanation: If the content is identified as an article, the
useExplainArticlehook is called.- It splits the paragraphs into smaller batches to fit within token limits (
MAX_CHARACTERS = 1000). - Each batch is sent to the AI with a detailed prompt (
getExplainPrompt) to generate sentence-by-sentence translations, identify key words, and provide grammatical explanations tailored to the user's configured language level. - The results are streamed or collected and then displayed in the UI.
Sources: src/hooks/read/read.tsx:125-171, src/entrypoints/side.content/components/side-content/content.tsx:29-36
- It splits the paragraphs into smaller batches to fit within token limits (
-
State Updates: Throughout the process, the UI state is managed by Jotai atoms (
readStateAtom,progressAtom) to show loading indicators, progress bars, and the final results.
Sources: src/entrypoints/side.content/components/side-content/content.tsx:16-17, 72-83
Build and Configuration
The project's build process and extension manifest are managed by WXT, configured in wxt.config.ts.
Manifest Configuration
The wxt.config.ts file dynamically generates the manifest.json based on the environment (mode) and target browser.
| Manifest Key | Configuration Detail |
|---|---|
name, description | Uses __MSG_extName__ and __MSG_extDescription__ for internationalization. |
permissions | Requests storage, tabs, alarms, cookies, contextMenus, and identity. |
oauth2 | Configured for Google Drive sync with client_id from environment variables and the drive.appdata scope. |
host_permissions | In development, allows localhost and *.readfrog.app. In production, it's restricted to *.readfrog.app and www.googleapis.com. |
key | A fixed extension ID is used in development for Chrome/Edge to ensure a consistent ID across rebuilds. |
browser_specific_settings | Includes a Gecko (Firefox) ID (extension@readfrog.app) and a minimum version requirement. |
Sources: wxt.config.ts:16-52
Build & Task Management
The project uses nx to define and cache common development tasks. These tasks are defined in nx.json and can be run via pnpm scripts defined in package.json.
pnpm build: Builds the extension for production.pnpm dev: Starts the development server with hot-reloading.pnpm test: Runs all tests using Vitest.pnpm lint: Lints the codebase with ESLint.
The targetDefaults in nx.json configure caching for these tasks, specifying input files that trigger a re-run (e.g., changes in src/**/*) and output directories to be cached (e.g., .output, .wxt).
Sources: nx.json:3-56, package.json:8-18