# Execution Prompt: Streaming Simplification

You are implementing `STREAMING_SIMPLIFICATION` in `/home/matiss/Documents/Final Year Project`.

## Objective
Deliver a WebRTC-only streaming architecture for this codebase by implementing the four artifacts:
1. `docs/STREAMING_SIMPLIFICATION_IMPLEMENTATION_PLAN.md`
2. `docs/STREAMING_SIMPLIFICATION_ABSOLUTE_CHECKLIST.md`
3. `docs/STREAMING_SIMPLIFICATION_VALIDATION_MATRIX.md`
4. This execution prompt.

## Governing constraints
- Preserve device token auth and role checks.
- Keep request/accept/end endpoints and WebRTC signaling functional.
- Remove socket JPEG frame fallback from runtime path.
- Keep rollback-capable behavior using `SIMPLE_STREAMING` where possible.
- Do not reintroduce any media-path dependency on mock provider endpoints.

## Execution sequence (strict)

1. Implement all backend stream endpoint and session-state simplifications first.
2. Simplify realtime gateway signaling path second.
3. Update web frontend streaming controller and pages.
4. Update mobile frontend streaming behavior.
5. Update docs, config notes, and OpenAPI/event description.
6. Run validation matrix gating; do not mark complete until all required evidence rows are filled.

## Completion gates

### Gate A — Backend
- `Backend/routes/streams.ts` follows simplified lifecycle only.
- `Backend/realtime/gateway.ts` contains no frame-relay path in active flow.
- Unauthorized access checks remain strict and verifiable.

### Gate B — Frontends
- Web and Mobile each have one stream state machine and one active rendering strategy.
- No scheduled frame-relay sender/receiver code remains in runtime path.
- End-of-stream cleanup is deterministic and symmetric.

### Gate C — Delivery readiness
- OpenAPI/docs updated for simplified contract.
- Feature flag/rollback documented.
- Validation matrix entries populated from observed evidence.

## Evidence rules

For every checklist line in `docs/STREAMING_SIMPLIFICATION_ABSOLUTE_CHECKLIST.md`:
1. Fill corresponding row in `docs/STREAMING_SIMPLIFICATION_VALIDATION_MATRIX.md` from pending -> done.
2. Populate columns:
   - **Code Evidence**: file path + symbols/line references
   - **Test Evidence**: command output or test report artifact names
   - **Runtime Evidence**: screenshot/video/log excerpt references and scenario details
3. Keep one evidence item per row if possible; if blocked, include blocker and retry plan.

## Required validation commands (when execution resumes)

- Backend: validate API/types/contracts compile/build and lint status.
- Gateway: static check that `stream:frame` handlers are absent in effective runtime mode.
- Frontend: build check for both web and mobile after removing unused imports/state.
- Runtime smoke checks:
  - client request -> camera accept -> stream start -> stream end
  - unauthorized request rejection
  - cleanup path after end and reconnect

## Final report format

Return a final report with:
1. Completed tasks grouped by file.
2. Validation matrix fully updated.
3. Any deviations from this spec and why.
4. Exact first and second risk identified after rollout.

Do not introduce additional assumptions not covered in the checklist without updating the checklist and matrix.
