Vetspire

View Source
[![CIMaster](https://github.com/Vetspire-VSP/vetspire/actions/workflows/cd-dev.yml/badge.svg?branch=master)](https://github.com/Vetspire-VSP/vetspire/actions/workflows/cd-dev.yml)
[![E2EStaging](https://github.com/Vetspire-VSP/vetspire/actions/workflows/e2e.yaml/badge.svg?branch=master)](https://github.com/Vetspire-VSP/vetspire/actions/workflows/e2e.yaml)

Coverage

Monorepo for the Vetspire veterinary practice-management platform — a React/TypeScript frontend, an Elixir/Phoenix GraphQL API, cloud functions, and supporting apps.


📑 Contents


🧭 Overview

This is the monorepo for the Vetspire platform, housing both frontend and backend codebases, cloud functions, documentation sites, and deployment scripts.

A set of browser SPAs talk to a single Elixir/Phoenix umbrella API over GraphQL (plus a few REST endpoints), which persists to PostgreSQL, runs background work on Oban, and integrates with labs, payments, and accounting providers.

graph LR
    subgraph Clients["Client SPAs ¡ React ¡ Firebase"]
        WEB["web/"]
        BOOK["online bookers<br/>& kiosks"]
    end
    API["api/<br/>Elixir umbrella<br/>GraphQL ¡ REST ¡ WS<br/>(GKE)"]
    PG[("PostgreSQL 15<br/>+ read replicas")]
    OBAN["Oban workers"]
    FNS["functions/<br/>Cloud Functions"]
    EXT["Labs ¡ Stripe ¡<br/>Intacct ¡ Twilio"]

    WEB & BOOK -->|GraphQL / REST| API
    API --> PG
    API --> OBAN
    OBAN --> EXT
    OBAN --> FNS

📖 For the full architecture — umbrella apps, request lifecycle, CI/CD, and more diagrams — see docs/ARCHITECTURE.md.


🧰 Tech Stack

AreaTechnologies
Backend (api/)Elixir 1.19 / OTP 28 ¡ Phoenix 1.7 ¡ Absinthe 1.10 (GraphQL) ¡ Ecto 3.13 ¡ Oban 2.20 + Oban Pro
Frontend (web/)React 17 ¡ TypeScript 5.7 ¡ esbuild ¡ Apollo Client 3 ¡ Zustand ¡ MUI 7 ¡ React Router 5
E2E (e2e/)Playwright 1.60 ¡ TypeScript ¡ Currents reporter
Data & infraPostgreSQL 15 (+ read replicas) ¡ GKE (Kubernetes) ¡ Firebase Hosting ¡ Google Cloud Functions
ObservabilityOpenTelemetry → Jaeger (local) · New Relic · Sentry

📁 Project Structure

DirectoryDescriptionDeployment Target
api/GraphQL & REST API — Elixir/Phoenix umbrella (6 OTP apps)GKE
web/Vetspire frontend (React)Firebase
e2e/Playwright end-to-end test suite— (CI / Cloud Run)
functions/Cloud functions for reporting, PDFs, integrationsGoogle Cloud Functions
datasync/Python CLI tool for client-side data ingestionClient machines
developer.vetspire.com/Public GraphQL docsFirebase
email-templates/MJML email templates—
scripts/Internal helper scripts—
dns/DNS config dumps—

â„šī¸ The datasync/ directory is the client-side Python ingestion tool. The umbrella also contains a separate datasync OTP app (server-side sync workers) — see docs/ARCHITECTURE.md.


✅ Prerequisites

Runtime versions are pinned in .tool-versions (use asdf or mise):

ToolVersion
Elixir1.19.5-otp-28
Erlang28.5.0.5
Node.js22.13.1
Yarn1.22.17
pnpm10.33.2
Python3.11.6

You'll also need PostgreSQL (via Docker, below), Docker, and the gcloud CLI.

💡 A Nix flake is provided for a reproducible toolchain. With direnv installed, .envrc loads your environment automatically on cd into the repo.


âš™ī¸ Backend Setup

# Start Docker daemon if necessary
sudo service docker start

# Start PostgreSQL (and the Jaeger tracing UI) containers
docker compose up db jaeger

# Auth to GCP
gcloud auth login
gcloud auth application-default login

# Backend setup
cd api
mix hex.repo add oban https://repo.oban.pro \
  --fetch-public-key SHA256:4/OSKi0NRF91QVVXlGAhb/BIMLnK8NHcx/EWs+aIWPc \
  --auth-key 0a0cb15a8ff6f9d6175a9ea19eccff0c

mix deps.get
mix ecto.reset
iex -S mix phx.server

Visit:

  • https://localhost:4000 — Vetspire API
  • https://localhost:4000/graphiql — GraphiQL endpoint
  • https://localhost:4001 — Admin app (requires USE_SSL=true — the admin endpoint only works over https)
  • http://localhost:16686 — Jaeger tracing UI (when the jaeger container is running)

The API is an Elixir umbrella of six OTP apps. If you don't need all of them during local development, set these ENV VARs to false to skip booting them:

VariableEffect when false
START_DATASYNCSkip booting the datasync app
START_PROTOCOLSSkip booting the protocols app
START_MONARCHSkip running Monarch data migrations on boot
START_OPENTELEMETRYSkip attaching OpenTelemetry (Sibyl) trace handlers
export START_DATASYNC=false
export START_MONARCH=false
export START_OPENTELEMETRY=false
export START_PROTOCOLS=false

âš ī¸ START_READ_REPLICA is not an environment toggle. Read replicas auto-boot in non-test environments and are routed to programmatically via Vetspire.Repo.use_read_replica?/0 — see api/apps/vetspire/lib/vetspire/repo.ex.


đŸ–Ĩī¸ Frontend Setup

cd web
pnpm install
pnpm start

Visit: https://localhost:3000

🔐 Local Login

  1. Go to https://localhost:3000/select_org
  2. Enter "test" for the subdomain.
  3. Login using test credentials from seed data

đŸ§Ē E2E Tests

End-to-end tests use Playwright and follow a Functional Page Model. Run them against a chosen environment:

cd e2e
pnpm install
pnpm test:local        # also: test:dev | test:staging | test:production
pnpm ui                # interactive UI mode
pnpm report            # open the last HTML report

Use pnpm (not npx) in e2e/. Conventions live in e2e/CLAUDE.md; architecture in docs/ARCHITECTURE.md.


🔌 Connecting to Remote Environments

To connect to dev, staging, or prod:

./scripts/connect <environment>

If not already authenticated:

gcloud auth login
gcloud auth application-default login

đŸ§Ē Using GraphiQL with Local Auth

  1. Run backend and frontend locally.
  2. Login at https://localhost:3000.
  3. Open browser console and run:
copy(localStorage.getItem("authToken"))
  1. Go to /graphiql, set the authorization header using the copied token.

đŸŒŗ Git Worktrees (Multi-Instance Development)

Git worktrees allow you to work on multiple branches simultaneously. Each worktree automatically gets its own database (named after the branch), so you can work on multiple features without conflicts.

Setup

1. Convert to bare repo (one-time setup):

# Clone as bare repo
git clone --bare git@github.com:Vetspire-VSP/vetspire.git vetspire
cd vetspire

# Create your main worktree
git worktree add master master

2. Create worktrees:

# New branch from master
git worktree add DI-1234 -b feat/DI-1234 master

# Existing branch
git worktree add my-feature fix/my-feature

# From remote branch
git worktree add DI-5678 -b chore/DI-5678 origin/DI-5678

3. Set up database (for each new worktree):

cd DI-1234
scripts/worktree-setup   # Clones build state, reconciles deps, sets up databases

Takes ~1m45s, and is safe to re-run. WORKTREE_SHARED_DB=1 shares one dev/test database across worktrees, which brings it down to ~50s. Pair it with scripts/worktree-warm-bases on a timer to keep the base worktrees current. If you drive worktrees with worktrunk, .config/wt.toml runs all of this for you on wt switch --create. See scripts/WORKTREES.md.

Configuration Options

Add these to .envrc_local in your worktree:

OptionDescription
USE_SSL=trueEnable HTTPS/WSS (required for the Admin app on 4001)
WORKTREE_SEPARATE_PORTS=trueUse separate ports per worktree (see below)

Port Isolation (Optional)

By default, all worktrees use the same ports (4000 for backend, 3000 for frontend). This means you can only run one worktree at a time.

To run multiple worktrees simultaneously, enable port isolation in .envrc_local:

export WORKTREE_SEPARATE_PORTS=true

With port isolation enabled, each worktree gets sequential ports based on alphabetical order:

  • First worktree: Backend 4000, Frontend 3000
  • Second worktree: Backend 4015, Frontend 3015
  • Third worktree: Backend 4030, Frontend 3030

Database Naming

Each worktree automatically uses a branch-specific database:

Note: postgres database names have a max character setting requiring trimmed db names on long branch names

  • Database: <branch-name> (slashes replaced with hyphens)
  • Test DB: vetspire_test_<branch-name>

You can bypass branch based test databases by removing the ENV var in your .envrc_local

unset TEST_DB_NAME

Examples

  • Branch feat/DI-1234 → Database feat-DI-1234
  • Branch PL-2948-preserve-existing-lab-order-test-modifiers-for-fuji-ris → Database PL-2948-preserve-existing-lab-order-test-modifiers

Best Practices

  • Cleanup: git worktree remove <name> when done
  • List: git worktree list to see all active worktrees
  • direnv: Install direnv for automatic environment configuration

🚀 Continuous Deployment

BranchEnvironmentClusterProject
masterDevelopmentvetspire-api-devvetspire-app
stagingStagingvetspire-staging-apivetspire-app
productionProductionvetspire-prod-apivetspire-app
productionSandboxvs-sandbox-k8s-a23bvs-sandbox

Deployments are automated via GitHub Actions (dev, staging, production). Order: backend → frontend. See the CI/CD overview for the full pipeline.


đŸ’ŗ Online Booker

The online booker application now lives here: Online Booker.


Editor IDE and agent setup

We've added Tidewave MCP as a development dependency for improved tooling when using Copilot or Claude in local IDE development.

To set up Tidewave MCP with your editor/agent see docs here: https://hexdocs.pm/tidewave/mcp.html

e.g. claude mcp add --transport http tidewave http://localhost:4000/tidewave/mcp


🧹 Linting & Formatting (VS Code)

Install:

Update settings.json:

"[javascript]": {
  "editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
  "editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescriptreact]": {
  "editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[graphql]": {
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true
}

Run:

pnpm lint

â˜ī¸ Vetspire Cloud Functions

Run locally:

cd functions
yarn start

Available at https://localhost:8080

Defined Functions

  • createAntechLab
  • pollAntechLabs
  • syncIntacct
  • createPDF
  • mergeURLsToPDF
  • generatePDF

📚 Documentation


🔍 Monitoring & Observability