---
id: T03
parent: S02
milestone: M001
provides: []
requires: []
affects: []
key_files: ["engine/api/routes.py", "engine/tests/test_api.py"]
key_decisions: ["DXF output returned as raw bytes with application/dxf content-type and metadata in X-Kerf-Metadata header", "JSON output nests generate_json result as parsed object inside envelope", "_format_response() shared helper for consistent response shaping across endpoints"]
patterns_established: []
drill_down_paths: []
observability_surfaces: []
duration: ""
verification_result: "All 35 API integration tests pass (cd engine && python -m pytest tests/test_api.py -v). Full suite of 169 tests across all modules pass clean (cd engine && python -m pytest tests/ -v)."
completed_at: 2026-03-26T04:39:50.412Z
blocker_discovered: false
---

# T03: Wire post-processing into /engine/trace, add output_format routing for svg/dxf/json, and create /engine/simplify endpoint with 35 passing integration tests

> Wire post-processing into /engine/trace, add output_format routing for svg/dxf/json, and create /engine/simplify endpoint with 35 passing integration tests

## What Happened
---
id: T03
parent: S02
milestone: M001
key_files:
  - engine/api/routes.py
  - engine/tests/test_api.py
key_decisions:
  - DXF output returned as raw bytes with application/dxf content-type and metadata in X-Kerf-Metadata header
  - JSON output nests generate_json result as parsed object inside envelope
  - _format_response() shared helper for consistent response shaping across endpoints
duration: ""
verification_result: passed
completed_at: 2026-03-26T04:39:50.423Z
blocker_discovered: false
---

# T03: Wire post-processing into /engine/trace, add output_format routing for svg/dxf/json, and create /engine/simplify endpoint with 35 passing integration tests

**Wire post-processing into /engine/trace, add output_format routing for svg/dxf/json, and create /engine/simplify endpoint with 35 passing integration tests**

## What Happened

Rewrote engine/api/routes.py to integrate the full post-processing and output pipeline. After vectorization, SVG output now flows through postprocess_svg() for RDP simplification, island detection, and node counting. Added output_format routing (svg/dxf/json) using generators from the output module. Created /engine/simplify endpoint that accepts SVG upload + epsilon + output_format. Built _format_response() shared helper for consistent response shaping. DXF returns raw bytes with metadata in X-Kerf-Metadata header. Wrote 35 integration tests covering all format combinations for both endpoints.

## Verification

All 35 API integration tests pass (cd engine && python -m pytest tests/test_api.py -v). Full suite of 169 tests across all modules pass clean (cd engine && python -m pytest tests/ -v).

## Verification Evidence

| # | Command | Exit Code | Verdict | Duration |
|---|---------|-----------|---------|----------|
| 1 | `cd engine && .venv/bin/python -m pytest tests/test_api.py -v` | 0 | ✅ pass | 720ms |
| 2 | `cd engine && .venv/bin/python -m pytest tests/ -v` | 0 | ✅ pass | 860ms |


## Deviations

Removed old _extract_svg_metadata() regex-based function, replaced entirely by postprocess_svg() pipeline. DXF responses use raw Response with binary content + X-Kerf-Metadata header instead of JSON envelope.

## Known Issues

None.

## Files Created/Modified

- `engine/api/routes.py`
- `engine/tests/test_api.py`


## Deviations
Removed old _extract_svg_metadata() regex-based function, replaced entirely by postprocess_svg() pipeline. DXF responses use raw Response with binary content + X-Kerf-Metadata header instead of JSON envelope.

## Known Issues
None.
