Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

docs: update AGENTS.md with current architecture

Luis Ortiz5167247ac937
diff --git a/AGENTS.md b/AGENTS.md
index b9f9b9d..6d9f330 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -12,37 +12,170 @@ You click "Record," perform a workflow in your browser, and Mimik automatically
**Everything runs in the Chrome extension. No backend.**
-- Storage: IndexedDB (browser-local)
+- Storage: IndexedDB via Dexie.js (browser-local)
- AI descriptions: optional, user provides their own API key in settings
- Export: generated client-side (no server rendering)
- No auth, no database, no hosting, no Docker
-## Features
+### Directory Structure
-| Feature | Description |
-| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| **Record** | Click the extension, perform your workflow. Every click/input auto-captures a screenshot with the element highlighted and a description generated. rrweb DOM recording runs alongside for video-like playback. |
-| **Edit** | Side panel UI to reorder steps, rename titles, edit descriptions, blur sensitive areas on screenshots, delete steps. |
-| **Replay** | Open a saved guide and hit replay. The extension walks through each step on the live page β€” finds elements, clicks/types for you, advances automatically. |
-| **Export** | Download as self-contained HTML (offline), Markdown (for docs/wikis/repos), or PDF. All generated client-side. |
-| **Settings** | Optional AI API key (OpenAI/Anthropic) for auto-generated step descriptions. Tool works without it. |
-| **Storage** | All guides saved locally in IndexedDB. No account, no server, no data leaves the browser. |
+```
+src/
+β”œβ”€β”€ core/ # Business logic (no UI dependencies)
+β”‚ β”œβ”€β”€ capture/ # Recording pipeline, event detection, screenshots
+β”‚ β”œβ”€β”€ export/ # HTML, PDF, Markdown export generators
+β”‚ └── guides/ # Data layer: types, Dexie DB, CRUD service
+β”œβ”€β”€ entrypoints/ # Chrome extension entry points (WXT)
+β”‚ β”œβ”€β”€ background/ # Service worker: state machine, message handlers, tab management
+β”‚ β”œβ”€β”€ content.ts # Content script: event capture, overlay, rrweb recording
+β”‚ β”œβ”€β”€ sidepanel/ # Side panel React mount
+β”‚ β”œβ”€β”€ fullview/ # Full-page view React mount
+β”‚ └── options/ # Settings page React mount
+β”œβ”€β”€ lib/ # Shared utilities
+β”‚ β”œβ”€β”€ messaging.ts # Extension messaging protocol (webext-core)
+β”‚ β”œβ”€β”€ port.ts # Long-lived port: background ↔ sidepanel
+β”‚ β”œβ”€β”€ browser-api.ts # Chrome API wrappers
+β”‚ β”œβ”€β”€ tab-messages.ts # Content script message types
+β”‚ β”œβ”€β”€ logger.ts # Logging utility
+β”‚ └── utils.ts # Shared helpers (dates, URLs, cn)
+β”œβ”€β”€ stores/ # Zustand state stores
+β”‚ └── fullview.ts # Fullview UI state (search, counts, guide data)
+└── ui/ # React components
+ β”œβ”€β”€ components/ui/ # shadcn/ui primitives (button, input, dialog, badge)
+ β”œβ”€β”€ fullview/ # Full-page dashboard
+ β”‚ β”œβ”€β”€ components/ # Extracted sub-components (grid, list, search, etc.)
+ β”‚ β”œβ”€β”€ App.tsx
+ β”‚ β”œβ”€β”€ TopNav.tsx
+ β”‚ β”œβ”€β”€ SearchModal.tsx
+ β”‚ β”œβ”€β”€ GuideContent.tsx
+ β”‚ β”œβ”€β”€ LibraryContent.tsx
+ β”‚ └── router.ts
+ β”œβ”€β”€ sidepanel/ # Side panel UI
+ β”‚ β”œβ”€β”€ App.tsx
+ β”‚ β”œβ”€β”€ LibraryView.tsx
+ β”‚ β”œβ”€β”€ GuideEditor.tsx
+ β”‚ β”œβ”€β”€ RecordingView.tsx
+ β”‚ β”œβ”€β”€ StepCard.tsx
+ β”‚ β”œβ”€β”€ ExportMenu.tsx
+ β”‚ β”œβ”€β”€ BlurCanvas.tsx
+ β”‚ └── ZoomScreenshot.tsx
+ └── options/ # Settings page
+ └── App.tsx
+```
+
+## State Management
+
+| Layer | Tool | Purpose |
+|-------|------|---------|
+| Capture lifecycle | xstate | State machine (IDLE ↔ RECORDING) in background service worker |
+| Fullview UI | Zustand | Search modal, guide counts, active guide data |
+| Persistence | Dexie (IndexedDB) | Guides, steps, screenshots, rrweb chunks |
+| Service worker recovery | sessionStorage | xstate machine snapshot persistence |
+| Background β†’ Sidepanel | Port messaging | Real-time state broadcast |
+
+## Extension Entry Points
+
+| Entry Point | File | Purpose |
+|-------------|------|---------|
+| Background | `entrypoints/background/` | Service worker: xstate actor, message handlers, tab management, navigation tracking |
+| Content Script | `entrypoints/content.ts` | Injected into all tabs: CaptureSession, event listeners, rrweb, highlight overlay |
+| Side Panel | `entrypoints/sidepanel/` | Recording controls, library, guide editor |
+| Full View | `entrypoints/fullview/` | Dashboard: library browse, guide viewer, Ctrl+K search |
+| Options | `entrypoints/options/` | AI API key settings (OpenAI / Anthropic) |
+
+## Messaging
+
+```
+Content Script ←→ Background Service Worker ←→ Sidepanel / Fullview
+```
+
+**Extension messages** (webext-core, `lib/messaging.ts`):
+- `getState` β†’ current capture state, step count, guide ID
+- `startRecording({url})` β†’ creates guide, returns guideId
+- `stopRecording()` β†’ finalizes guide
+- `userAction({guideId, action, elementMeta})` β†’ processes captured step
+- `rrwebChunk({guideId, events, timestamp})` β†’ stores DOM recording chunk
+
+**Tab messages** (content script ↔ background, `lib/tab-messages.ts`):
+- `PING` / `START_CAPTURE` / `STOP_CAPTURE` β€” lifecycle
+- `HIDE_OVERLAY` / `SHOW_OVERLAY` β€” overlay toggle before/after screenshot
+- `SHOW_NOTIFICATION` β€” "Recording started" overlay
+- `URL_CHANGED` / `GET_ROUTE` β€” SPA navigation tracking
+
+## Capture Pipeline
+
+**Start recording:**
+1. User clicks "Start Capture" in sidepanel
+2. Background transitions xstate machine IDLE β†’ RECORDING
+3. Creates Guide in IndexedDB, broadcasts `START_CAPTURE` to all tabs
+4. Content scripts initialize CaptureSession (event listeners + rrweb)
+5. Shows recording notification overlay on active tab
+
+**Capture a step:**
+1. Content script detects user action (click, input, drag)
+2. Extracts ElementMeta (selector, text, aria labels, position)
+3. Sends `userAction` to background
+4. Background hides overlay β†’ `captureVisibleTab` β†’ shows overlay
+5. Optionally sends screenshot to AI for description (OpenAI/Anthropic)
+6. Saves Step + Screenshot to IndexedDB
+
+**Stop recording:**
+1. Background transitions RECORDING β†’ IDLE
+2. Broadcasts `STOP_CAPTURE`, content scripts flush rrweb events
+3. Opens fullview dashboard with the guide
+
+## Export Formats
+
+| Format | Generator | Details |
+|--------|-----------|---------|
+| HTML | `core/export/html-export.ts` | Self-contained, base64 images, inline CSS |
+| PDF | `core/export/pdf-export.ts` | jsPDF, A4 portrait, auto page breaks |
+| Markdown | `core/export/markdown-export.ts` | Standard MD with base64 image data URLs |
## Tech Stack
-- **Extension:** Chrome Manifest V3, TypeScript
-- **UI:** React (side panel)
-- **State management:** XState (workflow/capture state machine)
-- **Session recording:** rrweb
-- **Storage:** IndexedDB via Dexie.js
-- **Export:** jsPDF (PDF), client-side HTML/Markdown generation
-- **AI (optional):** Direct API calls to OpenAI/Anthropic from the extension
+| Layer | Technology |
+|-------|-----------|
+| Extension framework | WXT (Manifest V3) |
+| Language | TypeScript |
+| UI | React 19 |
+| Styling | Tailwind CSS v4 |
+| Components | shadcn/ui |
+| State (capture) | xstate |
+| State (UI) | Zustand |
+| Storage | Dexie.js (IndexedDB) |
+| Messaging | webext-core |
+| Session recording | rrweb |
+| Export | jsPDF, client-side HTML/Markdown |
+| AI (optional) | OpenAI SDK, Anthropic SDK |
+| Icons | Lucide React |
+| Dates | dayjs |
+| DOM utils | css-selector-generator |
+
+## Design System
+
+All colors are defined as CSS variables in `src/ui/sidepanel/index.css` and used via Tailwind classes:
+
+| Token | Color | Usage |
+|-------|-------|-------|
+| `--color-foreground` | `#451a03` | Primary text |
+| `--color-muted-foreground` | `#92400E` | Secondary text |
+| `--color-warm` | `#B45309` | Tertiary text |
+| `--color-border` | `#E8E2DA` | Borders, dividers |
+| `--color-secondary` | `#FEF3C7` | Light wash backgrounds |
+| `--color-gold` | `#FDE68A` | Accent highlights |
+| `--color-amber` | `#F59E0B` | Primary amber |
+| `--color-primary` | `#451a03` | Dark backgrounds, badges |
+| `--color-primary-foreground` | `#FDE68A` | Text on dark backgrounds |
+
+Font: Poppins (loaded via `@fontsource/poppins`).
## Key Technical Details
-- **Screenshot capture** uses `chrome.tabs.captureVisibleTab` (Chrome API)
-- **Step detection** tracks DOM elements via selectors and scoring, classifies actions (click/input/scroll)
-- **Auto-titles** read element text, aria labels, and alt attributes
-- **Workflow engine** is an XState state machine managing capture lifecycle, guidance, and replay
-- **Replay** finds elements on live pages, executes click/type/scroll actions, advances through steps
-- **rrweb** records DOM mutations for video-like session playback
+- **Screenshot capture** uses `chrome.tabs.captureVisibleTab` with overlay hidden to avoid capturing the highlight
+- **Event deduplication** merges fast clicks within 300ms on same element; max 4 clicks per 800ms window
+- **Highlight overlay** uses a custom web component (`<mimik-highlight>`) with closed Shadow DOM at max z-index
+- **Content script injection** pings first, falls back to `chrome.scripting.executeScript()` for tabs without the script
+- **xstate snapshot** persisted to sessionStorage so the state machine survives service worker restarts
+- **Recording notification** uses `animationend` event (not hardcoded delays) for timing
+- **Font loading** uses `@fontsource/poppins` (CSP-safe, no CDN dependency)