5.9 KiB
5.9 KiB
Data Hound Development Guide
This document provides detailed technical information for developers working on the Data Hound project. It covers architecture, development workflows, and best practices.
Architecture Overview
Main Process (Electron)
The main process (electron/
) handles:
- File system operations (
services/fileSystem.ts
) - LLM service integration (
services/llmService.ts
,services/ollamaService.ts
) - Vector store management (
services/vectorStore.ts
) - IPC communication (
ipc/handlers.ts
) - Application state persistence (
store.ts
)
Key Services
-
File System Service (
fileSystem.ts
)- Handles file indexing and monitoring
- Manages file metadata extraction
- Implements file type detection and parsing
-
LLM Service (
llmService.ts
)- Manages LLM provider connections
- Handles prompt engineering
- Implements response streaming
-
Vector Store (
vectorStore.ts
)- Manages ChromaDB integration
- Handles document embeddings
- Implements semantic search functionality
Renderer Process (React)
The renderer process (src/
) is organized into:
- Components (
components/
) - Contexts (
contexts/
) - Custom hooks (
hooks/
) - Type definitions (
electron.d.ts
)
Key Components
-
ChatPanel
- Handles user queries and LLM responses
- Manages conversation history
- Implements message rendering
-
FileExplorer
- Directory selection and navigation
- File list visualization
- File metadata display
-
ScanningPanel
- Progress visualization for file scanning
- Status updates
- Error handling
Adding New Features
Adding a New LLM Provider
- Create a new service in
electron/services/
- Implement the provider interface:
interface LLMProvider { initialize(): Promise<void>; query(prompt: string): Promise<string>; streamResponse(prompt: string): AsyncGenerator<string>; }
- Add provider configuration to
store.ts
- Update the settings UI in
SettingsPanel
- Add the provider to the LLM service factory
Adding File Type Support
- Update
fileSystem.ts
with new file type detection - Implement parsing logic in a new service
- Add metadata extraction
- Update the vector store schema if needed
- Add UI support in FileExplorer
Adding a New Panel
- Create component in
src/components/
- Add routing in
App.tsx
- Implement required hooks
- Add IPC handlers if needed
- Update navigation
Development Workflows
Local Development
-
Start Electron development:
npm run dev
This runs:
- Vite dev server for React
- Electron with hot reload
- TypeScript compilation in watch mode
-
Debug main process:
- Use VSCode launch configuration
- Console logs appear in terminal
- Break points work in VSCode
-
Debug renderer process:
- Use Chrome DevTools (Cmd/Ctrl+Shift+I)
- React DevTools available
- Network tab shows IPC calls
Testing
-
Unit Tests:
- Located in
__tests__
directories - Run with
npm test
- Focus on service logic
- Located in
-
Integration Tests:
- Test IPC communication
- Verify file system operations
- Check LLM integration
-
E2E Tests:
- Use Playwright
- Test full user workflows
- Verify cross-platform behavior
Best Practices
TypeScript
- Use strict type checking
- Define interfaces for all IPC messages
- Avoid
any
- use proper types - Use discriminated unions for state
React Components
- Use functional components
- Implement proper error boundaries
- Memoize expensive computations
- Use proper prop types
Electron
- Validate IPC messages
- Handle window state properly
- Implement proper error handling
- Use proper security practices
State Management
- Use contexts for shared state
- Implement proper loading states
- Handle errors gracefully
- Use proper TypeScript types
Common Tasks
Adding an IPC Handler
-
Define types in
preload-types.ts
:interface IPCHandlers { newHandler: (arg: ArgType) => Promise<ReturnType>; }
-
Implement handler in
ipc/handlers.ts
:ipcMain.handle('newHandler', async (event, arg: ArgType) => { // Implementation });
-
Add to preload script:
newHandler: (arg: ArgType) => ipcRenderer.invoke('newHandler', arg)
-
Use in renderer:
const result = await window.electron.newHandler(arg);
Updating the Database Schema
- Create migration in
electron/services/vectorStore.ts
- Update type definitions
- Implement data migration
- Update queries
- Test migration
Adding Settings
- Add to store schema in
store.ts
- Update settings component
- Implement validation
- Add migration if needed
- Update relevant services
Troubleshooting
Common Issues
-
IPC Communication Failures
- Check handler registration
- Verify type definitions
- Check error handling
-
File System Issues
- Verify permissions
- Check path handling
- Validate file operations
-
LLM Integration
- Verify API keys
- Check network connectivity
- Validate response handling
Performance Optimization
-
Main Process
- Profile file system operations
- Optimize database queries
- Implement proper caching
-
Renderer Process
- Use React.memo for expensive components
- Implement virtual scrolling
- Optimize re-renders
Release Process
- Update version in
package.json
- Run full test suite
- Build production version
- Test packaged application
- Create release notes
- Tag release in git
- Build installers
- Publish release
Contributing
- Fork the repository
- Create feature branch
- Follow code style
- Add tests
- Submit pull request
Remember to:
- Follow TypeScript best practices
- Add proper documentation
- Include tests
- Update this guide as needed