How cryptotweezer/pitsypet works
Purpose and Runtime
This is a Next.js App Router application for pet-health management: authenticated users manage pet records, medications, symptoms, appointments, veterinary contacts, and AI-assisted health assessments. It runs as a TypeScript web application with server-rendered routes, client components, and route-handler APIs.
• src/app/layout.tsx
• src/app/page.tsx
• src/middleware.ts
Route Domains and User Entry Points
The public landing page leads into separate authenticated application and dashboard route groups. Pet-centric workflows use slugged pet URLs and assessment IDs/sequences; account, billing, clinic, history, and appointment views live under the dashboard.
• src/app/(app)/pets/[slug]/page.tsx
• src/app/(app)/assessment/[id]/page.tsx
• src/app/(dashboard)/dashboard/page.tsx
Identity, Authorization, and Data Boundary
Supabase is the primary backend boundary for authentication and Postgres persistence. Middleware and server/client/admin Supabase adapters establish request-specific access; migrations define profiles, pets, assessments, medical records, vector knowledge, search, and row-level-security policies.
• src/lib/supabase/middleware.ts
• src/lib/supabase/server.ts
• supabase/migrations/20260619001200_rls_policies.sql
Pet Medical Record Lifecycle
The pet API is the core record-management surface: it owns pet CRUD, soft-delete/restore/purge operations, and nested appointment, medication, and active-symptom resources. UI forms and sections consume this domain, while validation modules define request boundaries.
• src/app/api/pets/[id]/route.ts
• src/app/api/pets/[id]/symptoms/reconcile/route.ts
• src/components/pets/pet-form.tsx
Assessment and AI Triage Pipeline
Assessment routes orchestrate conversational symptom collection, classification/safety controls, retrieval-augmented veterinary knowledge, formatting, and fallback behavior. Results are persisted/displayed as clinical reasoning, risk, recommendations, and emergency guidance; assessment output can be exported for veterinary use.
• src/app/api/assessment/chat/route.ts
• src/lib/ai/rag.ts
• src/components/assessment/results/results-view.tsx
Knowledge Retrieval and Safety Controls
The AI layer is explicitly decomposed into schemas, classification, embeddings, RAG, safety, cost controls, and fallback handling. Supabase migrations provide veterinary knowledge, first-aid/emergency content, vector search, and audit support; these form the grounding boundary rather than treating model output as standalone advice.
• src/lib/ai/safety.ts
• src/lib/ai/embed.ts
• supabase/migrations/20260619001000_vector_search_function.sql
External Services and Operational Integrations
Stripe supports subscription checkout, billing portal access, and webhook-driven billing state. PostHog provides client analytics; Sentry instrumentation supports error monitoring; Arcjet/rate-limit utilities indicate request protection. Assessment export produces a vet-oriented document/summary.
• src/app/api/billing/webhook/route.ts
• src/lib/stripe.ts
• src/instrumentation.ts
Main entry points: page.tsx Pet app routes · chat/route.ts Assessment chat API · server.ts Supabase server adapter · [id]/route.ts Pet record API
Components 19
Next.js Web App
- Landing page · Entry point into authenticated product areas.
src/app/page.tsx - Pet app routes · Pet-centric pages use pet slugs and assessment IDs.
src/app/(app)/pets/[slug]/page.tsx - Dashboard · Account, billing, clinic, history, and appointment views.
src/app/(dashboard)/dashboard/page.tsx - Request middleware · Establishes request authentication and route access.
src/middleware.ts
Pet Records
- Pet record API · Owns pet lifecycle and nested medical resources.
src/app/api/pets/[id]/route.ts - Symptom reconciliation · Updates active symptoms within the pet record lifecycle.
src/app/api/pets/[id]/symptoms/reconcile/route.ts - Pet forms · Creates and edits pet records from the UI.
src/components/pets/pet-form.tsx
Assessment AI
- Assessment chat API · Orchestrates conversational symptom assessment and result persistence.
src/app/api/assessment/chat/route.ts - Safety controls · Applies classification, safety, cost, and fallback controls.
src/lib/ai/safety.ts - Veterinary RAG · Grounds assessment reasoning in retrieved veterinary knowledge.
src/lib/ai/rag.ts - Knowledge embeddings · Builds vector representations for knowledge retrieval.
src/lib/ai/embed.ts - Assessment results · Displays clinical reasoning, risk, recommendations, and emergency guidance.
src/components/assessment/results/results-view.tsx
Data & Identity
- Supabase server adapter · Provides request-scoped authenticated database access.
src/lib/supabase/server.ts - Supabase Auth & Postgres · Primary identity and persistence boundary with row-level security.
- RLS policies · Defines protected access to profiles, pets, assessments, and records.
supabase/migrations/20260619001200_rls_policies.sql - Vector search · Provides veterinary knowledge retrieval over vector data.
supabase/migrations/20260619001000_vector_search_function.sql
Billing & Operations
- Stripe billing · Manages subscriptions, checkout, portal, and billing state.
src/lib/stripe.ts - Billing webhook · Applies Stripe billing events to application state.
src/app/api/billing/webhook/route.ts - Error monitoring · Initializes Sentry operational error monitoring.
src/instrumentation.ts
Connections 24
- Landing page → Pet app routes: sign in
- Landing page → Dashboard: sign in
- Request middleware → Pet app routes: guards
- Request middleware → Dashboard: guards
- Request middleware → Supabase server adapter: auth context
- Pet app routes → Pet forms: renders
- Pet forms → Pet record API: manages pets
- Pet app routes → Pet record API: loads records
- Pet record API → Symptom reconciliation: active symptoms
- Pet record API → Supabase server adapter: persists
- Assessment chat API → Safety controls: screens input/output
- Assessment chat API → Veterinary RAG: grounds reasoning
- Veterinary RAG → Knowledge embeddings: queries vectors
- Veterinary RAG → Vector search: retrieves knowledge
- Assessment chat API → Supabase server adapter: stores assessment
- Pet app routes → Assessment chat API: submits assessment
- Assessment chat API → Assessment results: returns triage
- Supabase server adapter → Supabase Auth & Postgres: accesses
- RLS policies → Supabase Auth & Postgres: protects data
- Vector search → Supabase Auth & Postgres: extends search
- Dashboard → Stripe billing: billing actions
- Billing webhook → Stripe billing: receives events
- Billing webhook → Supabase server adapter: updates billing state
- Error monitoring → Pet app routes: monitors errors