How haideralsh/prompt-lab works
1. Overall shape
Prompt Lab is a Tauri desktop application: a React/Vite frontend in src/ talks to a Rust backend in src-tauri/ through Tauri commands and events. The app is cross-platform desktop-first, not a hosted web app.
2. Frontend shell
The UI is centered around src/app.tsx, src/main.tsx, and the layout components under src/components/layout/. The shell includes a header, sidebar, main workspace, footer, and toast system, with the main content organized into panels for directory, Git, instructions, selected files, and web pages.
3. State and cross-component coordination
Global client state lives in src/state/atoms.ts and src/state/initial.ts, implying an atom-based store for shared app state such as selected directory, file selection, settings, and panel data. Helper utilities like preserve-selected.ts, sort-files-by-token-count.ts, and update-window-title.ts indicate that state is normalized in the UI and reused across multiple panels.
4. Rust backend boundary
The backend is organized under src-tauri/src/api/, with each feature exposed as a separate module: clipboard, directory, editor, git, instruction, tree, and web. This separation is the key architectural boundary: the UI requests platform-sensitive or filesystem-heavy work from Rust, and Rust returns structured data or emits events back to the UI.
5. Directory and project loading flow
The directory API provides directory picking, recent directories, and listing. This is the entry point for a project context: the user selects a workspace, the backend resolves it, and the frontend uses that directory as the root for tree building, Git status, and file selection.
6. File tree subsystem
The tree module is one of the core backend subsystems. It includes index, cache, select, search, and render, showing a pipeline of:
- indexing a project tree,
- caching results,
- searching/filtering nodes,
- selecting files or nodes,
- rendering tree data for the UI.
This is the data backbone for the sidebar file explorer and file-context generation.
7. Git context subsystem
The git API provides commands plus status, watch, event, and tokenize. This suggests the backend monitors repository state, computes diffs or file statuses, and streams updates to the UI. The Git panel uses those updates to let users include code changes as LLM context, with token counts likely derived from diff content.
8. Instruction management
The instruction API and the instruction panel/form components support saving reusable prompt instructions. The frontend has create/edit flows, while the backend stores or validates instruction data. This subsystem is separate from file content and acts as reusable prompt scaffolding.
9. Web documentation capture
The web API contains scrape and favicon functionality. This indicates the app can fetch a webpage, convert it into markdown-like context, and display or save it as prompt material. It is a distinct ingestion path from local files and Git data.
10. Clipboard and editor integration
clipboard exposes copy behavior, and editor likely opens files in the user’s local editor. These are thin desktop integration layers that let the app hand context out to other tools, rather than keeping everything inside the app.
11. Token counting as a shared concern
Token-related code appears across UI and backend: src/types/tokens.ts, use-token-count-listener.tsx, Git token listeners, and instruction token counting. Token count is not just a display metric; it influences ordering, selection, and prompt assembly across the app’s main panels.
12. Selected-file and context composition flow
The selected-files panel, file-tree selection components, Git panel, web panel, and instruction panel all feed into a context-building workflow. The app appears designed to assemble a final prompt payload from multiple sources: project tree, chosen files, Git diff, saved instructions, and web docs.
13. Persistence and local app configuration
src/api/settings.ts, src/components/sidebar/settings-dialog.tsx, and src/store.ts on the Rust side suggest local persistence for settings and workspace data. The app likely stores recent directories, saved instructions, and UI preferences locally rather than in a remote backend.
14. Tooling, delivery, and verification
The repository uses pnpm + Vite + React on the frontend and Rust/Cargo + Tauri on the backend. CI is split into .github/workflows/build.yml and test.yml, and the Rust side has dedicated tests under src-tauri/tests/, especially for directory, editor, and tree search APIs.
15. How to draw the architecture
A good diagram should show:
- a desktop UI layer in React,
- a Tauri IPC boundary,
- backend feature modules for directory/tree, git, instructions, web scraping, clipboard/editor,
- and a shared local state/persistence layer.
The central data path is: user picks a directory → backend indexes tree and watches git → UI lets the user select files/instructions/web docs → app composes token-aware context for copying or external use.
Main entry points: api IPC API · layout.tsx Layout · panels Panels · tree Tree API
Components 18
Frontend
React/Vite desktop UI and client-side state
- App shell · Bootstraps the desktop UI and routes into the main application layout.
src/app.tsx - Layout · Header, sidebar, main workspace, footer, and toast composition.
src/components/layout/layout.tsx - Sidebar · Project navigation, search, resize behavior, and settings access.
src/components/sidebar/sidebar.tsx - Panels · Directory, Git, instruction, selected-files, and web panels.
src/components/panels - State atoms · Global atom-based state for directory, selection, settings, and panel data.
src/state/atoms.ts - Token UI · Token counting listeners, charts, and display components used across panels.
src/components/layout/use-token-count-listener.tsx - IPC API · Typed client calls into the Tauri backend for directory, git, instruction, selection, settings, and web actions.
src/api
Backend
Rust Tauri commands, events, and local persistence
- Directory API · Directory pick, recent directories, and listing from the backend.
src-tauri/src/api/directory - Tree API · Indexing, caching, selection, search, and render pipeline for project files.
src-tauri/src/api/tree - Git API · Repository status, watch events, and tokenization for change context.
src-tauri/src/api/git - Instruction API · Create, edit, validate, and persist reusable instruction content.
src-tauri/src/api/instruction - Web API · Scrapes pages and fetches favicons for web-based prompt context.
src-tauri/src/api/web - Clipboard · Copies assembled context out to the system clipboard.
src-tauri/src/api/clipboard - Editor · Opens files in the user’s preferred local editor.
src-tauri/src/api/editor - Local store · Rust-side local persistence for settings and workspace-related data.
src-tauri/src/store.rs
Shared
Data models and token-aware helpers used across the app
- Shared types · Directory, file-tree, git, and token type definitions shared in the frontend.
src/types - Helpers · Selection preservation, token sorting, and window-title updates used by the shell.
src/helpers - Context build · Combines selected files, git changes, instructions, and web captures into prompt-ready context.
Connections 23
- App shell → Layout: renders · The app entry composes the main desktop shell.
- Layout → Sidebar: contains · The shell includes the project sidebar.
- Layout → Panels: contains · The shell hosts the main workspace panels.
- Layout → Token UI: shows · Token metrics are surfaced in the shell.
- Sidebar → State atoms: reads/writes · Navigation, search, and settings are driven by shared state.
- Panels → State atoms: reads/writes · Panels coordinate selected files, instructions, pages, and project context.
- Panels → Context build: feeds · Panel content contributes to the final prompt payload.
- IPC API → Directory API: calls · Frontend requests workspace selection and directory listing.
- IPC API → Tree API: calls · Frontend requests tree indexing, search, selection, and rendering.
- IPC API → Git API: calls · Frontend requests repository status and receives updates.
- IPC API → Instruction API: calls · Frontend manages saved instructions through backend commands.
- IPC API → Web API: calls · Frontend fetches scraped web content and favicons.
- IPC API → Clipboard: calls · Frontend copies assembled context to the clipboard.
- IPC API → Editor: calls · Frontend opens files in an external editor.
- Directory API → Local store: persists · Recent directories and workspace data are stored locally.
- Tree API → Shared types: uses · Tree data structures are shared across the UI boundary.
- Git API → Token UI: emits counts · Git diff and status token counts drive UI metrics.
- Instruction API → Context build: adds · Saved instructions become part of prompt composition.
- Web API → Context build: adds · Scraped web pages become part of prompt composition.
- Git API → Context build: adds · Git status and diffs are incorporated into context.
- Tree API → Context build: adds · Selected files and tree-derived content feed context composition.
- Helpers → State atoms: normalizes · Selection and display helpers reshape shared UI state.
- Helpers → Token UI: orders · Token-aware sorting and display logic influence UI presentation.