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.
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.
- Bun installe (version recommandee:
1.2.20ou proche). - Docker installe pour les services locaux (
postgres,minio,mailpit). - Git + terminal.
Verifier rapidement:
bun --version
docker --versionDepuis la racine du repo:
bun install
cp apps/server/.env.example apps/server/.env
cp apps/web/.env.example apps/web/.envVariables principales a connaitre:
apps/server/.envDATABASE_URL=postgresql://postgres:postgres@localhost:5432/doctor_comBETTER_AUTH_SECRET=...(minimum 32 caracteres)BETTER_AUTH_URL=http://localhost:3000CORS_ORIGIN=http://localhost:3001SMTP_HOST=localhost,SMTP_PORT=1025pour Mailpit local.
apps/web/.envVITE_SERVER_URL=http://localhost:3000
- Demarrer les dependances backend locales:
docker compose up -d postgres medications-postgres minio mailpitServices 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
- Appliquer les migrations:
bun run db:migrate
bun run medications-db:migrate- Demarrer le serveur backend:
bun run dev:server- (Optionnel) Demarrer le web:
bun run dev:webURLs 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
bun run minio:upDemarre MinIO via Docker Compose (minio), avec:
- API S3:
http://localhost:9000 - Console:
http://localhost:9001
bun run check-typesTypecheck global du monorepo (gate principal).
bun run check-types:backendTypecheck backend uniquement (server, api, db, auth, shared).
bun run backend:smokeSmoke test backend transactionnel avec rollback. Il couvre le workflow patient -> rendez-vous -> consultation -> dossier -> agenda -> ordonnance page data sans polluer la base.
bun run buildBuild Turbo de tous les workspaces qui exposent build.
bun run devLance tous les workspaces de dev (server, web, native).
bun run dev:core
bun run dev:server
bun run dev:web
bun run dev:nativedev:core lance seulement server + web. Les autres commandes ciblent un workspace precis.
bun run db:generateGenere migration SQL a partir des schemas Drizzle.
bun run db:migrateApplique les migrations.
bun run db:pushPush direct schema -> DB (utile surtout en dev rapide, moins traceable qu’une migration versionnee).
bun run db:studioLance Drizzle Studio.
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- Modifier
packages/db/src/schema/*. - Lancer
bun run db:generate. - Verifier le SQL genere dans
packages/db/src/migrations/*. - Lancer
bun run db:migrate. - Lancer
bun run check-types. - Commit schema + migration + meta ensemble.
- Modifier Zod dans
packages/shared/src/schemas/*. - Verifier types derives dans
packages/shared/src/types/dto.ts. - Adapter
packages/api(router/service/repo). - Lancer
bun run check-types.
Bun n’est pas installe sur la machine.
curl -fsSL https://bun.sh/install | bashPuis redemarrer le terminal.
- 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:migrateSi apps/web remonte des erreurs TanStack route tree:
bun run --cwd apps/web routes:generate
bun run --cwd apps/web check-typesVerifier apps/server/.env:
CORS_ORIGIN=http://localhost:3001BETTER_AUTH_URL=http://localhost:3000
- Architecture packages: packagesARCH.md
- Schema DB checklist:
packages/db/src/DB_CHECKLIST.md - Schema metier source:
apps/server/DB.md - Turbo pipeline:
turbo.json