Skip to content

Repository files navigation

doctor.com

Monorepo Bun + Turborepo pour un backend medical scaffold:

  • apps/server: runtime Express (boot serveur + montage tRPC/Better-Auth).
  • packages/api: couche tRPC (context, router racine, modules placeholders).
  • packages/db: Drizzle schema + migrations + client PostgreSQL.
  • packages/auth: configuration Better-Auth.
  • packages/shared: DTO Zod, types inferes, erreurs applicatives.
  • apps/web: client web (TanStack Router) relie au backend scaffold.

Le detail complet de l’architecture packages/ est dans packagesARCH.md.

Etat du projet

Le repo est ready pour commencer a travailler en equipe sur la phase suivante, avec ces conditions:

  • typecheck global OK (bun run check-types).
  • migrations Drizzle synchronisees (bun run db:generate -> no changes).
  • structure modules/repo/service prete.

Important:

  • la logique metier/API n’est pas implementee (scaffold volontaire).
  • Better-Auth est cable, mais les flows providers/metier restent a completer.

Prérequis

  1. Bun installe (version recommandee: 1.2.20 ou proche).
  2. Docker installe pour les services locaux (postgres, minio, mailpit).
  3. Git + terminal.

Verifier rapidement:

bun --version
docker --version

Installation (premier lancement)

Depuis la racine du repo:

bun install
cp apps/server/.env.example apps/server/.env
cp apps/web/.env.example apps/web/.env

Variables principales a connaitre:

  • apps/server/.env
    • DATABASE_URL=postgresql://postgres:postgres@localhost:5432/doctor_com
    • BETTER_AUTH_SECRET=... (minimum 32 caracteres)
    • BETTER_AUTH_URL=http://localhost:3000
    • CORS_ORIGIN=http://localhost:3001
    • SMTP_HOST=localhost, SMTP_PORT=1025 pour Mailpit local.
  • apps/web/.env
    • VITE_SERVER_URL=http://localhost:3000

Démarrage rapide (backend + DB + web)

  1. Demarrer les dependances backend locales:
docker compose up -d postgres medications-postgres minio mailpit

Services utiles:

  • PostgreSQL app: localhost:5432
  • PostgreSQL medicaments: localhost:5433
  • MinIO API: http://localhost:9000
  • MinIO console: http://localhost:9001
  • SMTP Mailpit: localhost:1025
  • Inbox Mailpit: http://localhost:8025
  1. Appliquer les migrations:
bun run db:migrate
bun run medications-db:migrate
  1. Demarrer le serveur backend:
bun run dev:server
  1. (Optionnel) Demarrer le web:
bun run dev:web

URLs utiles:

  • Backend: http://localhost:3000
  • Health texte: GET /healthz -> server running
  • Health backend detaille: GET /healthz/backend
  • Health backend avec test storage profond: GET /healthz/backend?deep=1
  • tRPC mount: http://localhost:3000/trpc
  • Auth Better-Auth: http://localhost:3000/api/auth/*
  • Web: http://localhost:3001

Commandes racine a connaitre

Storage (MinIO)

bun run minio:up

Demarre MinIO via Docker Compose (minio), avec:

  • API S3: http://localhost:9000
  • Console: http://localhost:9001

Qualite / Build

bun run check-types

Typecheck global du monorepo (gate principal).

bun run check-types:backend

Typecheck backend uniquement (server, api, db, auth, shared).

bun run backend:smoke

Smoke test backend transactionnel avec rollback. Il couvre le workflow patient -> rendez-vous -> consultation -> dossier -> agenda -> ordonnance page data sans polluer la base.

bun run build

Build Turbo de tous les workspaces qui exposent build.

Dev

bun run dev

Lance tous les workspaces de dev (server, web, native).

bun run dev:core
bun run dev:server
bun run dev:web
bun run dev:native

dev:core lance seulement server + web. Les autres commandes ciblent un workspace precis.

Base de donnees

bun run db:generate

Genere migration SQL a partir des schemas Drizzle.

bun run db:migrate

Applique les migrations.

bun run db:push

Push direct schema -> DB (utile surtout en dev rapide, moins traceable qu’une migration versionnee).

bun run db:studio

Lance Drizzle Studio.

Commandes workspace (quand tu veux cibler un package/app)

Exemples utiles:

bun run --cwd apps/server dev
bun run --cwd apps/server check-types
bun run --cwd apps/web check-types
bun run --cwd apps/web routes:generate
bun run --cwd apps/web routes:watch
bun run --cwd packages/db check-types
bun run --cwd packages/db db:generate

Workflow recommandé pour l’equipe

Quand tu modifies la base de donnees

  1. Modifier packages/db/src/schema/*.
  2. Lancer bun run db:generate.
  3. Verifier le SQL genere dans packages/db/src/migrations/*.
  4. Lancer bun run db:migrate.
  5. Lancer bun run check-types.
  6. Commit schema + migration + meta ensemble.

Quand tu modifies des payloads API

  1. Modifier Zod dans packages/shared/src/schemas/*.
  2. Verifier types derives dans packages/shared/src/types/dto.ts.
  3. Adapter packages/api (router/service/repo).
  4. Lancer bun run check-types.

Troublshooting (erreurs frequentes)

bun: command not found

Bun n’est pas installe sur la machine.

curl -fsSL https://bun.sh/install | bash

Puis redemarrer le terminal.

PostgreSQL local non accessible

  • Verifier que le service PostgreSQL tourne sur localhost:5432.
  • Lancer le service (exemples):
brew services start postgresql@16
# ou
sudo systemctl start postgresql
  • Puis rejouer:
bun run db:migrate

TypeScript / routeTree web

Si apps/web remonte des erreurs TanStack route tree:

bun run --cwd apps/web routes:generate
bun run --cwd apps/web check-types

CORS en local

Verifier apps/server/.env:

  • CORS_ORIGIN=http://localhost:3001
  • BETTER_AUTH_URL=http://localhost:3000

Références utiles dans le repo

  • Architecture packages: packagesARCH.md
  • Schema DB checklist: packages/db/src/DB_CHECKLIST.md
  • Schema metier source: apps/server/DB.md
  • Turbo pipeline: turbo.json

About

AI-powered medical-practice workspace that brings appointments, patient records, consultations, prescriptions, and follow-ups together, with in-context assistance for clinical questions and medication safety.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages