Architecture: Universe deletion leaves orphaned data across 6+ collections...

Documentation for Sessions

🏗️ Architecture: Universe deletion leaves orphaned data across 6+ collections...

Date: 2026-03-23
Time: 13:53:55 UTC
Session: gspace1-251.8
Agent: backend
Confidence: 95%
Status: ✅ Documented


📋 Decision Context

Question:

Universe deletion leaves orphaned data across 6+ collections and git repositories. Generation manifests, deployment records, draft sessions, galaxies, and GitLab/Hetzner repos are never cleaned up.

Task: Not specified


🎯 Decision Made

Chosen:

Added cascade cleanup to SpacesService.deleteUniverse(): (1) generation_manifests deleteMany, (2) deployments deleteMany, (3) draft_sessions deleteMany, (4) galaxiesService.deleteByUniverse() (existed but was never called), (5) gitProvider.deleteRepository(). All wrapped in try/catch to be non-blocking. Cross-service AI data (backend-ai-api) intentionally NOT included to avoid hard dependency.

Options Considered:

  1. Synchronous HTTP call to backend-ai-api for cross-service cleanup
  2. Event-driven cascade via message queue (recommended for future)
  3. Direct MongoDB connection to ai-api database (violates boundaries)
  4. Scheduled orphan cleanup job (complementary solution)
  5. Local cascade only, no cross-service dependency (chosen)

💭 Reasoning

Universe deletion must be idempotent and non-blocking — each cascade step is wrapped in try/catch so failure of one doesn't block others. GitLab 404 is expected (repo may never have been created). Cross-service cleanup (backend-ai-api MongoDB) would create a hard runtime dependency between backend-api and backend-ai-api, violating the architectural principle that backends can operate independently. This should be solved via event-driven cascade (emit UniverseDeleted event, let ai-api subscribe) or a scheduled orphan cleanup job.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation