tractatus/src/routes/projects.routes.js
TheFlow c96ad31046 feat: implement Rule Manager and Project Manager admin systems
Major Features:
- Multi-project governance with Rule Manager web UI
- Project Manager for organizing governance across projects
- Variable substitution system (${VAR_NAME} in rules)
- Claude.md analyzer for instruction extraction
- Rule quality scoring and optimization

Admin UI Components:
- /admin/rule-manager.html - Full-featured rule management interface
- /admin/project-manager.html - Multi-project administration
- /admin/claude-md-migrator.html - Import rules from Claude.md files
- Dashboard enhancements for governance analytics

Backend Implementation:
- Controllers: projects, rules, variables
- Models: Project, VariableValue, enhanced GovernanceRule
- Routes: /api/projects, /api/rules with full CRUD
- Services: ClaudeMdAnalyzer, RuleOptimizer, VariableSubstitution
- Utilities: mongoose helpers

Documentation:
- User guides for Rule Manager and Projects
- Complete API documentation (PROJECTS_API, RULES_API)
- Phase 3 planning and architecture diagrams
- Test results and error analysis
- Coding best practices summary

Testing & Scripts:
- Integration tests for projects API
- Unit tests for variable substitution
- Database migration scripts
- Seed data generation
- Test token generator

Key Capabilities:
 UNIVERSAL scope rules apply across all projects
 PROJECT_SPECIFIC rules override for individual projects
 Variable substitution per-project (e.g., ${DB_PORT} → 27017)
 Real-time validation and quality scoring
 Advanced filtering and search
 Import from existing Claude.md files

Technical Details:
- MongoDB-backed governance persistence
- RESTful API with Express
- JWT authentication for admin endpoints
- CSP-compliant frontend (no inline handlers)
- Responsive Tailwind UI

This implements Phase 3 architecture as documented in planning docs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 17:16:51 +13:00

105 lines
2.5 KiB
JavaScript

/**
* Projects Routes
*
* Routes for managing projects in the multi-project governance system.
* All routes require admin authentication.
*/
const express = require('express');
const router = express.Router();
const projectsController = require('../controllers/projects.controller');
const variablesController = require('../controllers/variables.controller');
const { asyncHandler } = require('../middleware/error.middleware');
const { validateRequired } = require('../middleware/validation.middleware');
const { authenticateToken, requireRole } = require('../middleware/auth.middleware');
/**
* All routes require admin authentication
*/
router.use(authenticateToken);
router.use(requireRole('admin'));
// Global variables endpoint (before /:id to avoid route conflict)
router.get(
'/variables/global',
asyncHandler(variablesController.getGlobalVariables)
);
// Statistics endpoint (before /:id to avoid route conflict)
router.get(
'/stats',
asyncHandler(projectsController.getProjectStatistics)
);
// Get all projects
router.get(
'/',
asyncHandler(projectsController.getAllProjects)
);
// Get single project by ID
router.get(
'/:id',
asyncHandler(projectsController.getProjectById)
);
// Create new project
router.post(
'/',
validateRequired(['id', 'name']),
asyncHandler(projectsController.createProject)
);
// Update existing project
router.put(
'/:id',
asyncHandler(projectsController.updateProject)
);
// Delete project (soft delete by default, ?hard=true for permanent)
router.delete(
'/:id',
asyncHandler(projectsController.deleteProject)
);
// ========== Project-specific Variable Routes ==========
// Validate project variables (check for missing)
router.get(
'/:projectId/variables/validate',
asyncHandler(variablesController.validateProjectVariables)
);
// Get all variables for a project
router.get(
'/:projectId/variables',
asyncHandler(variablesController.getProjectVariables)
);
// Batch create/update variables
router.post(
'/:projectId/variables/batch',
validateRequired(['variables']),
asyncHandler(variablesController.batchUpsertVariables)
);
// Create or update variable (upsert)
router.post(
'/:projectId/variables',
validateRequired(['variableName', 'value']),
asyncHandler(variablesController.createOrUpdateVariable)
);
// Update existing variable
router.put(
'/:projectId/variables/:variableName',
asyncHandler(variablesController.updateVariable)
);
// Delete variable
router.delete(
'/:projectId/variables/:variableName',
asyncHandler(variablesController.deleteVariable)
);
module.exports = router;