# CLAUDE.md Tia - Baby Tracking App. Next.js 16, PostgreSQL, offline-first. ## Build Rule **ALWAYS run `npm run build` before pushing.** Fix errors locally first. ## Project Status - ✅ Fast-log (feed/sleep/diaper + offline queue) - ✅ PWA manifest + service worker - ✅ Vaccinations (IAP schedule) - ✅ Growth tracking - ✅ Memories gallery (placeholder) - ✅ AI chat (LiteLLM) - ✅ Dark mode toggle - ✅ Menu navigation - ⏳ Cloudflare R2 upload (needs credentials) - ⏳ Telegram alerts ## Key Files | Path | Purpose | |------|---------| | `src/app/page.tsx` | Home with quick log, dark mode toggle | | `src/app/menu/page.tsx` | Navigation drawer | | `src/app/medical/page.tsx` | IAP vaccination schedule | | `src/app/ai/page.tsx` | LiteLLM chat | | `src/app/api/logs/route.ts` | Feed/sleep/diaper logging | | `src/app/api/ai/route.ts` | LLM API proxy | | `src/db/schema/logs.ts` | Log schemas | | `public/sw.js` | Service worker for offline | ## Routes - `/` - Home - `/menu` - Navigation - `/settings` - Settings + dark mode - `/medical` - Vaccinations - `/growth` - Growth records - `/memories` - Photo gallery - `/ai` - AI chat - `/api/logs` - Log entries (type=feed|sleep|diaper) - `/api/ai` - AI chat ## Conventions ### API Pattern ```typescript // GET with query params, POST with JSON body export async function GET(request: Request) { const { searchParams } = new URL(request.url); const id = searchParams.get("id"); // use sql.unsafe() for raw queries } export async function POST(request: Request) { const body = await request.json(); // use sql.unsafe() with parameterized values } ``` ### UI Pattern ```typescript "use client"; import { useState, useEffect } from "react"; // dark mode: document.documentElement.classList.toggle("dark") // links: use not router.push() ``` ### Database - Use `sql.unsafe()` not `db.execute()` - postgres-js method - Dates: `new Date().toISOString()` string format - Enums: create manually, no IF NOT EXISTS support ## Local Dev ```bash cd tia npm run dev ``` ## Deployment Auto-deploys via webhook on Git push. Database tables created via `/api/setup`. ## Environment ``` DATABASE_URL=postgresql://user:pass@host:5432/db OPENAI_API_BASE_URL=http://litellm-gateway:4000/v1 LITELLM_MASTER_KEY=sk-tiger-gateway-... ```