Files
dyolink/backend
Amin Mousavi 8757a8952c feat(frontend): split Add detail into a segmented control with voice
The microphone becomes the second segment of the Add detail button, built like
the detail chip's trash affordance in the same file — an overflow-hidden rounded
wrapper holding two raw <button>s divided by border-s — rather than two shared
Buttons, which each hardcode their own rounding and would fight a segmented
control. border-s puts the mic at the logical end: visually right in en/nl,
visually left in fa, on the same side as the chip's trash in both directions.

The two halves share a wrapper and nothing else. Add keeps its exact behaviour.

The control never changes size while recording; the timer and level meter live
in a bar between the header row and the chip strip, because the header is
sm:justify-between and growing the button would shove the row on every start and
stop. The meter exists to prove the microphone is actually hearing something —
silence and a dead mic look identical otherwise.

Voice reaches the editor as one optional `voice` prop, so its absence *is* the
unavailable state and the two cannot disagree.

Fixes from review of this commit:

- mountedRef was set false on unmount and never re-armed, so under StrictMode
  the hook was permanently "unmounted" in dev and recording silently never
  started.
- onStart guarded only on `phase`, which does not change until getUserMedia
  resolves; a second click during the permission prompt orphaned the first
  MediaStream, leaving the mic indicator lit.
- Week start is now per locale. "Next Thursday" is week-relative, and hardcoding
  Saturday put an en/nl clinician's deadline a week out.
- A missing `which` on a weekday intent is read as "this" rather than failing —
  a bare weekday carries no qualifier, and rejecting it discarded a real
  deadline.
- durationMs is client-reported and so is a claim, not enforcement; the cap is
  now also checked against the vendor's own usage.seconds.
- Blob type falls back to the recorder's actual mimeType before webm, so old
  Safari's mp4/aac clips are not mislabelled.

Two review findings were rejected as incorrect, both re-verified against live
sources: google/gemini-3.7-flash does exist on OpenRouter (1M context,
$0.375/$1.875 per M), and base64 JSON input_audio is the documented primary
path for /audio/transcriptions, with multipart as the OpenAI-compatible
alternative. The spec's stale "unverified" note is corrected, and the provider
now has unit tests covering the request shape, usage parsing, and that a vendor
error body never reaches the thrown message.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 19:47:10 +03:30
..

Dyolink — Backend (NestJS)

Prerequisites

  • Node.js 20+ and npm
  • PostgreSQL reachable from your machine — either installed locally or run via Docker (see below)

First-time setup

  1. Clone the monorepo and go to the backend app:

    git clone <repository-url> dyolink
    cd dyolink/backend
    
  2. Install dependencies

    npm install
    
  3. Environment

    Copy .env.example to .env and set at least:

    • DATABASE_URL — PostgreSQL connection string for your dev database
    • JWT_SECRET — strong secret for signing tokens
      Do not commit .env.
  4. Database for local dev

    Option A — Postgres in Docker (no local install, e.g. Mac)
    From backend/, with .env present (copy from .env.example first):

    • Ensure DATABASE_URL uses localhost as the host (not postgres). Match user, password, and DB name to POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB in the same file.
    docker compose -f docker-compose.postgres.yml up -d
    

    Wait until Postgres is healthy (docker compose -f docker-compose.postgres.yml ps). The container creates the database on first start.

    To stop Postgres (data is kept in the named volume): docker compose -f docker-compose.postgres.yml down

    Option B — Postgres installed on the machine
    Create an empty database, then point DATABASE_URL at it.

  5. Generate Prisma Client

    npm run prisma:generate
    
  6. Apply migrations (creates/updates tables to match prisma/schema.prisma)

    npm run prisma:migrate
    

    This runs prisma migrate dev. Use it during development when the schema changes.

  7. Seed (optional — reference data only)

    npm run prisma:seed
    

    This does not wipe your database. It only upserts lookup data: organization types (CLINIC, LAB), subscription plans, and tab permissions. Existing users, organizations, memberships, patients, appointments, and links are left unchanged.

    To start from an empty database with fresh tables and reference data, see Reset database (clean slate) below.

Reset database (clean slate)

Use this when you want to delete all application data (users, organizations, patients, sessions, etc.) and rebuild the schema from migrations, then run the seed.

From backend/:

npx prisma migrate reset

Prisma will prompt for confirmation, drop the database, re-apply all migrations, and run prisma/seed.ts automatically.

What gets removed: everything in the database, including organizations and all related rows.

What the seed adds back: only reference data (types, plans, permissions) — not demo users or organizations. Register again or use your own test data after a reset.

Docker Postgres dev: if you also want to wipe the Docker volume (not only tables), stop the container and remove the volume:

docker compose -f docker-compose.postgres.yml down -v
docker compose -f docker-compose.postgres.yml up -d
npm run prisma:migrate
npm run prisma:seed

Do not run migrate reset against production or shared staging databases.

Run (development)

npm run start:dev

API listens on http://localhost:3000 by default (PORT in .env).

If the frontend runs on another origin (e.g. http://localhost:3001), set FRONTEND_URL in .env to that URL (CORS and invite links use it).

After pulling latest main

git pull
npm install
npm run prisma:generate
npm run prisma:migrate

If teammates added migrations, the migrate step above applies them. Resolve migration conflicts locally before pushing.

Useful commands

Command Purpose
npm run prisma:generate Regenerate client after schema.prisma changes
npm run prisma:migrate Dev migrations (migrate dev)
npm run prisma:deploy Production-style apply (migrate deploy) — e.g. CI/containers
npm run prisma:seed Upsert reference data only (does not clear existing rows)
npx prisma migrate reset Drop DB, re-migrate, run seed — dev clean slate
npm run build Compile Nest app
npm run start:prod Run compiled app (node dist/main)

Docker

File Purpose
Dockerfile Production API image
docker-compose.postgres.yml Local dev Postgres only (port mapped to host)

For full-stack deployment and CI, see the repository root README.md.