diff --git a/README.md b/README.md index c8256d2..dbcb5ea 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,31 @@ A reactive, interactive dog breeding genealogy mapping system for professional k - **✅ Branded Navigation** - Custom logo (br-logo.png) with gold-to-rusty-red gradient title - **✅ Trial Pairing Simulator** - COI calculator with common ancestors table and risk badge - **✅ Heat Cycle Calendar** - Month grid calendar with cycle windows, breeding date suggestions, and **projected whelping identifiers** +- **✅ Champion Bloodline Tracking** - Mark dogs as titled champions; offspring display a Champion Bloodline badge +- **✅ Kennel Settings** - Configurable kennel name, tagline, address, AKC ID, breed, owner info +- **✅ UI Theme** - CSS custom property theming with `--champion-gold` and dark-mode variables ### Database Architecture -- **✅ Clean Schema** - No migrations, fresh installs create correct structure +- **✅ Clean Schema** - No migrations needed; fresh installs create correct structure; existing DBs auto-migrate via safe `ALTER TABLE` guards - **✅ Normalized Design** - `parents` table for relationships (sire/dam) - **✅ Litter Linking** - Dogs linked to litters via `litter_id` - **✅ Health Records** - Medical history and genetic testing - **✅ Heat Cycles** - Breeding cycle tracking - **✅ Genetic Traits** - Inherited trait mapping +- **✅ Settings Table** - Single-row kennel configuration with all contact/identity fields -### Recently Added (March 9, 2026 — v0.5.1) +### Recently Added (March 9, 2026 — v0.6.0) +- **✅ Champion Flag** — `is_champion INTEGER DEFAULT 0` on `dogs` table; safe `ALTER TABLE` migration guard for existing DBs +- **✅ Champion Toggle in DogForm** — amber-gold highlighted checkbox row with `Award` icon; marks dog as titled champion +- **✅ Champion ✪ in Parent Dropdowns** — sire/dam selects append `✪` to champion names for at-a-glance visibility +- **✅ Champion Bloodline Badge** — offspring of champion parents display a badge on dog cards and detail pages +- **✅ Kennel Settings API** — `GET/PUT /api/settings` with single-row column schema and ALLOWED_KEYS whitelist +- **✅ Settings Table Migration** — all kennel fields added with safe `ALTER TABLE` guards on existing DBs; default seed row auto-created +- **✅ SettingsProvider / useSettings** — React context hook renamed `useSettings.jsx` (was `.js`; contained JSX causing Vite build failure) +- **✅ `server/index.js` Fix** — `initDatabase()` called with no args to match updated `db/init.js`; removed duplicate `/api/health` route +- **✅ `settings.js` Route Fix** — rewrote from double-encoded base64 + old key/value schema to correct single-row column schema + +### Previously Added (March 9, 2026 — v0.5.1) - **✅ Projected Whelp Window on Calendar** - Indigo/purple day cells (days 58–65 from breeding date) visible directly on the month grid - **✅ Expected Whelp Day Marker** - Indigo dot on the exact expected whelp day (day 63) alongside the green breeding dot - **✅ "[Name] due" Cell Label** - Baby 🍼 icon + dog name label inside the whelp day cell @@ -57,9 +72,9 @@ A reactive, interactive dog breeding genealogy mapping system for professional k - **Frontend**: React 18 with modern component design - **Visualization**: React-D3-Tree for pedigree charts - **Backend**: Node.js/Express API -- **Database**: SQLite (embedded, zero-config) with clean normalized schema +- **Database**: SQLite (embedded, zero-config) with clean normalized schema + safe `ALTER TABLE` migration guards - **Container**: Single Docker image with multi-stage build -- **Styling**: CSS custom properties with dark theme + gradient branding +- **Styling**: CSS custom properties with dark theme + `--champion-gold` + gradient branding ## Quick Start @@ -79,30 +94,21 @@ docker-compose up -d Access at: `http://localhost:3000` -### Fresh Install Database Setup +### Upgrading an Existing Installation -For a **fresh install**, the database will automatically initialize with the correct schema. - -For an **existing installation upgrade**: +The database now uses safe `ALTER TABLE` guards — **you do not need to delete your database to upgrade**. Just pull and rebuild: ```bash -# Stop the application docker-compose down - -# Backup your data -cp data/breedr.db data/breedr.db.backup - -# Delete old database (it will be recreated) -rm data/breedr.db - -# Pull latest code git pull origin master - -# Rebuild and restart docker-compose up -d --build ``` -The app will create a fresh database with the clean schema automatically. +New columns (`is_champion`, all `settings` kennel fields) are added automatically on first boot. Your existing dog data is preserved. + +### Fresh Install Database Setup + +For a **fresh install**, the database will automatically initialize with the correct schema and seed a default settings row. ## Database Schema @@ -111,15 +117,17 @@ The app will create a fresh database with the clean schema automatically. 1. **No sire/dam columns in `dogs` table** - Parent relationships stored in `parents` table 2. **Normalized structure** - Reduces redundancy, improves data integrity 3. **Litter linking** - Dogs reference litters via `litter_id` foreign key +4. **Safe migrations** - `ALTER TABLE ... ADD COLUMN` guards allow zero-downtime upgrades ### Core Tables -- **dogs** - Core dog registry (NO sire_id/dam_id columns) +- **dogs** - Core dog registry; includes `is_champion`, `litter_id`, `photo_urls` - **parents** - Sire/dam relationships (dog_id, parent_id, parent_type) - **litters** - Breeding records with sire/dam references - **health_records** - Medical and genetic testing - **heat_cycles** - Breeding cycle tracking - **traits** - Genetic trait mapping +- **settings** - Single-row kennel configuration (kennel_name, tagline, address, phone, email, website, akc_id, breed, owner_name) **Full schema documentation:** [DATABASE.md](DATABASE.md) @@ -127,8 +135,9 @@ The app will create a fresh database with the clean schema automatically. - `NODE_ENV` - production/development (default: production) - `PORT` - Server port (default: 3000) -- `DB_PATH` - SQLite database path (default: /app/data/breedr.db) +- `DATA_DIR` - Data directory for SQLite file (default: /app/data) - `UPLOAD_PATH` - Upload directory (default: /app/uploads) +- `STATIC_PATH` - Static assets directory (default: /app/static) ## Development @@ -149,32 +158,39 @@ npm run build ``` breedr/ -├── client/ # React frontend +├── client/ # React frontend │ ├── src/ │ │ ├── pages/ │ │ │ ├── BreedingCalendar.jsx # Heat cycle calendar + whelping identifiers │ │ │ ├── PairingSimulator.jsx # Trial pairing + COI +│ │ │ ├── SettingsPage.jsx # Kennel settings form │ │ │ ├── Dashboard.jsx │ │ │ ├── DogList.jsx │ │ │ ├── DogDetail.jsx │ │ │ ├── PedigreeView.jsx │ │ │ └── LitterList.jsx -│ ├── public/ +│ │ ├── components/ +│ │ │ └── DogForm.jsx # Champion toggle + parent selects +│ │ ├── hooks/ +│ │ │ └── useSettings.jsx # SettingsProvider + useSettings context +│ │ └── App.jsx │ └── package.json -├── server/ # Node.js backend +├── server/ # Node.js backend │ ├── routes/ -│ │ ├── breeding.js # Heat cycles, whelping, suggestions -│ │ ├── pedigree.js # COI, trial pairing -│ │ ├── dogs.js -│ │ └── litters.js +│ │ ├── dogs.js # is_champion in all queries +│ │ ├── settings.js # GET/PUT kennel settings (single-row schema) +│ │ ├── breeding.js # Heat cycles, whelping, suggestions +│ │ ├── pedigree.js # COI, trial pairing +│ │ ├── litters.js +│ │ └── health.js │ ├── db/ -│ │ └── init.js # Clean schema (NO migrations) +│ │ └── init.js # Schema + ALTER TABLE migration guards │ └── index.js -├── static/ # Branding assets (br-logo.png, etc.) -├── docs/ # Documentation -├── DATABASE.md # Schema documentation -├── ROADMAP.md # Development roadmap -├── Dockerfile # Multi-stage Docker build +├── static/ # Branding assets (br-logo.png, etc.) +├── docs/ # Documentation +├── ROADMAP.md +├── DATABASE.md +├── Dockerfile ├── docker-compose.yml └── README.md ``` @@ -183,9 +199,14 @@ breedr/ ### Dogs - `GET/POST /api/dogs` - Dog CRUD operations -- `GET /api/dogs/:id` - Get dog with parents and offspring +- `GET /api/dogs/:id` - Get dog with parents (incl. is_champion), offspring, and health summary +- `PUT /api/dogs/:id` - Update dog (incl. is_champion) - `POST /api/dogs/:id/photos` - Upload photos +### Settings +- `GET /api/settings` - Get kennel settings +- `PUT /api/settings` - Update kennel settings (partial update supported) + ### Pedigree & Genetics - `GET /api/pedigree/:id` - Generate pedigree tree - `POST /api/pedigree/trial-pairing` - COI + common ancestors + risk recommendation @@ -207,68 +228,37 @@ breedr/ - `GET /static/*` - Branding and static assets - `GET /uploads/*` - Dog photos -## Upgrading - -### From Earlier Versions - -If you have an **old database with sire/dam columns** or missing litter_id: - -```bash -# Backup your data -cp data/breedr.db data/breedr.db.backup - -# Delete old database -rm data/breedr.db - -# Pull latest code -git pull - -# Restart (will create clean schema) -docker-compose restart -``` - -**Important:** The new schema uses a `parents` table instead of sire/dam columns. Parent data cannot be automatically migrated - you'll need to re-enter parent relationships. - ## Troubleshooting +### Server crashes with `SyntaxError: Unexpected end of input` on `settings.js` +The settings route file may have been corrupted (double-encoded base64). Pull the latest code and rebuild. + +### "no such column: kennel_name" or "no such column: is_champion" +Your database predates the `ALTER TABLE` migration guards. Pull the latest code and restart — columns are added automatically. No data loss. + ### "no such column: weight" or "no such column: sire_id" - -Your database has an old schema. Delete and recreate: - +Your database has a very old schema. Delete and recreate: ```bash +cp data/breedr.db data/breedr.db.backup rm data/breedr.db docker-compose restart ``` -### Parent relationships not saving - -Check server logs for: -``` -✔ Dog inserted with ID: 123 - Adding sire relationship: dog 123 -> sire 5 - ✔ Sire relationship added -``` - -If you don't see these logs, ensure `sire_id` and `dam_id` are being sent in the API request. - ### Logo not appearing in navbar - Ensure `br-logo.png` is placed in the `static/` directory at the project root. The file is served at `/static/br-logo.png`. ### Heat cycles not showing on calendar - Ensure dogs are registered with `sex: 'female'` before creating heat cycles. The API validates this and will return a 400 error for male dogs. ### Whelping window not appearing on calendar - -A breeding date must be logged on the cycle for whelp window cells to appear. Use the Cycle Detail modal → "Log Breeding Date" field. The whelp preview appears client-side instantly; the calendar cells populate after save. +A breeding date must be logged on the cycle for whelp window cells to appear. Use the Cycle Detail modal → "Log Breeding Date" field. ## Roadmap ### ✅ Completed - [x] Docker containerization -- [x] SQLite database with clean schema -- [x] Dog management (CRUD) +- [x] SQLite database with clean schema + ALTER TABLE migration guards +- [x] Dog management (CRUD) with champion flag - [x] Photo management - [x] Interactive pedigree visualization - [x] Litter management @@ -280,8 +270,10 @@ A breeding date must be logged on the cycle for whelp window cells to appear. Us - [x] Trial Pairing Simulator (COI + common ancestors + risk badge) - [x] Heat Cycle Calendar (month grid + windows + breeding suggestions + whelping estimate) - [x] **Projected Whelping Calendar Identifier** (whelp window cells, due label, active card range, live modal preview, whelping banner) +- [x] **Champion Bloodline Tracking** (is_champion flag, DogForm toggle, offspring badge) +- [x] **Kennel Settings** (GET/PUT /api/settings, SettingsProvider, kennel name in navbar) -### 🔧 In Progress / Up Next +### 🔜 In Progress / Up Next - [ ] Health Records System - [ ] Genetic trait tracking @@ -295,6 +287,19 @@ A breeding date must be logged on the cycle for whelp window cells to appear. Us ## Recent Updates +### March 9, 2026 - Champion Bloodline, Settings, Build Fixes (v0.6.0) +- **Added:** `is_champion` column to `dogs` table with safe `ALTER TABLE` migration guard +- **Added:** Champion toggle checkbox in DogForm with amber-gold highlight and `Award` icon +- **Added:** `✪` suffix on champion sire/dam in parent dropdowns +- **Added:** Champion Bloodline badge on offspring cards/detail pages +- **Added:** `GET/PUT /api/settings` route — single-row column schema with `ALLOWED_KEYS` whitelist +- **Added:** Full kennel settings columns in `settings` table with migration guards +- **Added:** `SettingsProvider` / `useSettings` React context for kennel name in navbar +- **Fixed:** `useSettings.js` → `useSettings.jsx` (Vite build failure — JSX in `.js` file) +- **Fixed:** `server/index.js` — `initDatabase()` called with no args; removed duplicate `/api/health` route +- **Fixed:** `server/routes/settings.js` — rewrote from double-encoded base64 + old key/value schema +- **Fixed:** `DB_PATH` arg removed from `initDatabase()` call; `DATA_DIR` env var now controls directory + ### March 9, 2026 - Projected Whelping Calendar Identifier (v0.5.1) - **Added:** Indigo whelp window (days 58–65) on calendar grid cells when a breeding date is logged - **Added:** Indigo dot marker on exact expected whelp day (day 63) @@ -323,23 +328,6 @@ A breeding date must be logged on the cycle for whelp window cells to appear. Us - **Fixed:** `/static` and `/uploads` paths no longer fall through to React router - **Fixed:** Brand logo sized as fixed 1:1 square for proper aspect ratio -### March 9, 2026 - Clean Database Schema (v0.4.0) -- **Fixed:** Database schema cleaned up - no migrations -- **Fixed:** Removed weight/height columns (never implemented) -- **Fixed:** Proper parent handling via parents table -- **Added:** litter_id column for linking puppies to litters -- **Added:** Comprehensive DATABASE.md documentation -- **Improved:** Server startup with clean initialization - -### March 8, 2026 - UI Redesign & Bug Fixes -- **Fixed:** Microchip field UNIQUE constraint (now properly optional) -- **Redesigned:** Modern dark theme with sleek aesthetics -- **Redesigned:** Compact horizontal info cards (80x80 avatars) -- **Improved:** Dashboard with gradient stats cards -- **Improved:** Navigation bar with glass morphism -- **Added:** Sex-colored icons (blue ♂, pink ♀) -- **Added:** Registration number badges - ## Documentation - [DATABASE.md](DATABASE.md) - Complete schema documentation diff --git a/ROADMAP.md b/ROADMAP.md index 4a66b30..bc3f46b 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -19,13 +19,15 @@ - [x] Indexes and triggers - [x] **litter_id column** for linking puppies to litters - [x] **Clean schema design** - NO migrations, fresh init only +- [x] **Safe ALTER TABLE migration guards** - new columns added automatically on upgrade ### API Endpoints -- [x] `/api/dogs` - Full CRUD operations +- [x] `/api/dogs` - Full CRUD operations (incl. `is_champion`) - [x] `/api/pedigree` - Tree generation and COI calculator - [x] `/api/litters` - Breeding records - [x] `/api/health` - Health tracking - [x] `/api/breeding` - Heat cycles and whelping calculator +- [x] `/api/settings` - Kennel configuration (GET/PUT) - [x] Photo upload with Multer - [x] **Parent relationship handling** via parents table - [x] `/static/*` - Branding and static asset serving @@ -114,8 +116,8 @@ - [x] **Projected Whelping Calendar Identifier** ✅ *(March 9, 2026 — v0.5.1)* - [x] Gestation constants: earliest=58, expected=63, latest=65 days - - [x] `getWhelpDates(cycle)` client-side helper (no extra API call) - - [x] Indigo whelp window cells (days 58–65) on calendar grid + - [x] `getWwhelpDates(cycle)` client-side helper (no extra API call) + - [x] Indigo whelp window cells (days 58–63) on calendar grid - [x] Indigo dot marker on expected whelp day (day 63) - [x] `Baby` icon + "[Name] due" label inside whelp day cells - [x] "Whelp est. [date]" row with range on active cycle cards @@ -127,9 +129,40 @@ --- -## 📋 Phase 4: Health & Genetics (NEXT UP) +## ✅ Phase 4a: Champion & Settings (COMPLETE — v0.6.0) -### Health Records *(Priority 1)* +### Champion Bloodline Tracking +- [x] `is_champion INTEGER DEFAULT 0` column on `dogs` table +- [x] Safe `ALTER TABLE dogs ADD COLUMN is_champion` migration guard +- [x] `is_champion` included in all `GET /api/dogs` + `GET /api/dogs/:id` responses +- [x] `is_champion` persisted in `POST` and `PUT /api/dogs` +- [x] `is_champion` included on sire/dam JOIN queries and offspring query +- [x] Champion toggle checkbox in `DogForm` with amber-gold highlight + `Award` icon +- [x] `✪` suffix on champion names in sire/dam parent dropdowns +- [x] Champion Bloodline badge on offspring cards and dog detail pages + +### Kennel Settings +- [x] `settings` table: `kennel_name`, `kennel_tagline`, `kennel_address`, `kennel_phone`, `kennel_email`, `kennel_website`, `kennel_akc_id`, `kennel_breed`, `owner_name` +- [x] Safe `ALTER TABLE settings ADD COLUMN` migration loop for all kennel fields +- [x] Auto-seed default row (`kennel_name = 'BREEDR'`) if table is empty +- [x] `GET /api/settings` — returns single-row as flat JSON object +- [x] `PUT /api/settings` — partial update via `ALLOWED_KEYS` whitelist +- [x] `SettingsProvider` / `useSettings` React context hook +- [x] Kennel name displayed in navbar from settings +- [x] `SettingsPage` component for editing kennel info + +### Build & Runtime Fixes (v0.6.0) +- [x] `useSettings.js` → `useSettings.jsx` — Vite build failed because JSX in `.js` file +- [x] `server/index.js` — `initDatabase()` called with no args (was passing `DB_PATH`, now path is internal) +- [x] `server/index.js` — removed duplicate `app.get('/api/health')` inline route +- [x] `server/index.js` — `DATA_DIR` env var replaces `path.dirname(DB_PATH)` for directory creation +- [x] `server/routes/settings.js` — rewrote from double-encoded base64 + old key/value schema to correct single-row column schema + +--- + +## 📋 Phase 4b: Health & Genetics (NEXT UP) + +### Health Records *(Priority 1)* 🚨 - [ ] Health records list view per dog - [ ] Add/edit health test results - [ ] Vaccination tracking with expiry alerts @@ -137,12 +170,24 @@ - [ ] Document uploads (PDFs, images) - [ ] Health clearance status badges on dog cards -### Genetic Tracking *(Priority 2)* +**Complexity:** Medium | **Impact:** High | **User Value:** Excellent + +**Why this is recommended:** +- Natural complement to existing dog profiles +- Vaccination expiry alerts are high day-to-day utility +- Clearance badges on dog cards improve trust at a glance +- Builds toward breeding decision support + +**Estimated Time:** 6-8 hours + +### Genetic Trait Tracking *(Priority 2)* - [ ] Track inherited traits - [ ] Color genetics calculator - [ ] Health clearance status - [ ] Link traits to ancestors +**Estimated Time:** 5-7 hours + --- ## 📋 Phase 5: Advanced Features (PLANNED) @@ -236,32 +281,26 @@ --- -## 🌕 Current Sprint: v0.6.0 +## 📅 Current Sprint: v0.7.0 -### ✅ Completed This Sprint (v0.5.1) +### ✅ Completed This Sprint (v0.6.0) +- [x] `is_champion` flag — DB column, API, DogForm toggle, offspring badge, parent dropdown `✪` +- [x] Kennel Settings — `settings` table with all kennel fields, `GET/PUT /api/settings`, `SettingsProvider`, navbar kennel name +- [x] `useSettings.jsx` rename (Vite build fix) +- [x] `server/index.js` fix — `initDatabase()` no-arg call, duplicate health route removed +- [x] `server/routes/settings.js` rewrite — fixed double-encoded base64 + wrong key/value schema + +### ✅ Previously Completed (v0.5.1) - [x] Projected Whelping Calendar Identifier — indigo whelp window cells, due label, active card range, jump-to-month button - [x] Live whelp preview in Cycle Detail modal (client-side, no save required) - [x] Full-width whelping banner for months with projected whelps - [x] "Projected Whelp" legend entry + updated page subtitle -### ✅ Previously Completed (v0.5.0) -- [x] Trial Pairing Simulator — `/pairing` route, COI%, risk badge, common ancestors -- [x] Heat Cycle Calendar — month grid, phase color coding, start-cycle modal -- [x] Cycle Detail modal — breeding windows, inline breeding date, whelping estimate -- [x] New backend endpoints: `GET /heat-cycles`, `GET /heat-cycles/:id/suggestions` -- [x] Removed `progesterone_peak_date` from POST/PUT (moved to extended backlog) +### 🔜 Next Up (Priority Order) -### 🔧 Next Up (Priority Order) - -#### Option 1: Health Records System (Recommended) 💡 +#### Option 1: Health Records System (Recommended) 🚨 **Complexity:** Medium | **Impact:** High | **User Value:** Excellent -**Why this is recommended:** -- Natural complement to existing dog profiles -- Vaccination expiry alerts are high day-to-day utility -- Clearance badges on dog cards improve trust at a glance -- Builds toward breeding decision support - **Tasks:** - Create `HealthRecordForm` component - Health records list/timeline per dog on DogDetail page @@ -276,11 +315,6 @@ #### Option 2: Genetic Trait Tracking **Complexity:** Medium | **Impact:** Medium | **User Value:** Good -**Why consider this:** -- Visual color/coat genetics are important for breeders -- Links naturally to pedigree view -- Useful for marketing/listing dogs - **Tasks:** - Trait entry form (coat color, pattern, carried traits) - Display traits on dog detail page @@ -301,6 +335,9 @@ - [x] Brand logo display and sizing - [x] Gradient title rendering - [x] Static asset serving in prod and dev +- [ ] Champion toggle — DogForm save/load round-trip +- [ ] Champion badge — offspring card display +- [ ] Kennel settings — save + navbar name update - [ ] Trial pairing simulator (end-to-end) - [ ] Heat cycle calendar (start cycle, detail modal, whelping) - [ ] Projected whelping calendar identifier (whelp cells, due label, banner) @@ -314,13 +351,21 @@ ## How to Contribute 1. Pick a feature from "Next Up" above -2. Create a feature branch: `feat/feature-name` +2. Create a feature branch off `master`: `feat/feature-name` 3. Implement with tests 4. Update this roadmap and README.md 5. Submit PR for review ## Version History +- **v0.6.0** (March 9, 2026) - Champion Bloodline, Settings, Build Fixes + - `is_champion` flag on dogs table with ALTER TABLE migration guard + - Champion toggle in DogForm; `✪` suffix in parent dropdowns; offspring badge + - Kennel settings table + `GET/PUT /api/settings` + `SettingsProvider` + - `useSettings.jsx` rename (Vite build fix) + - `server/index.js` fix: `initDatabase()` no-arg, duplicate health route removed + - `server/routes/settings.js` rewrite: double-encoded base64 + wrong schema fixed + - **v0.5.1** (March 9, 2026) - Projected Whelping Calendar Identifier - Indigo whelp window cells (days 58–65) on month grid - Indigo dot marker on exact expected whelp day (day 63) @@ -333,7 +378,7 @@ - **v0.5.0** (March 9, 2026) - Breeding Tools Complete - Trial Pairing Simulator: COI calculator, risk badge, common ancestors - - Heat Cycle Calendar: month grid, phase windows, start-cycle modal + - Heat Cycle Calendar: month grid, phase color coding, start-cycle modal - Cycle Detail: breeding windows, inline breeding date, whelping estimate - New API: `GET /heat-cycles`, `GET /heat-cycles/:id/suggestions` - Progesterone tracking moved to extended backlog