CLAUDE.md
Guides Claude Code on build commands, architecture, and patterns for a React PWA with offline-first data sync.
What this file does
Guides Claude Code on build commands, architecture, and patterns for a React PWA with offline-first data sync.
When to use it
- Adding Claude Code support to a React TypeScript PWA
- Documenting offline-first architecture with IndexedDB and sync queue
- Setting up project conventions for a monorepo or single-page app
- Onboarding new developers to a complex frontend codebase
Assumes this stack
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Build and Development Commands
# Development
npm run dev # Start Vite dev server with HMR (http://localhost:5173)
# Build
npm run build # TypeScript compile + Vite production build
# Quality Checks
npm run lint # Run ESLint for code quality
# Preview Production Build
npm run preview # Preview production build locally
Architecture Overview
Core Stack
- React 18 with TypeScript for type-safe component development
- Vite as build tool with SWC for fast transpilation
- Progressive Web App (PWA) with offline-first architecture using Workbox
- IndexedDB via Dexie for client-side data persistence
- Zustand for lightweight state management
Key Architectural Patterns
Offline-First Data Flow
- Local Storage: All data operations write to IndexedDB first via
src/lib/db.ts - Sync Queue: Changes tracked in
syncQueuetable for eventual consistency - Background Sync:
SyncServicehandles bidirectional sync when online - Conflict Resolution: Last-write-wins strategy for concurrent edits
State Management Structure
- Global App State:
src/stores/useAppStore.ts- User auth, settings, sync status - Local Persistence: Zustand middleware persists to localStorage
- Database Layer: Dexie wraps IndexedDB with reactive queries
Component Architecture
- UI Components:
src/components/ui/- shadcn/ui base components (Button, Card, etc.) - Page Components:
src/pages/- Route-level components with lazy loading - Lazy Loading: Custom retry mechanism in
src/utils/lazyLoading.tsx - Error Boundaries: Graceful error handling at component tree level
PWA Implementation
Service Worker Strategy
- Auto-update: New versions automatically installed
- Caching: Static assets cached for offline use
- Manifest: Configured in
vite.config.tswith PWA plugin
Key PWA Files
src/components/PWAInstallPrompt.tsx- Install prompt handlervite.config.ts- PWA manifest and Workbox configuration
Data Models
Inspection Entity (src/lib/db.ts)
Primary business entity with:
- UUID for cross-device sync
- Readings (temperature, pressure, flow, vibration)
- Photo attachments (base64 encoded)
- Sync status tracking
Sync Queue
Tracks pending operations:
- Entity reference (UUID)
- Operation type (create/update/delete)
- Snapshot of data at queue time
Critical Services
SyncService (src/services/syncService.ts)
- Bidirectional sync with retry logic
- Batch processing (50 items per batch)
- Exponential backoff on failures
- Conflict resolution via timestamp comparison
Analytics & Error Tracking
- Amplitude for analytics (
src/services/analyticsService.ts) - Sentry for error monitoring (integrated in
App.tsx)
Routing & Navigation
- React Router v6 with browser router
- Bottom navigation bar (
src/components/Navigation.tsx) - Dynamic default view based on user settings
- Routes: Dashboard, Scanner, Viewer3D, Inspections, Settings
3D Visualization
- Three.js with React Three Fiber
- Located in
src/pages/Viewer3D.tsx - Interactive 3D models for plant inspection
Performance Optimizations
- Route-based code splitting with retry logic
- Virtual scrolling for large lists (
src/components/VirtualList.tsx) - Performance monitoring hooks in
src/hooks/ - Manual vendor chunking in Vite config
Path Aliases
@/maps tosrc/directory (configured invite.config.ts)
Security Headers
Configured in Vite dev server:
- Strict Transport Security
- X-Frame-Options: DENY
- Content Security Policy
- Camera/microphone permissions for PWA features
What's inside
5 sections: build commands, architecture overview, PWA implementation, data models, critical services.
Change this for your project
- Replace
AeyeOps/plant-vision-mobilewith your repository name - Replace
src/lib/db.tswith your own database module path - Replace
src/services/syncService.tswith your sync service path - Replace
src/services/analyticsService.tswith your analytics service path
Where it goes
Save as CLAUDE.md in your repository root. Claude Code reads it automatically at the start of every session.
Worth borrowing
- Offline-first data flow with local IndexedDB writes and sync queue for eventual consistency
- Route-based code splitting with retry mechanism for lazy loading
- Zustand store with localStorage persistence for global app state
Related Documents
Code indexing for AI agents: summarization strategies and evaluation systems
Synthesises 2024-2025 research on code indexing for AI agents, covering summarisation strategies, hybrid retrieval architectures, and evaluation benchmarks.
write-script
Guides an AI through writing a YouTube video script with strict structural, language, and quiz rules for a survival channel.
Claude AI Git Workflow Integration
Recommends using the git-ai-commit CLI tool for AI-generated commit messages instead of manual ones.
Missing Business Agents Research — FLUXION 2026
Identifies 12 missing business operations agents for an indie software company and ranks them by impact and effort with €0 implementation plans.