The Next-Generation AI Writing Assistant for Chrome
Context-Aware Grammar Checking โข Tone Analysis โข Instant Rewriting โข Multi-Language Support
View Demo โข Report Bug โข Request Feature
- Project Overview
- Key Features
- Architecture & How It Works
- Code Deep Dive
- Tech Stack
- Installation & Setup
- Usage Guide
- Project Structure
- Future Roadmap
- Contributing
PrivatePen-Pro is a sophisticated Chrome Extension and Web Application designed to integrate advanced AI capabilities directly into the browser's writing workflow. Unlike traditional regex-based spellcheckers, PrivatePen utilizes Google's Gemini 3 Flash & Pro models to understand the semantics, context, and tone of text.
Whether drafting emails in a Side Panel or correcting blog posts via an injected Floating Toolbar, the application ensures data privacy, high performance, and linguistically accurate results across any language.
| Feature | Description |
|---|---|
| ๐ง Neural Grammar Engine | Uses LLMs to detect complex sentence structure errors, awkward phrasing, and context-dependent spelling mistakes. |
| ๐จ Emotional Tone Radar | Visualizes writing style (Formal, Friendly, Aggressive, Professional) using interactive Recharts radar graphs. |
| ๐ Contextual Rewriting | Instantly transforms text styles (e.g., "Make it Professional", "Make it Pirate", "Summarize") while preserving meaning. |
| ๐ Polyglot Core | Built-in support for any language. Users can type "French" or "Klingon" in settings, and the AI adapts its output language and cultural nuances. |
| โก Floating Injection | A content script injects a lightweight toolbar into any webpage when text is selected, offering immediate AI assistance without leaving the tab. |
| ๐๏ธ Speech-to-Text | Integrated Web Speech API support for dictation and hands-free drafting. |
| ๐พ Smart Storage | Abstracted storage layer that syncs user history, templates, and settings across devices (via Chrome Sync) or local storage (Dev mode). |
PrivatePen-Pro follows a hybrid Chrome Extension (Manifest V3) and Single Page Application (SPA) architecture.
- Input: User selects text (Content Script) or types in the Editor (Side Panel).
- State Management: React Context (
StorageContext,SettingsContext) captures the input. - Service Layer: The application calls
geminiService.ts. - AI Processing:
- Gemini 3 Flash: Used for low-latency tasks like Grammar Checking and Tone Analysis.
- Gemini 3 Pro: Used for complex creative tasks like Rewriting and Expansion.
- Response Handling: The AI returns either raw text or structured JSON (via
responseSchema), which is parsed and rendered in the UI.
- Side Panel: The main dashboard. Persistent, allows for long-form writing and history management.
- Content Scripts: Isolated JavaScript environments that run on web pages (
content.ts). They detect text selection, calculate DOM coordinates, and render the ReactFloatingToolbarcomponent into the DOM shadow root (or container). - Background Service Worker: Handles context menu events and cross-origin logic if necessary.
Here is an explanation of the critical logic blocks in the application for developers.
This file handles all interactions with the Google GenAI SDK.
- JSON Enforcement: To ensure the Grammar Checker returns data we can programmatically highlight, we use
responseMimeType: "application/json"and define a strictresponseSchema.// Example: Enforcing structured output for grammar responseSchema: { type: Type.ARRAY, items: { type: Type.OBJECT, properties: { original: { type: Type.STRING }, suggestion: { type: Type.STRING }, // ... } } }
- Prompt Engineering: We use
systemInstructionto define the persona (e.g., "You are a strict grammar checker" or "You are an expert linguist").
The core writing component.
- State Management: Uses complex state for
text,history(Undo/Redo stack), andsuggestions. - Selection Handling: Detects
selectionStartandselectionEndon the textarea to allow the AI to process only specific parts of the text. - Real-time Visualization: Integrates
Rechartsto render theToneAnalysisdata returned by the API.
- Event Listeners:
content.tslistens formouseupevents globally. - Coordinate Calculation: Calculates the
DOMRectof the selected text to position the toolbar directly above the cursor. - Isolation: Renders a separate React Root specifically for the toolbar to ensure styles don't conflict with the host webpage.
- Frontend: React 18 (Component-based UI)
- Language: TypeScript (Type safety & strict interfaces)
- Build Tool: Vite (Fast HMR & efficient bundling for extensions)
- AI Engine: Google Gemini API (
@google/genaiSDK) - Styling: Tailwind CSS (Utility-first styling)
- Icons: Lucide React (Consistent, lightweight icons)
- Data Viz: Recharts (Radar charts for tone analysis)
- Node.js (v16+)
- npm or yarn
- A Google Cloud Project with Gemini API enabled.
git clone https://github.com/yourusername/privatepen-pro.git
cd privatepen-pronpm installCreate a .env file in the root directory.
touch .envAdd your API key (Get it from Google AI Studio):
API_KEY=your_gemini_api_key_hereTo create the production build:
npm run buildThis generates a dist folder containing the manifest, compiled JS, and assets.
- Open Chrome and navigate to
chrome://extensions/. - Enable Developer mode (top right switch).
- Click Load unpacked.
- Select the
distfolder generated in Step 4.
Developer Tip: You can run
npm run devto launch the app in a web browser for UI testing, though Chrome-specific APIs (likechrome.storage) will be mocked.
- Click the extension icon in the Chrome toolbar.
- Click "Open Editor".
- Drafting: Type normally.
- Grammar: Click the "Fix" button. Red underlines will appear. Click them to accept changes.
- Tone: Click "Tone" -> "Analyze" to see the radar chart.
- Language: Go to Settings tab and type your target language (e.g., "Spanish").
- Highlight text on any website.
- The PrivatePen Toolbar will appear.
- Select Fix, Rewrite, or Summarize.
- Click Replace to overwrite the selected text with the AI version.
privatepen-pro/
โโโ public/ # Static assets (icons)
โโโ src/
โ โโโ components/ # React UI Components
โ โ โโโ Editor.tsx # Main text editor logic
โ โ โโโ FloatingToolbar.tsx # Injected widget
โ โ โโโ ...
โ โโโ contexts/ # React Context (Auth, Settings, Storage)
โ โโโ services/ # Business Logic
โ โ โโโ geminiService.ts # AI integration
โ โ โโโ storageService.ts # Chrome storage wrapper
โ โโโ background.ts # Extension background worker
โ โโโ content.ts # Content script entry
โ โโโ App.tsx # Main routing
โ โโโ manifest.json # Extension configuration
โโโ dist/ # Production build output
โโโ vite.config.ts # Vite configuration
โโโ package.json # Dependencies
- Context Awareness: Allow the AI to read the entire webpage content to provide context-aware replies (e.g., for email replies).
- Custom Personas: Create and save custom AI personalities (e.g., "My Brand Voice").
- PDF Support: Ability to upload and summarize PDF documents.
- Team Sync: Share templates and dictionaries across a team.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature')