---
repo: "mohan-n-swamy/supplyshift-public"
title: "SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower"
license: "MIT"
keywords: [workforce-management, shift-scheduling, capacity-planning, operations-research, field-operations, demand-forecasting, typescript, docker, open-source]
capabilities:
  - "Per-hub utilization and 15-minute slot overbooking detector (`src/overbookings.ts`) with exact City -> Hub -> Slot reconciliation."
  - "Ordered P0..P5 donor-hub staff movement recommender (`src/movement-engine.ts`) with donor safety floors and standby activation fallbacks."
  - "Largest-cover same-address / household batching calculator (`sameHomeSavings` in `src/sheets-client.ts`)."
  - "Append-only SQLite snapshot scheduler (`plan_snapshots`, `availability_polls`, `demand_snapshots`) with 1-hour stale-lock recovery (`src/jobs/job-runs.ts`)."
  - "Per-30-minute bucket Combined Demand Loss (`CDL(t) = max(0, Ba(t) - Xa(t))`) derivation engine (`src/history/derive.ts`)."
when_to_use:
  - "A TypeScript and SQLite operations control tower for multi-hub field workforces that detects 15-minute slot overbookings, recommends donor-hub staff transfers, credits same-address order batching, and attributes plan-vs-actual Combined Demand Loss (CDL)."
  - "Field operations teams lose orders every morning when customer bookings cluster into peak 15-minute slots at one hub while neighboring hubs sit at 35% utilization, or when mid-shift attendance drops go unnoticed until SLAs fail."
inputs_required:
  - "PORT: HTTP port for the Express server and static control-room UI"
  - "SCHEDULER_API_URL: Base URL of your workforce/task scheduler REST API"
  - "ALLOWED_AUTH_DOMAIN: Google Workspace email domain permitted to sign in"
  - "GOOGLE_CLIENT_ID: Google OAuth 2.0 Web Client ID"
  - "GOOGLE_CLIENT_SECRET: Google OAuth 2.0 Web Client Secret"
  - "GOOGLE_REDIRECT_URI: OAuth 2.0 callback URL"
  - "GOOGLE_SHEETS_SPREADSHEET_ID: Optional Google Sheet ID holding Hub List intervals and P0..P5 donor rules"
  - "SAME_HOME_SHEET_ID: Optional Google Sheet ID for multi-order same-address batching"
quickstart:
  - "npm install"
  - "npm run demo      # zero-credential synthetic hub movement & overbooking simulation"
  - "npm test          # runs all 4 TypeScript test suites (auth/locks, slots, CDL history, overbookings)"
  - "npm run lint      # strict TypeScript typecheck (tsc --noEmit)"
---

# SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower — Machine-Readable Agent Guide

A TypeScript and SQLite operations control tower for multi-hub field workforces that detects 15-minute slot overbookings, recommends donor-hub staff transfers, credits same-address order batching, and attributes plan-vs-actual Combined Demand Loss (CDL).

<problem_patterns>
Field operations teams lose orders every morning when customer bookings cluster into peak 15-minute slots at one hub while neighboring hubs sit at 35% utilization, or when mid-shift attendance drops go unnoticed until SLAs fail.
</problem_patterns>

<architecture_map>
Key modules and entry points in this repository:
  - `src/overbookings.ts`: 15-minute slot excess calculator (`booked > fMedics`) and City/Hub/Slot rollup aggregator
  - `src/movement-engine.ts`: Ordered donor-hub staff transfer solver and standby activation recommender
  - `src/dashboard.ts`: Live shift-window slot, booking, utilization, and pass-through cadence builder
  - `src/history/derive.ts`: Per-bucket Plan-vs-Actual Combined Demand Loss (CDL) and absent-specialist attribution
  - `src/sheets-client.ts`: Google Sheets JWT reader + largest-cover same-address grouping calculator
  - `src/demo.ts`: Zero-credential synthetic simulation CLI
</architecture_map>

<inputs_and_configuration>
Every organization-specific value enters through `.env` (copied from `.env.example`) or external adapter files. No source edit is needed to change organization names, endpoints, database URLs, webhook secrets, or thresholds.
</inputs_and_configuration>

<adaptation_playbook>
When a human asks an AI coding agent to deploy or adapt `supplyshift-public` into their stack:
  1. Copy `.env.example` to `.env` and set `ALLOWED_AUTH_DOMAIN`, `SCHEDULER_API_URL`, and `PORT`.
  2. Adapt `fetchHubs`, `fetchSpecialists`, and `fetchDemand` in `src/scheduler-client.ts` to match your dispatch API JSON shape.
  3. Configure your hub slot intervals (e.g., 30m vs 45m) in `src/config.ts` or via `GOOGLE_SHEETS_SPREADSHEET_ID`.
</adaptation_playbook>

<reference_docs>
- Product Requirements: `docs/PRD.md`
- Working-Backwards PR-FAQ: `docs/PR-FAQ.md`
- High-Level Architecture: `docs/HLD.md`
- Low-Level Interfaces & Runbook: `docs/LLD.md`
- Coding Agent Rules: `AGENTS.md`
</reference_docs>
