How kapi-ide/kapi-lite works
Project Type and Purpose
• This is an Electron-based desktop application (“Kapi Lite”) with a React/TypeScript renderer and a Node-powered main process.
• Purpose: provide a local-first, AI-powered code review and chat interface that scans the user’s file system, stores context in IndexedDB, and sends selected code snippets to an LLM for analysis.
High-Level Architecture
a. User Interface (Renderer Process)
• React components and pages under src/
• Bundled by Vite, loaded via index.html
b. Preload / IPC Bridge
• electron/preload.ts exposes safe APIs via contextBridge
c. Main Process (Electron)
• electron/main.ts manages windows, routes IPC calls to handlers
• electron/fileSystemHandlers.ts enforces permission/security for FS ops
d. Local Services & Storage
• src/services : conversationService, fileSystemService, indexedDBService
• Business logic in src/utils (chatService, codeCollector, langchainConfig, migrationUtils)
• IndexedDB for persistent context in the browser sandbox
e. External AI Integration
• LLM endpoints (local or remote) accessed via chatService/langchainConfig
Relationships & Data Flows
• Renderer → Preload: UI invokes window.api.* methods for FS listing, chat, reviews
• Preload → Main: IPC channel forwards requests (e.g., “select directory”, “read file”)
• Main → File System Handlers: validates paths, reads files, respects .gitignore
• Renderer Services → IndexedDB: stores chat history, permissions, migration state
• Renderer Utils → External AI: bundles context, calls LLM, receives and displays suggestions
Architectural Patterns & Principles
• Separation of Concerns:
• UI (React) vs. platform integration (Electron) vs. business logic (Services/Utils)
• Security Layer: permission gating in fileSystemHandlers.ts
• Local-First: IndexedDB for context persistence, controlled code sharing
• Modular Code Review Pipeline: Code collector → prompt generator → LLM call → inline feedback
Final Checklist
• Stack vertically: UI → Preload → Main → Services → External LLM
• With filenames or folder names for each component