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: describe the code layout across the apps

Luis Ortizd8a3c2db4aac
diff --git a/AGENTS.md b/AGENTS.md
index 2fb657c..932c20c 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -10,7 +10,7 @@ You click "Record," perform a workflow in your browser, and Mimik automatically
## Architecture
-**Everything runs in the Chrome extension. No backend.**
+**Everything runs on the user's machine β€” in the Chrome extension or the desktop app. No backend.**
- Storage: IndexedDB via Dexie.js (browser-local)
- AI descriptions: optional, user provides their own API key in settings
@@ -20,71 +20,23 @@ You click "Record," perform a workflow in your browser, and Mimik automatically
### Directory Structure
```
-src/
-β”œβ”€β”€ core/ # Business logic (no UI dependencies)
-β”‚ β”œβ”€β”€ capture/ # Recording pipeline
-β”‚ β”‚ β”œβ”€β”€ ai/ # AI description + title generation (Vercel AI SDK)
-β”‚ β”‚ β”‚ β”œβ”€β”€ description.ts # getAIDescription (DOM context β†’ AI β†’ step text)
-β”‚ β”‚ β”‚ β”œβ”€β”€ title.ts # generateGuideTitle (steps β†’ AI β†’ guide name)
-β”‚ β”‚ β”‚ β”œβ”€β”€ models.ts # AI_PROVIDERS config (OpenAI/Anthropic model lists)
-β”‚ β”‚ β”‚ β”œβ”€β”€ prompts.ts # Prompt templates
-β”‚ β”‚ β”‚ └── provider.ts # createModel factory (OpenAI/Anthropic)
-β”‚ β”‚ β”œβ”€β”€ dom/ # DOM extraction utilities
-β”‚ β”‚ β”‚ β”œβ”€β”€ context.ts # DOMContext extraction + serialization
-β”‚ β”‚ β”‚ β”œβ”€β”€ element-meta.ts # extractElementMeta (selector, text, aria, rect)
-β”‚ β”‚ β”‚ └── element-utils.ts # findFocusableAncestor, isTextField, etc.
-β”‚ β”‚ β”œβ”€β”€ events/ # Event capture system
-β”‚ β”‚ β”‚ β”œβ”€β”€ handlers.ts # CaptureController class + startCapture
-β”‚ β”‚ β”‚ └── input-session.ts # InputSession (typing lifecycle)
-β”‚ β”‚ β”œβ”€β”€ machine.ts # xstate capture state machine
-β”‚ β”‚ β”œβ”€β”€ session.ts # CaptureSession (lifecycle manager)
-β”‚ β”‚ β”œβ”€β”€ spa-nav.ts # SPA navigation tracking
-β”‚ β”‚ β”œβ”€β”€ start-notification.ts # Recording notification overlay
-β”‚ β”‚ └── step-description.ts # Fallback rule-based descriptions
-β”‚ β”œβ”€β”€ blur/ # Smart blur: regex presets, DOM scanner, element picker, panel UI
-β”‚ β”œβ”€β”€ export/ # HTML, PDF, DOCX, Markdown, video generators + shared utils
-β”‚ └── 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: CaptureSession, event listeners
-β”‚ β”œβ”€β”€ sidepanel/ # Side panel React mount
-β”‚ β”œβ”€β”€ fullview/ # Full-page view React mount
-β”‚ β”œβ”€β”€ onboarding/ # Onboarding wizard (opens on first install)
-β”‚ └── 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
- β”œβ”€β”€ onboarding/ # Onboarding wizard UI
- β”‚ └── App.tsx # 5-step wizard (welcome, AI, blur, pin, done)
- β”œβ”€β”€ shared/ # Shared UI components
- β”‚ └── SettingsView.tsx # AI settings (provider, model, API key)
- └── options/ # Settings page
- └── App.tsx
+src/ the Chrome extension (WXT)
+β”œβ”€β”€ entrypoints/ background, content, sidepanel, fullview, onboarding, options, offscreen, mic-permission
+β”œβ”€β”€ capture/ capture session, DOM event handlers and the capture sink, in the content script
+β”œβ”€β”€ blur/ smart blur picker and manager in the page
+β”œβ”€β”€ guideme/ Guide Me in the page
+β”œβ”€β”€ lib/ extension plumbing: browser-api/, port/, offscreen/, voice/, update-notice/, messaging
+β”œβ”€β”€ ui/ extension screens: sidepanel/, fullview/, onboarding/, options/, mic-permission/, shared/
+└── locales/
+packages/
+β”œβ”€β”€ core/src/ logic both surfaces share: capture, guides, export, screenshot, blur, guideme, i18n, env
+β”œβ”€β”€ ui/src/ React both surfaces share, grouped by feature
+└── capture-native/ the Windows UIAutomation addon, in Rust
+apps/desktop/src/
+β”œβ”€β”€ main/ Electron main: window, tray, capture pipeline, overlay windows, shortcuts
+β”œβ”€β”€ preload/ the contextBridge API
+└── renderer/ the app window, the overlay renderer, settings/, ai/ and the checks
+scripts/ repository checks that pnpm lint runs
```
## State Management
@@ -339,7 +291,7 @@ had grown a private copy of it, identical line for line.
## Boundaries The Linter Holds
-`biome.json` covers `src`, `packages/core`, `packages/ui` and `apps/desktop`. `packages/ui` was
+`biome.json` covers `src`, `packages/core`, `packages/ui`, `apps/desktop` and `scripts`. `packages/ui` was
missing from that list for a long time and nobody noticed, which is how forty-odd files reached it
unchecked; adding it produced forty-one fixes on the first run.
@@ -356,7 +308,7 @@ runtime to a path with no file and the app dies on launch with `ERR_MODULE_NOT_F
`capture/screenshot.ts` keeps its own three-line `clamp` rather than importing core's: deduplicating
a one-liner is not worth a cross-boundary dependency that does not work.
-## UI Package Layout
+## Code Layout
`packages/ui/src` is grouped by feature, not by the surface that first used a file: `ai`,
`annotation`, `common`, `export`, `guide`, `history`, `library`, `navigation` and `search`. Inside a
@@ -364,31 +316,52 @@ feature, components sit in `components/`, hooks in `hooks/`, plain functions in
slice in `store/`, and a `types.ts` only when several files share a type. `components/ui` holds the
shadcn primitives as the generator writes them, and `stores/` merges the slices.
+The apps take the same shape one surface at a time. Each of `src/ui/sidepanel`, `fullview`,
+`onboarding`, `mic-permission`, `shared` and `apps/desktop/src/renderer` keeps its components side by
+side, its functions in `lib/` and its hooks in `hooks/`. `src/lib` is already a lib folder, so a
+module there that held several functions became a folder named after it β€” `browser-api/`, `port/`,
+`offscreen/`, `update-notice/` β€” and the voice pieces share `voice/`. An entry script such as
+`overlay.ts` or `check-storage.ts` keeps only its dispatch and imports the rest from a folder of the
+same name.
+
A file exports one thing β€” a component, a hook or a function β€” and is named after it. A hook or a
`lib/` function may keep one private helper that nothing else calls; a component file keeps none, so
-its helpers live in the feature's `lib/`. Constants and types may sit beside the export they serve.
+its helpers live in `lib/`. Constants, types and objects of functions may sit beside the export they
+serve. That rule holds in all four roots: `packages/ui/src`, `src/ui`, `src/lib` and
+`apps/desktop/src/renderer`.
+
+Exports are named. A default export can be imported under any name, so one component can read
+differently at every import site; a named one is found by the same search everywhere. WXT
+entrypoints and the config files keep their defaults because the framework reads them, and the one
+`React.lazy` maps a named export onto the `default` it needs.
The apps import from `'@mimik/ui'` and nowhere deeper, except `@mimik/ui/env` and
-`@mimik/ui/global.css`. `src/index.ts` is the one file allowed to re-export, and code inside the
-package never imports through it β€” that would be a cycle. Adding a public component means adding a
-line there. The extension build was diffed against the pre-entry baseline: the service worker and
-the content script came out byte-identical, because neither imports the package, and the rest moved
-by a few hundred bytes.
-
-The linter holds all of it. `noRestrictedImports` rejects a deep `@mimik/ui/*` import from the apps
-and a bare `'@mimik/ui'` from anything under `packages/`. `noBarrelFile` rejects any other
-re-exporting file, and `useComponentExportOnlyModules` rejects a component file that also exports a
-function or a hook. The shadcn primitives are excused from the last rule, since they export their
-`*Variants` beside the component and regenerating them would bring that back. Nothing checks
-that a `lib/` file holds one function; that part is review.
+`@mimik/ui/global.css`. `src/index.ts` is the one file allowed to re-export. Inside the package every
+import is relative β€” it never names itself, through the entry or otherwise, so it cannot cycle
+through its own index. The extension build was diffed against the baseline from before the entry
+existed: the content script came out byte-identical, and the whole build within a few hundred bytes.
+
+State that several functions share lives in a `{ current }` holder β€” `localVoiceHost`, the offscreen
+document's `creating` promise, `lastVoice` in `port/state.ts` β€” because an imported `let` is
+read-only in the module that imports it, so a getter and setter pair could not be split without one.
+The UI package's env adapter is the same idea for functions: `tabs`, `panel` and `messages` are
+objects of accessors over the one configured adapter, which leaves `configureUi` its only export.
+
+The linter holds it. `noRestrictedImports` rejects a deep `@mimik/ui/*` import from the apps and any
+`@mimik/ui` import from inside `packages/`. `noBarrelFile`, `useComponentExportOnlyModules` and
+`noDefaultExport` cover the four roots, with the shadcn primitives excused from the second since they
+export their `*Variants` beside the component. `scripts/check-exports.mjs` runs after Biome in
+`pnpm lint` and catches what no Biome rule can: a second exported function, a helper declared in a
+component file, a second private helper anywhere else, and any re-export outside the package entry.
Three things break quietly when files move here. The root `tsconfig.json` declares its own `paths`,
which replace the ones in `.wxt/tsconfig.json` rather than extending them, so the bare `@mimik/ui`
entry has to be listed in the root config and in `apps/desktop/tsconfig.json` alike. A `vi.mock`
-path is a string the refactoring tools do not rewrite, and a stale one mocks nothing without
-failing. And `sideEffects` in the package's `package.json` names `common/lib/dayjs-locale.ts`,
-because that file registers the dayjs locales by importing them; renaming it without updating
-the entry lets a bundler drop the translations.
+path is a string the refactoring tools do not rewrite; a stale one mocks nothing without failing,
+and once a module is split each mock has to name the file its function now lives in β€”
+`vi.mock('@/lib/browser-api/local-storage')`, not the folder. And `sideEffects` in the package's
+`package.json` names `common/lib/dayjs-locale.ts`, because that file registers the dayjs locales by
+importing them; renaming it without updating the entry lets a bundler drop the translations.
## Which Client Is Running
@@ -1017,7 +990,7 @@ what has `host_permissions`, and the desktop calls `validateApiKey` directly on
process fetch.
The rest of `SettingsView` stayed put. Voice narration, smart blur, brand logos and the microphone
-picker have no desktop meaning, and it reaches for `@/lib/browser-api`. Splitting it did mean the
+picker have no desktop meaning, and it reaches into `@/lib/browser-api/`. Splitting it did mean the
autosave had to change shape: the AI fields left the parent's snapshot, so `AiSettings` reports its
own changes through `onChange` and both halves queue into the same debounced flush. `SettingsView`
still keeps the provider and key in state for one reason β€” `resolveVoiceApiKey` falls back to the AI
@@ -1127,7 +1100,7 @@ unexplained.
## Design System
-All colors are defined as CSS variables in `src/ui/global.css` and used via Tailwind classes:
+All colors are defined as CSS variables in `packages/ui/src/global.css` and used via Tailwind classes:
| Token | Color | Usage |
|-------|-------|-------|