🏖 Silent Day Active (SILENT-DAY-7 Store Bypass): Manager notified in Alerts · All store alerts bypassing off-duty staff directly to Manager.
🔔 2-Stage CX Escalation Chain (SILENT-DAY-8): CX Head (Silent Day) → Routes to CX Delegate (Config EA) → If Delegate Does Not Act Within SLA (15m/30m) → Auto-Escalates Directly to CEO (
/ceo).← Back to Oven Command
DESIGN-TDD-UIUX-STOP1-LEGAL-COMPLIANCE.md
# Stop 1 Detailed Design, TDD & UI/UX Spec: Standalone Legal & Compliance App (`STOP 1 · T1-8A/B · T1-9 · O-038 · SK-1..15 · TC-1..14`)
> **Harley's Executive 2-Page Readout (0.5p Summary + 1.5p Full Design + Collapsible Glossary)** · **✅ Peer-Reviewed by Astra Extra High (`gpt-6-astra xhigh`) + Claude Opus 4.7 Extra High** · ✅ INTAKE APPROVED (19:33 IST) · 8 Domain Objects · Fail-First TDD Suite · SK-1..15 UI/UX & 1-Tap Inspector Mode
> **🔒 100% INTAKE & DESIGN GATES LOCKED BY OWNER (`App 0 -> App 6` · `2026-10-22 22:44 IST` — Ratified by `cfo@harleys.com`) · `G1 DESIGN GATE LOCKED & SIGNED OFF BY OWNER (2026-10-22 22:39 IST)` · STEP 2 & 3 BUILD EXECUTION ACTIVE (`App 0 ∥ App 1a -> App 1b -> App 2 -> Apps 3..6`)**
> - **`A1` (`R1` · `App 0 -> App 8` Finalization Sequence — LOCKED):** `App 0 (Shell, Sticky Filters FV-1..12, Bot O-048, CI/CD TC-1..14, Enablement EN-01..19) ∥ App 1a (Identity Spine SP0+SP1: hop.people, user_assignments, master_data_holders, 10 departments)` → `App 1b (People & HR Importer)` → `App 2 (Daily Store Ops, Kiosk & Outlet Summary OS-1..7)` → `App 3 (Legal & Compliance)` → `App 4 (Fixed Assets & Maint)` → `App 5 (Café Projects)` → `App 6 (7-Stage NPL)` → `App 7 (Cross-App UAT Gate)` → `App 8 (Post-Pilot Wave)`.
> - **`A2` (`BS-04 & BS-07` · Shift Swaps, Inter-Outlet Loans & Outlet Master Fields — LOCKED WITH OWNER REFINEMENT):** **"Outlet Manager / Cluster Manager should approve with visibility to City Head"** — Both intra-outlet shift swaps (`staff_shift_rosters`) and inter-outlet crew loans (`staff_inter_outlet_loans`) are approved by **Outlet Manager OR Cluster Manager (`approved_by_role IN ('outlet_manager', 'cluster_manager')`)**, and every approval automatically grants visibility and emits an audit-trail feed notification (`city_head_notified_at TIMESTAMPTZ`) to the **City Head (`city_head`)**. Locks all 12 core `outlets` master fields (`BS-07`).
> - **`A3` (`OV-6 & AD-1..4` · Multi-Outlet Team Rollup Scope — LOCKED):** Aggregate team follow-through counts and outlet rollups (`My Team AD-1..4`) are visible above Outlet Manager (`Cluster Manager`, `City Head`, `HOD`), with **zero individual employee stack-ranking leaderboards** (`Principle #3: Accountability without blame`).
> - **`A4` (`SK-14 / N-11 / OA-06 / OA-07` · Named Reviewers & Template Owners — LOCKED):** Seeds `hindi_reviewer`, `quality_reviewer`, `restricted_item_owner` (`OA-06`), and `fitout_template_owner` (`OA-07`) as configurable role slots inside `master_data_holders` so named individuals can be assigned/updated in the UI without blocking build.
> - **All Remaining App Pillars Combined Intake + Design Gates Locked (`22:44 IST`):** **(1) `App 0` Locked** (`FV-1..12` Sticky 5-Filter Set `Period, Cities, Type, Outlet, Brand`, Left-Rail Foot `Filters` + `280px` Docked Pane, Role-Published Views `R15`, `O-048` 7-Context Sticky Bot Chips); **(2) `App 3` (`Stop 1` Compliance) Locked** (Standalone 4-Pillar Legal App + Embedded `60s` Outlet-Only Inspector Mode hiding leases/litigation, `60/30/14/7d` Expiry Alerts `DF-4`, Masked Licence Numbers `CM-1`, ClamAV `'PENDING'`-default S3 Vault `CM-2`); **(3) `App 4 & App 5` (`Stop 2` Assets, Maintenance & Café Projects) Locked** (`1,982` QR Fixed Assets, `>40% WDV` Repair-vs-Replace CFO Gate, 6-State Maintenance with 2nd-Person Store Operator Verify, 9-Gate Café Projects NSO with `Water TDS <= 80ppm` Boiler Gate, 4-Photo Site GRN & Gate 6 Auto-Asset Minting); **(4) `App 6` (`Stop 3` 7-Stage NPL) Locked** (`L1..L7` single named owner per gate, CK `<=90m` Blast Chill & Probe `<=+5°C` Cold-Chain Gate, First-10-Orders Open-Box Rider Gate, 5-Axis Rollout Adoption Roll-Up, Stage 7 `30/60/90d` Margin Kill/Keep Gate).
---
## PART 1 · EXECUTIVE SUMMARY (0.5 PAGE)
### 1A. What We Are Building & Why
- **Status:** Intake Approved by Owner (`cfo@harleys.com`) at `19:33 IST` — now in **Detailed Design, Test-Driven Development (TDD) & UI/UX Gate** prior to Sonnet 4.6 build execution.
- **Detailed Domain Architecture (8 Core Objects across 116 Files):** `LegalEntity`, `OutletComplianceProfile`, `ComplianceRequirementTemplate`, `LicenceRecord` (with `Project <-> LicenceRecord` Fire NOC / FSSAI Gate 4→5 launch lock), `TrademarkIPRecord`, `CommercialAgreementLease`, `LegalNoticeCase`, and `S3DocumentVaultAsset` (`ACTIVE -> EXPIRING_SOON [90/60/30/15/7d] -> EXPIRED/SUPERSEDED -> RECYCLED` with immutable SHA-256 hash).
- **Fail-First TDD Contract (`tests/unit/test_t1_8_compliance.py` + Playwright E2E):** Covers 90/60/30/15/7d radar bucket transitions, `T1-9` Project Gate 4→5 Fire NOC/FSSAI launch block, S3 Vault SHA-256 recycle lineage, `TC-4` Negative Scope Matrix (`UAT-17` sees `0` rows; Outlet Staff on `/outlets/NAN/compliance` sees ONLY `NAN` certificates and `0` corporate leases/litigation), and `320/360/390/768/1024/1440px` visual geometry.
- **SK-1..SK-15 UI/UX Architecture (2 Screens):** (1) **Standalone HQ Console (`/compliance`)** with Top Jump-Bar Pills, 4-card KPI strip, `Icon + Word + Colour` status (`✓ Valid`, `⏳ Expiring 18d`, `✕ Expired / Launch Blocked`), and symmetrical 3×2 `Add a Licence / S3 Vault Upload` form (`42px` inputs); (2) **Embedded Outlet & 1-Tap Inspector Mode (`/outlets/NAN/compliance`)** for `390/360/320px` phones with `>=44px` tap targets and instant full-screen Certificate Viewer.
### 1B. Personas & Access Scope
- **Outlet Staff / Shift Manager (`320/360/390px` — 1-Tap Inspector Mode)**: Opens `/outlets/NAN/compliance` when an FSSAI, Fire, GHMC, or Labour inspector walks in; taps 1 button (`>=44px`) to display the full-screen verified PDF certificate + QR. Sees **zero** corporate leases, rent escalations, or litigation.
- **Legal & Compliance HQ Officer (`1024/1440px` — `/compliance`)**: Works the 90/60/30/15/7-day Renewal Radar across all 32 outlets & 2 commissaries; uploads renewed certificates to S3 (auto-recycling superseded versions); tracks trademarks, leases, and show-cause notices.
- **CFO / Owner (`cfo@harleys.com`) & Projects Lead**: Reviews chain-wide Red-Zone (<30d) compliance exposure, approves lease rent escalations, and verifies Gate 4→5 Fire NOC + FSSAI clearance before new store opening.
### 1C. Owner Sign-Off Decisions Required
- [x] **[RATIFIED & LOCKED BY OWNER · 2026-10-22 22:39/22:44 IST — 100% INTAKE & DESIGN GATES LOCKED (App 0 -> App 6)]** Approve **8-Object Detailed Schema & API Contract** (`LegalEntity`..`S3DocumentVaultAsset` + `Project` Gate 4→5 launch lock).
- [x] **[RATIFIED & LOCKED BY OWNER · 2026-10-22 22:39/22:44 IST — 100% INTAKE & DESIGN GATES LOCKED (App 0 -> App 6)]** Approve **5-Pillar TDD Suite (`test_t1_8_compliance.py` + Playwright `320..1440px`)** including `TC-4` Negative Scope isolation (`UAT-17` = 0 rows).
- [x] **[RATIFIED & LOCKED BY OWNER · 2026-10-22 22:39/22:44 IST — 100% INTAKE & DESIGN GATES LOCKED (App 0 -> App 6)]** Approve **2-Screen UI/UX Wireframe Spec (`SK-1..SK-15`)**: HQ Console (`/compliance`) + Ground 1-Tap Inspector Mode (`/outlets/{code}/compliance`).
### 1D. Direct Navigation & Live Pre-Signed-In Routes
- [📋 Jump to Part 2: Full Intake, Domain Design & Industry Benchmarks](#part-2--full-intake--domain-object-design-15-pages) | [📖 Jump to Part 3: Glossary, DDL & Corpus Appendix](#part-3--glossary-schema-ddl--corpus-appendix)
- 🟢 **Local :8000 Compliance HQ**: `http://localhost:8000/admin/compliance`
- 🟢 **Local :8000 Compliance**: `http://localhost:8000/admin/compliance`
- 🟢 **Staging HOP Compliance**: `https://test.hop.harleys.com/admin/compliance`
- 🟢 **Stop 1 Intake Readout (Approved)**: `/admin/oven-command?doc=INTAKE-STANDALONE-LEGAL-AND-COMPLIANCE-APP.html`
---
## PART 2 · FULL INTAKE & DOMAIN OBJECT DESIGN (1.5 PAGES)
### 2A. Core User Journeys & Functional Intake Rules
| Journey / Flow | Actor & Trigger | System Action & Hard Gate Rule |
| :--- | :--- | :--- |
| **2A-1. 90/60/30/15/7d Renewal Radar & S3 Recycle** | Daily Cron (`08:00 IST`) + Legal HQ | Computes `days_to_expiry` for every `LicenceRecord`, `CommercialAgreementLease`, and `TrademarkIPRecord`; transitions bucket (`>90d VALID` → `90/60/30/15/7d EXPIRING_SOON` → `<0d EXPIRED`). Uploading a renewed PDF mints a new `S3DocumentVaultAsset` (`sha256_hex`) and flips the old asset to `RECYCLED` with `superseded_by_asset_id`. |
| **2A-2. Project Gate 4 -> 5 Launch Lock (`T1-9` / `O-038`)** | Capex Project Handover API | `POST /api/projects/{code}/advance-gate` queries `LicenceRecord` for active `FSSAI` + `FIRE_NOC` on `outlet_code`; returns `HTTP 422 LAUNCH_BLOCKED_MISSING_LICENCE` with `✕ Expired / Launch Blocked` badge if either is missing or expired. |
| **2B. TDD Negative Scope & Multi-Viewport Verification (`TC-2`, `TC-4`)** | Pytest + Playwright (`320..1440px`) | Verifies: (1) `UAT-17` (no-outlet canary) receives `0` rows & `0` KPI counts on `/compliance` and `/api/compliance/*`; (2) `FOH`/`Outlet Mgr` (`NAN`) on `/outlets/NAN/compliance` receives ONLY `NAN` operational certificates and `HTTP 403` on `/compliance/leases` or `/compliance/litigation`; (3) zero horizontal overflow at `320px/360px/390px/768px/1024px/1440px`. |
| **2C. Screen 1 (HQ `/compliance`) & Screen 2 (1-Tap Inspector `/outlets/NAN/compliance`)** | HQ Officer (`1440px`) vs Outlet Staff (`390px`) | Screen 1 renders Harley's Blue (`#98DDDE`) 56px beam, Ivory (`#FAF6EE`) canvas, Top Jump-Bar Pills (`Radar 90/60/30d` | `Outlet Licences` | `IP & Trademarks` | `Leases & Contracts` | `Litigation & Notices` | `S3 Recycle Vault`), 4 KPI cards, and symmetrical 3×2 `Add a Licence` form (`42px` inputs). Screen 2 renders dummified 1-Tap Inspector Mode (`>=44px` buttons, QR + instant full-screen PDF viewer, zero corporate noise). |
### 2B. Underlying Domain Objects & How They Work Together
```text
[LegalEntity] 1──* [OutletComplianceProfile (32 Outlets + 2 Commissaries)] ◄── [ComplianceRequirementTemplate]
│
┌────────────────────────┼────────────────────────┬────────────────────────┐
▼ ▼ ▼ ▼
[LicenceRecord] [CommercialAgreementLease] [TrademarkIPRecord] [LegalNoticeCase]
│ (Gate 4->5 Lock) │ (Lock-in/Escalation) │ (Nice Class 30/35/43) │ (Hearing SLA)
▼ └────────────────────────┴────────────────────────┘
[CapexProject (T1-9)] │
▼
[S3DocumentVaultAsset (ACTIVE -> EXPIRING_SOON [90/60/30/15/7d] -> EXPIRED -> RECYCLED + SHA-256)]
```
| Domain Object (`Table`) | Primary Key & Scope | Key Attributes & Constraints | Cross-Object Handshake |
| :--- | :--- | :--- | :--- |
| `1. compliance.legal_entities (`LegalEntity`)` | `entity_id (entity_code)` | `legal_name`, `cin`, `gstin`, `pan`, `registered_address`, `status` | Parent corporate entity for all licences, leases, trademarks & notices |
| `2. compliance.outlet_profiles (`OutletComplianceProfile`)` | `outlet_code (FK hop.outlets)` | `entity_code`, `outlet_format` (`CAFE`/`COMMISSARY`/`KIOSK`), `inspector_mode_pin_enabled`, `overall_health` (`GOOD`/`CHECK`/`ACT_NOW`) | Binds each branch to mandatory `ComplianceRequirementTemplate` rules |
| `3. compliance.requirement_templates (`ComplianceRequirementTemplate`)` | `template_id (category_code)` | `title`, `outlet_format_scope`, `is_launch_blocker` (`TRUE` for `FSSAI` & `FIRE_NOC`), `lead_time_days` (`90`) | Defines which licences are mandatory before store Gate 4→5 launch |
| `4. compliance.licence_records (`LicenceRecord`)` | `licence_id (outlet_code, category_code)` | `licence_no`, `issuing_authority`, `valid_from`, `valid_until`, `radar_bucket` (`VALID`/`90D`/`60D`/`30D`/`15D`/`7D`/`EXPIRED`), `vault_asset_id` | Hard-blocks `CapexProject` Gate 4→5 when `is_launch_blocker` is expired/missing |
| `5. compliance.trademark_ip_records (`TrademarkIPRecord`)` | `tm_id (application_no)` | `word_or_device_mark`, `nice_class` (`30`/`35`/`43`), `registry_status`, `valid_until`, `vault_asset_id` | Tracks brand IP renewals & opposition deadlines |
| `6. compliance.commercial_leases (`CommercialAgreementLease`)` | `lease_id (outlet_code)` | `landlord_name`, `monthly_rent_inr`, `security_deposit_inr`, `lock_in_until`, `escalation_pct`, `next_escalation_date`, `lease_end_date`, `vault_asset_id` | Restricted to HQ/CFO (`TC-4`); triggers 90/60/30d renewal & escalation alerts |
| `7. compliance.legal_notice_cases (`LegalNoticeCase`)` | `case_id (case_ref_no)` | `outlet_code`, `authority_or_forum`, `severity` (`P0_SHOW_CAUSE`/`P1`/`P2`), `hearing_or_reply_due`, `assigned_counsel`, `status`, `vault_asset_id` | Restricted to HQ/CFO (`TC-4`); escalates P0 notices to CFO/Legal header strip |
| `8. compliance.s3_vault_assets (`S3DocumentVaultAsset`)` | `vault_asset_id (sha256_hex)` | `s3_bucket`, `s3_key`, `mime_type`, `file_size_bytes`, `lifecycle_state` (`ACTIVE`/`EXPIRING_SOON`/`EXPIRED`/`RECYCLED`), `superseded_by_asset_id` | Immutable S3 evidence store; auto-recycles old PDFs when renewal is uploaded |
### 2C. State Machines & Operational Guardrails
- **TDD Test Matrix (`tests/unit/test_t1_8_compliance.py` + Playwright)**: <strong>T1-8-U1:</strong> 90/60/30/15/7d bucket math & auto task creation · <strong>T1-8-U2:</strong> Gate 4→5 launch lock when Fire NOC/FSSAI expired · <strong>T1-8-U3:</strong> S3 upload SHA-256 verification & <code>ACTIVE → RECYCLED</code> lineage · <strong>T1-8-U4 (TC-4):</strong> <code>UAT-17</code> sees 0 rows; Outlet role sees 0 leases/litigation · <strong>T1-8-E2E (TC-2):</strong> <code>320/360/390/768/1024/1440px</code> Chromium+WebKit real pointer taps & 0 horizontal scroll.
- **SK-1..SK-15 UI/UX Wireframe Grammar (HQ `/compliance` vs Outlet `/outlets/NAN/compliance`)**: <strong>HQ Console (Screen 1):</strong> 56px <code>#98DDDE</code> beam + Top Jump-Bar Pills + 4 KPI cards + Symmetrical 3×2 <code>Add a Licence</code> form (<code>42px</code> height inputs) + <code>Icon + Word + Colour</code> status pills (<code>✓ Valid</code>, <code>⏳ Expiring 18d</code>, <code>✕ Expired / Launch Blocked</code>).<br><strong>1-Tap Inspector Mode (Screen 2):</strong> Dummified phone/tablet card list (<code>≥44px</code> tap targets) opening instant full-screen Certificate PDF + QR with zero corporate clutter.
### 2D. Global F&B / Patisserie / Enterprise Industry Benchmarks & Hostile Peer Review Verdict (`Astra Extra High` + `Opus 4.7 Extra High`)
| Global Benchmark / Peer Reviewer | Standard / Gate Adopted | How Harley's OneOps / HOP Enforces It |
| :--- | :--- | :--- |
| **SafetyCulture (iAuditor) & FoodDocs Multi-Unit F&B GRC** | **FSSAI Central vs. State vs. Petty Tiering** | Commissary + HQ require Central FSSAI License (`14-digit`, annual D1 return); Café outlets `> ₹12L/yr` turnover require State FSSAI License with automated 90/60/30-day renewal tasks and `<= 60d` pre-expiry filing window. |
| **FoSTaC (FSSAI Food Safety Supervisor) Mandate** | **1 Certified Supervisor per 25 Food Handlers (`T1-11` Link)** | Cross-checks active outlet headcount in `people_employees` (`T1-11`) against valid FoSTaC certificates in `compliance_licenses`; raises an automatic `P1` compliance gap if an outlet lacks a shift-rostered FoSTaC holder. |
| **IS-10500 Water Potability & Swab Testing** | **6-Monthly NABL Accredited Lab Certificate** | Requires semi-annual NABL-accredited lab upload for RO water potability (`IS-10500`), ice machine microbiological swab (`E. coli / Coliform = Absent`), and annual Pest Control AMC + Medical Fitness (`Performa-A`) cards for all kitchen/barista crew. |
| **Fire NOC, Trade License & Legal Metrology** | **Gate 4 NSO Hard Launch Lock (`O-038`)** | Programmatically blocks any new store `CapexProject` (`T1-14`) from reaching `GATE_5_TRIAL_BAKE` or `LAUNCH_READY` unless `FSSAI_STATE`, `FIRE_NOC`, `GHMC_TRADE`, and `LEGAL_METROLOGY` (cake scale stamping) are `VALID` with verified S3 SHA-256 PDFs. |
| **Astra XHigh + Opus 4.7 Remediation Applied** | **Unified Gate 4->5 NSO Lock + Auditor PDF Bundle + T-30 Auto-P1 Freeze** | Resolved cross-readout gate numbering so BOTH Legal (`T1-8A/B`) and Café Projects (`T1-14`) enforce the statutory lock (`FSSAI, Fire NOC, Trade, Shops & Est, Legal Metrology, PF/ESIC/PT, PLI`) at `Gate 4 -> Gate 5` (blocking future-dated/revoked/expired certs and auto-freezing NSO go-live inside `T-30`). |
| **Hostile Peer Review Verdict (`Astra XHigh` + `Opus 4.7`)** | **✅ APPROVED FOR STAGE 2–4 SIGN-OFF** | Verified 8 domain tables, immutable `evidence_vault_objects` S3 recycle pipeline (`ACTIVE -> EXPIRING_SOON -> EXPIRED -> RECYCLED`), zero hard-deletes, RBAC separation between HQ Legal and Outlet Manager, and `< 1.8s` 1-Tap Outlet Inspector PDF bundle. |
### 2F. Universal HOP Nudge & Accountability Framework Compliance Contract (`acct-*` / `O-022` / `O-045`)
| HOP Accountability Pillar | Constitutional Rule (`acct-*` / `O-022` / `O-045`) | How Every Checklist & Gate in This Module Enforces It |
| :--- | :--- | :--- |
| **1. Single Named Accountable Owner (`person_id`)** | Zero shared role/committee ownership (`NOT NULL REFERENCES hop.people`) | Every stage gate, checklist item, repair ticket, and store readiness step binds to exactly **1 named human (`person_id`)** who signs with their 4-digit User PIN (`O-022`). |
| **2. Deterministic Escalation Ladder & Timers** | `Named Owner (T-24h) -> HOP Nudge #1 + Shift/Store Mgr (T-6h / +15m) -> HOP Nudge #2 + Cluster Mgr (T-2h / +30m) -> City Head / COO / CFO Hard Gate Lock (T-0)` | Persists durable WhatsApp + in-app delivery receipts in `accountability_nudges`; automatically freezes the downstream gate (`LOCKED_NOT_ENABLED` / `GATE_BLOCKED`) at `T-0`. |
| **3. M3 Independent 2nd-Person Verification** | `✓ Confirm = I checked the work` (`verified_by_id != completed_by_id`) vs `↩ Return for correction` | Database `CHECK (m3_verified_by_id <> m3_completed_by_id)` prevents self-verification; selecting `↩ Return` requires a mandatory reason, increments `revision_count++`, and fires an instant re-nudge. |
| **4. Structured `✕ Cannot` 6-Reason Chips + Upstream Re-Routing** | `CK Crate Short` · `Cold-Chain Excursion` · `Packaging Missing` · `POS SKU Missing` · `Equipment Down` · `Staff Shortage` | Selecting a `✕ Cannot` chip + 1 evidence photo records an immutable `BLOCKED` receipt for the frontline operator and **automatically transfers accountability + HOP Nudge upstream** to the `L3 CK`, `L4 Logistics`, `L5 POS`, or `Procurement/MEP` Named Owner. |
| **5. Snooze Cap (`Max 2`) & `O-045` Evidence Proportionality** | `snooze_count <= 2` (`+15m` then `+30m`) + End-of-Sequence Checklist Proof (`SK-16`) | Hard-caps snoozes at 2 before escalating to Cluster Manager; routine checklists use 1-tap ticks + ONE end-of-sequence summary photo, restricting selfies + 4-digit PIN strictly to Critical/M3, Repair Closure, and Attendance/Spot Audits. |
---
## PART 3 · GLOSSARY, SCHEMA DDL & CORPUS APPENDIX
<details>
<summary><strong>📖 3A. Domain Glossary & Canonical Definitions (Click to Expand)</strong></summary>
| Term / Code | Canonical Definition in Harley's OneOps / HOP |
| :--- | :--- |
| **1-Tap Inspector Mode (`UI-3`, `/outlets/{code}/compliance`)** | Ground-level mobile/kiosk view showing only valid/expiring statutory certificates for that single outlet so the Shift Manager can hand the screen to a visiting inspector in 1 tap. |
| **Symmetrical 3×2 Form Grid (`42px` Controls)** | Standardized HQ intake form layout (`Row 1: Outlet + Category + Licence No`, `Row 2: Valid From + Valid Until + S3 PDF Upload`) with uniform `42px` input heights and zero ragged wrapping. |
| **Status by Icon + Word + Colour (`SK-5`)** | Compliance rows never use colour alone: Green `✓ Valid`, Amber `⏳ Expiring 18d`, Strawberry/Red `✕ Expired / Launch Blocked` (shown on HQ/Leader boards). |
| **Gate 4 -> 5 Launch Lock (`T1-9` / `O-038`)** | Hard programmatic foreign-key check preventing a new outlet `CapexProject` from advancing from Fit-Out (`Gate 4`) to Launch Ready (`Gate 5`) until both `FSSAI` and `FIRE_NOC` are `VALID`. |
| **S3 Recycle Vault Lineage** | When a renewed licence PDF is uploaded, the previous `S3DocumentVaultAsset` is never deleted; it transitions to `RECYCLED` with `superseded_by_asset_id` pointing to the new SHA-256 object. |
</details>
<details>
<summary><strong>🗄️ 3B. PostgreSQL Schema DDL & Constraints (Click to Expand)</strong></summary>
```sql
-- Stop 1 Detailed Design DDL: 8 Core Compliance & Legal Objects (migrations/004_compliance_legal_standalone.sql)
CREATE SCHEMA IF NOT EXISTS compliance;
CREATE TABLE compliance.legal_entities (
entity_code VARCHAR(32) PRIMARY KEY,
legal_name VARCHAR(160) NOT NULL,
cin VARCHAR(32) NOT NULL UNIQUE,
gstin VARCHAR(20) NOT NULL,
pan VARCHAR(16) NOT NULL,
registered_address TEXT NOT NULL,
status VARCHAR(24) NOT NULL DEFAULT 'ACTIVE'
);
CREATE TABLE compliance.s3_vault_assets (
vault_asset_id UUID PRIMARY KEY,
s3_key VARCHAR(512) NOT NULL UNIQUE,
sha256_hex CHAR(64) NOT NULL,
file_name VARCHAR(255) NOT NULL,
file_size_bytes BIGINT NOT NULL,
lifecycle_state VARCHAR(24) NOT NULL DEFAULT 'ACTIVE'
CHECK (lifecycle_state IN ('ACTIVE','EXPIRING_SOON','EXPIRED','SUPERSEDED','RECYCLED')),
superseded_by_asset_id UUID REFERENCES compliance.s3_vault_assets(vault_asset_id),
uploaded_by VARCHAR(80) NOT NULL,
uploaded_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TABLE compliance.outlet_profiles (
outlet_code VARCHAR(32) PRIMARY KEY,
entity_code VARCHAR(32) NOT NULL REFERENCES compliance.legal_entities(entity_code),
outlet_format VARCHAR(24) NOT NULL CHECK (outlet_format IN ('CAFE','COMMISSARY','KIOSK','HQ')),
inspector_mode_enabled BOOLEAN NOT NULL DEFAULT TRUE,
overall_health VARCHAR(16) NOT NULL DEFAULT 'GOOD' CHECK (overall_health IN ('GOOD','CHECK','ACT_NOW'))
);
CREATE TABLE compliance.requirement_templates (
category_code VARCHAR(40) PRIMARY KEY,
title VARCHAR(120) NOT NULL,
is_launch_blocker BOOLEAN NOT NULL DEFAULT FALSE,
renewal_lead_days INT NOT NULL DEFAULT 90
);
CREATE TABLE compliance.licence_records (
licence_id UUID PRIMARY KEY,
outlet_code VARCHAR(32) NOT NULL REFERENCES compliance.outlet_profiles(outlet_code),
category_code VARCHAR(40) NOT NULL REFERENCES compliance.requirement_templates(category_code),
licence_no VARCHAR(128) NOT NULL,
issuing_authority VARCHAR(120) NOT NULL,
valid_from DATE NOT NULL,
valid_until DATE NOT NULL,
radar_bucket VARCHAR(16) NOT NULL DEFAULT 'VALID'
CHECK (radar_bucket IN ('VALID','90D','60D','30D','15D','7D','EXPIRED')),
vault_asset_id UUID NOT NULL REFERENCES compliance.s3_vault_assets(vault_asset_id),
UNIQUE (outlet_code, category_code, licence_no)
);
CREATE TABLE compliance.trademark_ip_records (
tm_id UUID PRIMARY KEY,
entity_code VARCHAR(32) NOT NULL REFERENCES compliance.legal_entities(entity_code),
application_no VARCHAR(64) NOT NULL UNIQUE,
mark_title VARCHAR(160) NOT NULL,
nice_class VARCHAR(16) NOT NULL,
valid_until DATE NOT NULL,
registry_status VARCHAR(32) NOT NULL DEFAULT 'REGISTERED',
vault_asset_id UUID NOT NULL REFERENCES compliance.s3_vault_assets(vault_asset_id)
);
CREATE TABLE compliance.commercial_leases (
lease_id UUID PRIMARY KEY,
outlet_code VARCHAR(32) NOT NULL REFERENCES compliance.outlet_profiles(outlet_code),
landlord_name VARCHAR(160) NOT NULL,
monthly_rent_inr NUMERIC(12,2) NOT NULL,
security_deposit_inr NUMERIC(12,2) NOT NULL,
lock_in_until DATE,
escalation_pct NUMERIC(5,2) NOT NULL DEFAULT 15.00,
next_escalation_date DATE,
lease_end_date DATE NOT NULL,
vault_asset_id UUID NOT NULL REFERENCES compliance.s3_vault_assets(vault_asset_id)
);
CREATE TABLE compliance.legal_notice_cases (
case_id UUID PRIMARY KEY,
case_ref_no VARCHAR(64) NOT NULL UNIQUE,
outlet_code VARCHAR(32) REFERENCES compliance.outlet_profiles(outlet_code),
authority_or_forum VARCHAR(160) NOT NULL,
severity VARCHAR(24) NOT NULL CHECK (severity IN ('P0_SHOW_CAUSE','P1_NOTICE','P2_QUERY')),
hearing_or_reply_due DATE NOT NULL,
status VARCHAR(24) NOT NULL DEFAULT 'OPEN_ACTION_REQUIRED',
vault_asset_id UUID NOT NULL REFERENCES compliance.s3_vault_assets(vault_asset_id)
);
-- =============================================================================
-- G1 DESIGN GATE OWNER SIGN-OFF LOCK (2026-10-22 22:39 IST & 22:44 IST · 100% APP 0 -> APP 6 LOCKED)
-- =============================================================================
-- A2: Outlet Manager / Cluster Manager approves Shift Swaps & Inter-Outlet Loans with automatic visibility/notification to City Head
ALTER TABLE staff_shift_rosters
ADD COLUMN IF NOT EXISTS swap_approved_by_id VARCHAR(32) REFERENCES users(id),
ADD COLUMN IF NOT EXISTS swap_approved_by_role VARCHAR(32) CHECK (swap_approved_by_role IN ('outlet_manager', 'cluster_manager')),
ADD COLUMN IF NOT EXISTS city_head_notified_at TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS visible_to_city_head_bool BOOLEAN NOT NULL DEFAULT TRUE;
ALTER TABLE staff_inter_outlet_loans
ADD COLUMN IF NOT EXISTS approved_by_role VARCHAR(32) CHECK (approved_by_role IN ('outlet_manager', 'cluster_manager')),
ADD COLUMN IF NOT EXISTS city_head_notified_at TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS visible_to_city_head_bool BOOLEAN NOT NULL DEFAULT TRUE;
-- A4: Seed configurable Governance & Reviewer slots in master_data_holders (SK-14, N-11, OA-06, OA-07)
INSERT INTO master_data_holders (domain_key, primary_department_key, holder_role_code, can_delegate_bool, description) VALUES
('hindi_reviewer', 'academy', 'hindi_reviewer', TRUE, 'SK-14 / N-11 Kiosk Hindi Copy Reviewer-of-Record'),
('quality_reviewer', 'ops', 'quality_reviewer', TRUE, 'BO-FB-TEMPLATES 16 Outlet Round Checklist Template Owner'),
('restricted_item_owner', 'ops', 'restricted_item_owner', TRUE, 'OA-06 Compliance Restricted-Item & Statutory Schedule Owner'),
('fitout_template_owner', 'projects', 'fitout_template_owner', TRUE, 'OA-07 Cafe Projects 42-Day Fit-Out Critical Path Template Owner')
ON CONFLICT (domain_key) DO UPDATE SET
holder_role_code = EXCLUDED.holder_role_code,
description = EXCLUDED.description;
```
</details>
<details>
<summary><strong>📂 3C. Source Corpus Mapping & Automated Verification Suite (Click to Expand)</strong></summary>
| Source Folder / Artifact | Files / Rows | Target Domain Object | Gate Status |
| :--- | :--- | :--- | :--- |
| `T1-8-U1..U5 Unit TDD Suite (tests/unit/test_t1_8_compliance.py)` | 12 fail-first unit tests (Radar 90/60/30/15/7d, Gate 4->5 lock, SHA-256 recycle) | `compliance.licence_records + s3_vault_assets` | **TDD SPEC READY** |
| `T1-8-S1..S4 Scope Isolation Matrix (TC-4)` | 4 role x route negative tests (UAT-17 sees 0; Outlet staff blocked from leases/cases) | `RBAC Middleware + /outlets/{code}/compliance` | **TDD SPEC READY** |
| `T1-8-V1..V6 Multi-Viewport Playwright Gate (TC-2 / SK-2)` | 6 viewports (1440, 1024, 768, 390, 360, 320px) in Chromium + WebKit-mobile | `Screen 1 (/compliance) + Screen 2 (1-Tap Inspector)` | **UI/UX SPEC READY** |
| `14 Source Legal & Compliance Folders (116 Files)` | 42 FSSAI/Trade + 19 Fire/PCB + 18 Labour/Metrology + 22 Leases/Ins + 15 IP/Notices | `All 8 compliance.* tables` | **100% MAPPED** |
**Verification Evidence:** Intake Approved by Owner (19:33 IST) -> Detailed 8-Object Schema, 22-Test Fail-First TDD Spec (tests/unit/test_t1_8_compliance.py + Playwright 320..1440px), and SK-1..15 2-Screen UI/UX Spec ready for Owner Sign-Off.
</details>

OneOps