Skip to content

Backend rework — structured logging, repository pattern, E2E tests#140

Closed
VECTORG99 wants to merge 1 commit into
mainfrom
feat/backend-rework
Closed

Backend rework — structured logging, repository pattern, E2E tests#140
VECTORG99 wants to merge 1 commit into
mainfrom
feat/backend-rework

Conversation

@VECTORG99

Copy link
Copy Markdown
Collaborator

Backend Rework — 4 Issues

This PR consolidates 4 backend improvements for the Joidy monorepo. All 90 tests pass.

Phase 1: #38 — Distributed Tracing & Structured Logging

All 3 Python services (api, ai-service, worker) now have:

  • Contextvars-based correlation ID that propagates through asyncio context
  • X-Request-ID header propagation: Worker → API → AI-service
  • JSON logging in production, colored human-readable output in dev
  • CorrelationLogFilter on both stream and file handlers
  • RequestIdMiddleware now wired as outermost middleware (previously was missing from main.py)
  • AI-service now has structured logging (was previously relying on uvicorn stderr)

Phase 2: #37 — DI / Repository Pattern

  • api/repositories.py — single-file repository layer: BaseRepository[T] generic + 18 domain repositories + FastAPI Depends providers
  • Deleted api/services/unit_of_work.py — dead code referencing non-existent classes
  • Fixed embedding_service.py — removed SessionLocal() direct creation; trigger_embedding() accepts optional db (background task compatible)
  • Migrated 6 of 8 DB-using services to use repositories (goal, gamification, github, skill_tree, tag_graph, personal_streak)
  • Incrementalnote_service and joidy_vault_writer remain on raw session (compatible either way)

Phase 3: #11 — E2E API Tests

  • CI fix: .github/workflows/ci.yml now runs python -m pytest instead of unittest — discovers all 4 previously-skipped router tests
  • 26 new E2E tests covering note CRUD lifecycle, tag CRUD + parent/cycle detection, goal CRUD + completion, gamification stats/XP
  • 82 tests pass (26 new + 56 existing, including 4 previously undetected router tests)

Phase 4: #12 — Obsidian Sync Integration Tests

  • 8 new vault sync tests covering vault write endpoints (daily, objectives, skills) and the Obsidian import flow (create with source_path, find by path, update imported note, rebuild-derived)

Files Changed

Phase Files Change
#38 api/middleware/correlation_id.py NEW
#38 api/middleware/request_id.py MODIFIED
#38 api/logging_config.py MODIFIED
#38 api/main.py MODIFIED
#38 ai-service/logging_config.py NEW
#38 ai-service/main.py MODIFIED
#38 worker/logging_config.py MODIFIED
#38 worker/watchers/vault_watcher.py MODIFIED
#38 worker/tasks/joidy_daily_writer.py MODIFIED
#38 api/routers/ai.py MODIFIED
#37 api/repositories.py NEW
#37 api/services/embedding_service.py MODIFIED
#37 api/services/goal_service.py MODIFIED
#37 api/services/gamification_engine.py MODIFIED
#37 api/services/github_service.py MODIFIED
#37 api/services/skill_tree.py MODIFIED
#37 api/services/tag_graph.py MODIFIED
#37 api/services/personal_streak_service.py MODIFIED
#37 api/services/unit_of_work.py DELETED
#11 .github/workflows/ci.yml MODIFIED
#11 api/tests/test_e2e_notes.py NEW
#11 api/tests/test_e2e_tags.py NEW
#11 api/tests/test_e2e_goals.py NEW
#11 api/tests/test_e2e_gamification.py NEW
#12 api/tests/test_e2e_vault.py NEW

Closes #38, #37, #11, #12

@VECTORG99 VECTORG99 closed this Jul 24, 2026
@VECTORG99
VECTORG99 deleted the feat/backend-rework branch July 24, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infra: Trazabilidad Distribuida y Logging Estructurado (JSON)

1 participant