|
| 1 | +# SLA Deadline Tracker — Module Boundaries |
| 2 | + |
| 3 | +This document defines the internal contracts, public interfaces, and dependency |
| 4 | +rules for each module inside the SLA Deadline Tracker tool. The tool is a V1, |
| 5 | +team-audience mini-product for response-SLA monitoring. It is built in |
| 6 | +isolation and is not wired into the main application yet. |
| 7 | + |
| 8 | +## 1. Module: Types (shared contracts) |
| 9 | + |
| 10 | +Location: `types/index.ts`. |
| 11 | + |
| 12 | +Responsibility: declares the shared TypeScript interfaces used across the tool. |
| 13 | +Owns no logic and imports nothing. |
| 14 | + |
| 15 | +Public API: |
| 16 | + |
| 17 | + export interface SlaTrackedItem { |
| 18 | + id: string; |
| 19 | + label: string; |
| 20 | + startedAt: string; // ISO-8601 |
| 21 | + deadlineAt: string | null; |
| 22 | + responded: boolean; |
| 23 | + respondedAt: string | null; |
| 24 | + } |
| 25 | + |
| 26 | + export interface SlaPolicy { |
| 27 | + responseBudgetMs: number; |
| 28 | + warnWindowMs: number; |
| 29 | + } |
| 30 | + |
| 31 | + export type SlaStatus = "responded" | "on-track" | "due-soon" | "breached"; |
| 32 | + |
| 33 | + export interface SlaEvaluation { |
| 34 | + itemId: string; |
| 35 | + status: SlaStatus; |
| 36 | + remainingMs: number; |
| 37 | + breached: boolean; |
| 38 | + responded: boolean; |
| 39 | + } |
| 40 | + |
| 41 | + export interface SlaSummary { |
| 42 | + total: number; |
| 43 | + responded: number; |
| 44 | + onTrack: number; |
| 45 | + dueSoon: number; |
| 46 | + breached: number; |
| 47 | + } |
| 48 | + |
| 49 | +Dependencies: no imports from `services/`, `hooks/`, `components/`, or the main |
| 50 | +application. |
| 51 | + |
| 52 | +## 2. Module: Services (business logic) |
| 53 | + |
| 54 | +Location: `services/slaTracker.ts`. |
| 55 | + |
| 56 | +Responsibility: encapsulates all framework-free SLA logic — per-item status |
| 57 | +evaluation, aggregate summarization, and deadline computation. The engine is |
| 58 | +pure and deterministic; time is injected (`now`) so evaluations are |
| 59 | +reproducible. Services never import React and never reach outside this folder. |
| 60 | + |
| 61 | +Public API: |
| 62 | + |
| 63 | + export function evaluateSla( |
| 64 | + item: SlaTrackedItem, |
| 65 | + policy: SlaPolicy, |
| 66 | + now: number, |
| 67 | + ): SlaEvaluation; |
| 68 | + |
| 69 | + export function summarizeSla( |
| 70 | + items: readonly SlaTrackedItem[], |
| 71 | + policy: SlaPolicy, |
| 72 | + now: number, |
| 73 | + ): SlaSummary; |
| 74 | + |
| 75 | + export function computeDeadline( |
| 76 | + startedAt: string, |
| 77 | + policy: SlaPolicy, |
| 78 | + ): string; |
| 79 | + |
| 80 | +Dependencies: |
| 81 | + |
| 82 | +- Allowed to import: TypeScript types from `../types/`. |
| 83 | +- Forbidden: React or hooks, presentational components, main app stores or |
| 84 | + APIs, any networking, and any use of `Date.now()` inside the engine (callers |
| 85 | + supply `now`). |
| 86 | + |
| 87 | +## 3. Module: Fixtures (deterministic sample data) |
| 88 | + |
| 89 | +Location: `fixtures/sla.fixture.ts`. |
| 90 | + |
| 91 | +Responsibility: provides deterministic sample items and a standard policy for |
| 92 | +tests. No production data, no network. |
| 93 | + |
| 94 | +Public API: |
| 95 | + |
| 96 | + export const STANDARD_SLA_POLICY: SlaPolicy; |
| 97 | + export const FIXED_NOW: number; |
| 98 | + export const SAMPLE_ITEMS: SlaTrackedItem[]; |
| 99 | + |
| 100 | +Dependencies: allowed to import types from `../types/` only. |
| 101 | + |
| 102 | +## 4. Module: Tests |
| 103 | + |
| 104 | +Location: `tests/slaTracker.test.ts`. |
| 105 | + |
| 106 | +Responsibility: unit coverage for the engine — every `SlaStatus` branch, |
| 107 | +determinism, large-array single-pass behavior, and deadline math. |
| 108 | + |
| 109 | +Dependencies: allowed to import `../services/`, `../fixtures/`, `../types/`. |
| 110 | +Forbidden to import anything outside the folder or the main app. |
| 111 | + |
| 112 | +## 5. Module: Hooks (React integration) — PLANNED, not implemented |
| 113 | + |
| 114 | +Location: `hooks/` (future). |
| 115 | + |
| 116 | +Responsibility (when built): synchronize the service with React components, |
| 117 | +managing the item list, loading/error state, and time-relative refreshes. Hooks |
| 118 | +must obtain `now` from a clock source and pass it into the engine; they must not |
| 119 | +introduce their own SLA math. |
| 120 | + |
| 121 | +Intended public shape: |
| 122 | + |
| 123 | + export function useSlaTracker( |
| 124 | + items: SlaTrackedItem[], |
| 125 | + policy: SlaPolicy, |
| 126 | + ): { summary: SlaSummary; evaluations: SlaEvaluation[]; refresh: () => void }; |
| 127 | + |
| 128 | +Dependencies (when built): allowed to import React hooks, the service from |
| 129 | +`../services/`, and types from `../types/`. Forbidden: presentational |
| 130 | +components and core app state contexts. |
| 131 | + |
| 132 | +## 6. Module: Components (user interface) — PLANNED, not implemented |
| 133 | + |
| 134 | +Location: `components/` (future). |
| 135 | + |
| 136 | +Responsibility (when built): renders status badges, deadline lists, and |
| 137 | +breach alerts. Components stay presentational and delegate all logic to the |
| 138 | +hook. |
| 139 | + |
| 140 | +Dependencies (when built): allowed to import hooks from `../hooks/` and types |
| 141 | +from `../types/`. Forbidden: core app features, layout navigation, or importing |
| 142 | +service functions directly. |
| 143 | + |
| 144 | +## 7. Public API surface |
| 145 | + |
| 146 | +Location: `index.ts` — re-exports the engine and types. Future UI/integration |
| 147 | +work should import **only** from `index.ts`, never from `services/` internals. |
| 148 | + |
| 149 | +## Import rules checklist |
| 150 | + |
| 151 | +- [ ] Only import from files inside `tools/v1/team/sla-deadline-tracker/`. |
| 152 | +- [ ] Maintain a one-way dependency flow: components → hooks → services → types. |
| 153 | +- [ ] No circular dependencies. |
| 154 | +- [ ] All shared interfaces are imported from `types/`. |
| 155 | +- [ ] No path may ever import from `src/`, the app shell, routing, inbox |
| 156 | + architecture, wallet/Stellar core, or the design system. |
| 157 | +- [ ] The engine never calls `Date.now()`; `now` is always supplied by the |
| 158 | + caller. |
0 commit comments