|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Op Notes is a surgical notes management desktop application for hospitals built with Electron, React, and SQLite. It manages patient records, surgery notes, doctor information, and follow-up records. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +pnpm install # Install dependencies |
| 13 | +pnpm dev # Development mode with hot reload |
| 14 | +pnpm build # Full build with typecheck |
| 15 | +pnpm lint # ESLint with auto-fix |
| 16 | +pnpm typecheck # TypeScript compilation check |
| 17 | +pnpm format # Run prettier formatter |
| 18 | +pnpm build:mac # Build macOS app |
| 19 | +pnpm build:win # Build Windows installer |
| 20 | +pnpm build:linux # Build Linux packages |
| 21 | +``` |
| 22 | + |
| 23 | +## Architecture |
| 24 | + |
| 25 | +### Electron Process Structure |
| 26 | + |
| 27 | +``` |
| 28 | +Main Process (src/main/) |
| 29 | +├── index.ts # Window creation, auto-update, IPC setup |
| 30 | +├── api.ts # Centralized IPC handler routing |
| 31 | +├── db.ts # Kysely + SQLite initialization |
| 32 | +├── db/migrations/ # Database schema migrations |
| 33 | +└── repository/ # Data access layer (patient.ts, doctor.ts, surgery.ts) |
| 34 | +
|
| 35 | +Preload (src/preload/) |
| 36 | +└── index.ts # Context bridge exposing window.api.invoke() |
| 37 | +
|
| 38 | +Renderer Process (src/renderer/src/) |
| 39 | +├── main.tsx # React root with router, QueryClient, providers |
| 40 | +├── routes/ # Page components (patients/, doctors/, surgeries/, settings/) |
| 41 | +├── components/ # UI components (ui/ for Radix/Shadcn, domain-specific folders) |
| 42 | +├── contexts/ # React Context providers |
| 43 | +├── hooks/ # Custom React hooks |
| 44 | +└── lib/queries.ts # React Query key factory |
| 45 | +``` |
| 46 | + |
| 47 | +### IPC Communication Pattern |
| 48 | + |
| 49 | +All renderer-to-main communication uses a single IPC channel: |
| 50 | +```typescript |
| 51 | +// Renderer calls: |
| 52 | +window.api.invoke('methodName', ...args) |
| 53 | + |
| 54 | +// Main process handles in api.ts: |
| 55 | +ipcMain.handle('invokeApiCall', (event, method, ...args) => api[method](...args)) |
| 56 | +``` |
| 57 | + |
| 58 | +API methods return `{ result }` on success or `{ error }` on failure. |
| 59 | + |
| 60 | +### Database |
| 61 | + |
| 62 | +- **Engine**: SQLite with better-sqlite3, Kysely query builder |
| 63 | +- **Location**: `~/.opnotes/data.db` |
| 64 | +- **Tables**: patients, doctors, surgeries, surgery_followups, surgery_doctors_done_by, surgery_doctors_assisted_by, app_settings |
| 65 | +- **FTS tables**: patients_fts, surgeries_fts, doctors_fts for full-text search |
| 66 | +- **Migrations**: Code-based in `src/main/db/migrations/` |
| 67 | + |
| 68 | +### Key Type Definitions |
| 69 | + |
| 70 | +- Database schema types: `src/shared/types/db.d.ts` |
| 71 | +- API filter types: `src/shared/types/api.d.ts` |
| 72 | +- Preload API types: `src/preload/index.d.ts` |
| 73 | + |
| 74 | +### State Management |
| 75 | + |
| 76 | +- **Server state**: React Query with 10-second stale time |
| 77 | +- **Forms**: React Hook Form with Zod validation |
| 78 | +- **Global settings**: React Context (SettingsContext) |
| 79 | +- **Routing**: React Router with hash-based routing |
| 80 | + |
| 81 | +### Printing |
| 82 | + |
| 83 | +Separate print window loads `src/renderer/print.html`. Data passed via IPC `printData` event. Templates use Handlebars in `resources/templates/`. |
| 84 | + |
| 85 | +## Tech Stack |
| 86 | + |
| 87 | +- Electron 28 + electron-vite |
| 88 | +- React 18 + TypeScript 5.3 |
| 89 | +- Kysely (type-safe SQL) + better-sqlite3 |
| 90 | +- Tailwind CSS + Radix UI + Shadcn components |
| 91 | +- TipTap for rich text editing |
| 92 | +- React Query for data fetching |
0 commit comments