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:
- Serve files via static file middleware
- 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
APIs/backend-ai-api/src/app/module-files/module-files.controller.tsAPIs/backend-ai-api/src/app/module-files/module-files.service.tsAPIs/backend-ai-api/src/app/module-files/module-files.types.tsAPIs/backend-vitto-api/src/app/module-generation/validation/auto-correction.service.ts
🔗 Related
- Decision ID:
dev_1772110522966_5vu9z3j - Session: 142
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation