Repository Structure
Package Manager
Brainbox uses npm workspaces for dependency management:Turborepo Configuration
Location:turbo.json
Task Dependencies
^build: Depends on dependencies being built firstdependsOn: Ensures correct execution orderoutputs: Cached build artifactsinputs: Files that trigger rebuilds
Applications
apps/server
Fastify API server with WebSocket support for real-time sync. Location:apps/server/
Package Configuration
Directory Structure
Key Features
- REST API: HTTP endpoints for authentication, file uploads
- WebSocket API: Real-time sync protocol
- Background jobs: Email, file processing, cleanup
- Database migrations: Schema versioning
apps/web
React web application with SQLite WASM. Location:apps/web/
Package Configuration
Directory Structure
Key Features
- SQLite WASM: Browser-based database with OPFS storage
- Service Worker: Offline support and caching
- PWA: Installable progressive web app
- Code splitting: Lazy-loaded routes
apps/desktop
Electron desktop application with native SQLite. Location:apps/desktop/
Package Configuration
Directory Structure
Key Features
- better-sqlite3: Native SQLite performance
- IPC communication: Main/renderer process bridge
- Auto-update: Electron’s built-in updater
- Native menus: OS-native application menus
Shared Packages
packages/core
Shared types, schemas, and business logic used across all apps. Location:packages/core/
Package Configuration
Directory Structure
Exports
packages/crdt
Yjs CRDT wrapper for conflict-free merging. Location:packages/crdt/
Package Configuration
Exports
packages/client
Client sync engine, database, queries, and mutations. Location:packages/client/
Package Configuration
Directory Structure
Usage
packages/ui
Shared component library built on Radix UI. Location:packages/ui/
Package Configuration
Components
Usage
Dependency Graph
Build System
TypeScript Configuration
Shared base configuration:Build Tools
- tsup: Fast TypeScript bundler for packages
- Vite: Fast build tool for web app
- Electron Forge: Desktop app packaging
- tsx: TypeScript execution for server dev mode
Build Commands
Development Workflow
Starting Development Servers
Adding a New Package
- Create package directory:
- Add
package.json:
- Add
tsconfig.json:
- Install from root:
Internal Package Dependencies
Reference other workspace packages using* version:
Testing
All packages use Vitest:Linting and Formatting
ESLint Configuration
Root.eslintrc.json:
Prettier Configuration
.prettierrc:
Commands
Continuous Integration
GitHub Actions workflow:Performance
Build Caching
Turborepo caches build outputs:.turbo/.
Parallel Execution
Independent tasks run in parallel:Best Practices
Package Organization
- Keep packages focused: Each package has a single responsibility
- Minimize dependencies: Avoid circular dependencies
- Export intentionally: Use explicit exports in package.json
Versioning
- Workspace protocol: Use
*for internal dependencies - Semantic versioning: Follow semver for public packages
- Coordinated releases: Version all packages together
Code Sharing
- Core for shared logic: Put reusable code in
@brainbox/core - Avoid duplication: Extract common patterns to packages
- Type safety: Use TypeScript across all packages
Next Steps
- Architecture Overview - High-level system design
- Local-First Architecture - Client databases
- Sync Engine - WebSocket sync protocol
- CRDT Implementation - Conflict resolution