# Frontend Data Design Specification (`datadesign.md`)

A human-centered data presentation guide explaining how backend data is processed, grouped, and displayed across the website without overwhelming the user.

---

## 1. Core Philosophy: The 3-Layer Rule

Rather than dumping every raw backend statistic onto the screen, the website must organize data into **three distinct layers of depth**:

1. **Layer 1: The Human Verdict (Always Visible)**
   - Delivers an instant 1-second answer to: *Did it pass? How fast was it? Did anything break?*
   - Strictly limits the default screen to two numbers and one plain-English summary sentence.

2. **Layer 2: Actionable Error Triage (On-Demand Drawer)**
   - Only appears when the user taps `[ See Failures ]`.
   - Filters out successful noise and shows only broken endpoints, error status codes, and server response messages.

3. **Layer 3: Advanced Telemetry Drawer (For Power Users)**
   - Stays tucked away under a subtle link: `View Advanced Metrics`.
   - Contains deep engineering metrics ($p90$/$p99$ percentiles, bandwidth bytes, and raw cycle numbers).

---

## 2. Layer Specifications

### Layer 1: The Human Verdict
- **When All Requests Pass:**
  - Display a clear confirmation badge (`ALL PASSED`).
  - Show only two primary figures: Total Requests Completed and Average Speed (in milliseconds).
  - Include an insight sentence: e.g., *"System stayed rock-solid under load."*
- **When Failures Occur:**
  - Display a warning badge indicating the failure count.
  - Show the ratio of successful vs failed requests, along with the most frequent error type (e.g. `HTTP 504 Gateway Timeout`).
  - Include a plain-English sentence pinpointing where the system broke (e.g., *"Stable up to 100 users, then saturated at 150 users"*).
  - Provide an action button: `[ 🔍 See the X Failures ]`.

---

### Layer 2: Actionable Error Triage
- **Trigger:** Tapping `[ See Failures ]` opens this panel.
- **Form Factor:**
  - **Desktop:** A smooth slide-over panel on the right side of the screen.
  - **Mobile:** A bottom sheet that slides up with a swipe-down close handle.
- **Content Organization:**
  - **Grouped Summary Pills:** Group identical errors together with counts (e.g. `8× HTTP 504 Timeout`, `2× HTTP 429 Rate Limit`) so the user sees root causes at a glance.
  - **Expandable Failure Cards:**
    - Collapsed by default showing HTTP method, target URL, status code, and latency before failure.
    - Tapping a card unfolds the server's rejection message or response payload.
    - Provide a one-tap `Copy Payload` button for easy debugging.

---

### Layer 3: Advanced Telemetry Drawer
- **Trigger:** Tapping `View Advanced Metrics` expands this section quietly beneath the main verdict.
- **Content Organization:**
  - **Latency Distribution:** A compact visual gauge or ribbon displaying `Min`, `p50`, `p75`, `p90`, `p95`, `p99`, and `Max` response times.
  - **SLA Threshold:** A marker indicating the target response threshold (e.g., 300ms) with a breach callout if tail latency crossed it.
  - **Bandwidth Consumption:** Total data sent and received formatted into readable KB or MB, along with average payload size per request.
  - **Concurrency Breakdown (Load Tests Only):** A breakdown of each cycle showing active concurrency ramp-up and batch completion counts.

---

## 3. Data Processing Instructions

### 3.1. Concurrency Data Synthesis
1. Calculate the total requests sent, passed, and failed by summing across all cycle objects.
2. Scan the cycles in sequential order to identify the first cycle where failure rate exceeds 2%.
3. If a breaking cycle is found, extract its concurrency level and generate the saturation message stating the last stable level and the failing level.
4. If no cycle exceeds the failure threshold, declare 100% stability.
5. Group any error items in the diagnostics array by HTTP status code to produce the summary pill counts.

### 3.2. Sequence Workflow Synthesis
1. Order all numbered step records sequentially from first to last.
2. Check each step's condition result flag.
3. If any step failed, immediately identify the step index and extract the target endpoint and failure reason.
4. Set the verdict insight to describe exactly which step failed the workflow.
5. If all steps passed, generate a message confirming all sequential workflow steps completed successfully.

### 3.3. API Fuzzing & Validation Synthesis
1. Check if tail latency ($p99$) exceeds 3 times the median latency ($p50$).
2. If divergence is high, flag tail latency degradation in the summary.
3. Count the total parameters tested and total permutation values generated.
4. Present the parameter coverage as a clean pill tag on the summary card.

---

## 4. Responsive Viewport Rules

- **Mobile Viewports (< 640px):**
  - All cards are full-width and stacked vertically.
  - Error triage opens as an interactive bottom sheet with swipe-down dismissal.
  - No horizontal scrolling is permitted under any circumstances.
- **Tablet & Desktop Viewports (≥ 640px):**
  - Verdict card is centered with a comfortable reading width.
  - Error triage opens as a dedicated slide-over drawer anchored to the right screen edge.
  - Advanced telemetry expands horizontally with clean multi-column alignment.

---

## 5. Acceptance Checklist for Implementation
- [ ] Verdict card displays immediately after test completion with no more than 2 core numbers visible by default.
- [ ] No raw percentiles, byte counters, or complex formulas appear until explicitly requested by the user.
- [ ] Error triage drawer opens smoothly and isolates only failed requests.
- [ ] Copy button on failed response payloads copies the exact payload to clipboard.
- [ ] Viewport resizing scales cleanly from mobile phones to wide desktop monitors without layout breakages.
