refactor(edda-serve): split lib.rs into api/ sub-modules#383
Conversation
Split foundational types out of the 8.7K-line lib.rs into dedicated files: - error.rs: AppError enum and IntoResponse impl - state.rs: ServeConfig, AppState, ChronicleContext, PairingRequest - helpers.rs: validate_iso8601, time_now_rfc3339 - middleware.rs: auth_middleware, is_localhost, generate_pairing_token Part of GH-375. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract all HTTP handler functions from the monolithic lib.rs (8.7K lines) into 12 domain-specific modules under api/: - auth.rs: device pairing endpoints - events.rs: health, status, context, decisions, log, note, decide, karvi - drafts.rs: draft approval workflow - telemetry.rs: cycle telemetry ingest and stats - snapshots.rs: snapshot CRUD, village stats, patterns - analytics.rs: recap, overview, projects - dashboard.rs: dashboard JSON + compute_attention - metrics.rs: quality, controls, overview metrics, trends - policy.rs: scope check, authz, approval, tool-tier - briefs.rs: task briefs, actors, dashboard HTML - stream.rs: SSE event stream - ingestion.rs: ingestion evaluate/records/suggestions Each module exports routes() for the test router and public_routes()/protected_routes() for the production server. lib.rs production code reduced to ~135 lines (entrypoint + mod declarations). All 106 tests pass, zero clippy warnings. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code Review: PR #383 (Round 1) — LGTM 🎉All P0 and P1 issues have been resolved. SummaryThis PR cleanly splits the 8,781-line
Minor Observation (not blocking)The bidirectional dependency between Verdict: LGTM ✅No critical or high-priority issues remaining. This PR is ready for merge. Completed after 1 round(s) of automated review-fix loop |
Summary
edda-serve/src/lib.rsinto 16 focused files undersrc/api/andsrc/lib.rsreduced from ~4,400 lines to ~135 lines (mod declarations +serve()entrypoint)routes()/public_routes()/protected_routes()— router-per-module pattern eliminates the route duplication betweenserve()and testrouter()error.rs,state.rs,helpers.rs,middleware.rsNew file structure
Verification
edda_serve::serve()andedda_serve::ServeConfigCloses #375
Test plan
cargo check -p edda-serve— compiles cleancargo check -p edda-serve --tests— test compilation cleancargo test -p edda-serve— 106/106 tests passcargo clippy -p edda-serve --all-targets— zero warningscargo fmt -p edda-serve— formatting clean🤖 Generated with Claude Code