Pattern: Backend Module Files API: How to serve generated module file...

Documentation for Sessions

🎨 Pattern: Backend Module Files API: How to serve generated module file...

Date: 2026-02-26
Time: 12:55:22 UTC
Session: gspace1-142.20
Agent: angular
Confidence: 93%
Status: ✅ Documented


📋 Decision Context

Question:

Backend Module Files API: How to serve generated module files from disk safely with AI-assisted editing?

Task: Not specified


🎯 Decision Made

Chosen:

Build a dedicated controller with path traversal protection and AI refine endpoint

Options Considered:

  1. Serve files via static file middleware
  2. Build a dedicated controller with path traversal protection and AI refine endpoint

💭 Reasoning

DESIGN: ModuleFilesController in backend-ai-api provides 4 endpoints: GET /structure (file tree), GET /file?path= (content), PUT /file?path= (write), POST /refine (AI edit). Security: slug validated via regex /^[a-z0-9][a-z0-9-_]*$/, file paths normalized and checked for '..' and absolute paths, resolved paths verified via path.resolve() startsWith check. Files live at {workspaceRoot}/modules/{slug}/... which matches the generation pipeline's output path (process.cwd() + '/modules/' + slug). AI refine uses Anthropic directly with Angular 20 coding rules in the system prompt, returns { original, modified, diff, explanation }. KNOWN GAP: AutoCorrectionService from backend-vitto-api (regex-based LLM error fixes) is NOT integrated. AI refine output skips corrections for: wrong tenant patterns, missing ChangeDetectionStrategy, Promise-to-Observable rewrites, missing HTML/SCSS template generation. Impact: medium — users will see fixable lint errors after AI edits. WHAT WOULD FIX THIS: Import AutoCorrectionService or duplicate its regex rules in ModuleFilesService.writeFileContent() as a post-processing step. WHAT WOULD MAKE THIS WRONG: If the generation pipeline changes its output directory from modules/{slug}/ to something else, all file endpoints break silently.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation