# Doctor On Call API — production bundle (compiled JavaScript, MySQL)

Ready-to-run build: no TypeScript, no build step on the server. `server.js` is the entry point.

## Contents
- `server.js`, `app.js`, `api/`, `common/`, `config/`, `jobs/`, `modules/`: the compiled app
- `prisma/schema.prisma` + `prisma/migrations/`: MySQL schema and migrations
- `prisma.config.js`: Prisma CLI config (reads DATABASE_URL from .env)
- `ecosystem.config.js`: PM2 process definition (name: backend)
- `.env.production`: TEMPLATE of every setting. Copy to `.env` and fill in on first install.

## First install
    cp .env.production .env      # then fill every <...> and CHANGE_ME value (database, SMTP, secrets)
    npm ci --omit=dev            # installs runtime packages and generates the Prisma client
    npm run migrate:deploy       # creates/updates the database tables
    npx pm2 start ecosystem.config.js && npx pm2 save

## Updating an existing server
Keep the server's existing `.env`, `uploads/` and `logs/`. Never overwrite `.env` with `.env.production`.

    npx pm2 stop backend
    # remove the old compiled code (keep .env, uploads/, logs/, node_modules/)
    rm -rf api common config jobs modules tests app.js app.js.map server.js server.js.map prisma
    unzip -o backend-prod.zip
    npm ci --omit=dev
    npm run migrate:deploy
    npx pm2 restart backend --update-env
    curl -s https://<api-domain>/api/v1/health     # expect "Service is healthy"
