Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 22x | import { PromptTemplate, PromptSlot, ValidationRule } from '../types';
export class TemplateRegistry {
private templates: Map<string, PromptTemplate> = new Map();
constructor() {
this.registerBuiltInTemplates();
}
private registerBuiltInTemplates(): void {
this.register(this.createProjectKickstart());
this.register(this.createFrontendDesign());
this.register(this.createBackendDesign());
this.register(this.createDatabaseSchema());
this.register(this.createAuthSetup());
this.register(this.createDeploymentConfig());
this.register(this.createComponentTemplate());
this.register(this.createApiEndpoint());
this.register(this.createCrudPattern());
this.register(this.createErrorHandling());
this.register(this.createTestGeneration());
}
private createProjectKickstart(): PromptTemplate {
const slots: PromptSlot[] = [
{ name: 'projectName', type: 'string', required: true, description: 'Project name' },
{ name: 'description', type: 'string', required: true, description: 'High-level project description' },
{ name: 'techStack', type: 'array', required: false, default: ['node', 'react'], description: 'Preferred tech stack' },
{ name: 'complexity', type: 'enum', required: true, options: ['simple', 'moderate', 'complex'], description: 'Project complexity' },
];
const rules: ValidationRule[] = [
{ type: 'style', rule: 'Must generate valid technology recommendations', severity: 'error', autoFix: false },
{ type: 'syntax', rule: 'Output must be valid YAML/JSON', severity: 'error', autoFix: true },
];
return {
id: 'project-kickstart',
level: 'project',
category: 'initialization',
template: `You are an expert software architect. Given the following project requirements, generate a comprehensive project scaffold including:
1. Architecture diagram (component tree, data flow)
2. Recommended tech stack with justification
3. Task breakdown into modules
4. High-level timeline
Project: {{projectName}}
Description: {{description}}
Complexity: {{complexity}}
Preferred Stack: {{techStack}}
Output as a structured YAML manifest.`,
slots,
validationRules: rules,
contextRequirements: [],
};
}
private createFrontendDesign(): PromptTemplate {
const slots: PromptSlot[] = [
{ name: 'framework', type: 'enum', required: true, options: ['react', 'vue', 'svelte', 'angular', 'vanilla'], description: 'Frontend framework' },
{ name: 'theme', type: 'enum', required: true, options: ['material', 'bootstrap', 'tailwind', 'custom'], description: 'UI theme system' },
{ name: 'primaryColor', type: 'string', required: true, description: 'Primary brand color (hex)' },
{ name: 'features', type: 'array', required: true, description: 'List of UI features/pages' },
{ name: 'accessibility', type: 'enum', required: false, options: ['wcag_a', 'wcag_aa', 'wcag_aaa'], default: 'wcag_aa', description: 'Accessibility target' },
];
const rules: ValidationRule[] = [
{ type: 'accessibility', rule: 'ARIA labels on all interactive elements', severity: 'error', autoFix: true },
{ type: 'accessibility', rule: 'Color contrast ratio >= 4.5:1 for normal text', severity: 'error', autoFix: true },
{ type: 'performance', rule: 'Core Web Vitals targets (LCP < 2.5s, FID < 100ms, CLS < 0.1)', severity: 'error', autoFix: false },
{ type: 'style', rule: '60-30-10 color rule application', severity: 'warning', autoFix: false },
];
return {
id: 'frontend-design',
level: 'feature',
category: 'frontend',
template: `Generate a complete {{framework}} frontend application using {{theme}} design system with primary color {{primaryColor}}.
Features to implement:
{{features}}
Requirements:
- Material Design 3 principles (responsive grid, typography scale, elevation tokens)
- {{accessibility}} compliance with ARIA labels, keyboard navigation, focus management
- Semantic HTML5 with progressive enhancement
- 60-30-10 color rule using the palette
- Service worker for offline caching
- Critical CSS extraction and lazy loading
- Responsive breakpoints: mobile (<768px), tablet (768-1024px), desktop (>1024px)
Generate:
1. Component tree structure
2. Each component with full HTML/CSS/JS
3. Theme configuration (CSS custom properties)
4. Route configuration
5. Responsive layout system`,
slots,
validationRules: rules,
contextRequirements: ['project-description', 'color-palette'],
};
}
private createBackendDesign(): PromptTemplate {
const slots: PromptSlot[] = [
{ name: 'framework', type: 'enum', required: true, options: ['express', 'flask', 'fastapi', 'django'], description: 'Backend framework' },
{ name: 'language', type: 'enum', required: true, options: ['typescript', 'python', 'go'], description: 'Server language' },
{ name: 'apiStyle', type: 'enum', required: true, options: ['rest', 'graphql'], description: 'API architecture' },
{ name: 'entities', type: 'array', required: true, description: 'Data entities with fields' },
];
const rules: ValidationRule[] = [
{ type: 'security', rule: 'Input sanitization on all endpoints', severity: 'error', autoFix: true },
{ type: 'security', rule: 'Rate limiting on auth endpoints', severity: 'error', autoFix: true },
{ type: 'security', rule: 'CORS configuration with explicit origins', severity: 'error', autoFix: true },
{ type: 'style', rule: 'Standardized error response format', severity: 'error', autoFix: false },
];
return {
id: 'backend-design',
level: 'feature',
category: 'backend',
template: `Generate a {{framework}} {{apiStyle}} API server in {{language}}.
Entities:
{{entities}}
Requirements:
- Input sanitization and validation middleware
- Rate limiting configuration
- CORS policy with CSP headers
- Structured error handling with consistent response format
- Request/Response logging middleware
- Health check endpoint
- OpenAPI/Swagger documentation generation
For each entity, create:
1. Model/schema definition
2. Full CRUD controller with validation
3. Route definitions
4. Middleware chains
5. Error handling for edge cases`,
slots,
validationRules: rules,
contextRequirements: ['entity-definitions', 'auth-strategy'],
};
}
private createDatabaseSchema(): PromptTemplate {
const slots: PromptSlot[] = [
{ name: 'dbType', type: 'enum', required: true, options: ['postgresql', 'mysql', 'mongodb', 'dynamodb'], description: 'Database type' },
{ name: 'orm', type: 'enum', required: false, options: ['prisma', 'typeorm', 'sequelize', 'mongoose'], description: 'ORM choice' },
{ name: 'entities', type: 'array', required: true, description: 'Entity definitions with fields and relations' },
{ name: 'indexing', type: 'array', required: false, description: 'Index strategy definitions' },
];
const rules: ValidationRule[] = [
{ type: 'syntax', rule: 'Valid SQL/NoSQL schema syntax', severity: 'error', autoFix: true },
{ type: 'performance', rule: 'Indexes on foreign keys and frequently queried columns', severity: 'warning', autoFix: false },
{ type: 'security', rule: 'No hardcoded credentials in connection strings', severity: 'error', autoFix: true },
];
return {
id: 'database-schema',
level: 'feature',
category: 'database',
template: `Design a {{dbType}} database schema.
ORM: {{orm}}
Entities: {{entities}}
Indexing strategy: {{indexing}}
Requirements:
- Foreign key constraints with cascade behavior
- UUID primary keys for all entities
- Timestamps (createdAt, updatedAt) on all tables
- Soft delete support where appropriate
- Migration scripts (up and down)
- Seed data for development
- Query optimization hints and indexing strategy
- Connection pooling configuration`,
slots,
validationRules: rules,
contextRequirements: ['entity-definitions', 'relational-map'],
};
}
private createAuthSetup(): PromptTemplate {
const slots: PromptSlot[] = [
{ name: 'strategy', type: 'array', required: true, description: 'Auth strategies (oauth2, jwt, session, sso)' },
{ name: 'roles', type: 'array', required: true, description: 'RBAC role definitions' },
{ name: 'sessionType', type: 'enum', required: true, options: ['stateless', 'stateful'], description: 'Session management type' },
];
const rules: ValidationRule[] = [
{ type: 'security', rule: 'CSRF protection enabled', severity: 'error', autoFix: true },
{ type: 'security', rule: 'Secure HTTP-only cookies for JWT', severity: 'error', autoFix: true },
{ type: 'security', rule: 'Password hashing with bcrypt/argon2', severity: 'error', autoFix: true },
{ type: 'security', rule: 'Rate limiting on login/register endpoints', severity: 'error', autoFix: true },
];
return {
id: 'auth-setup',
level: 'feature',
category: 'authentication',
template: `Generate complete authentication and authorization system.
Strategies: {{strategy}}
Roles: {{roles}}
Session Management: {{sessionType}}
Requirements:
- OAuth 2.0 flows with PKCE for SPAs
- JWT with refresh token rotation
- Role-based access control (RBAC) middleware
- CSRF token management
- Security headers (CSP, X-Frame-Options, HSTS)
- Password policies (min length, complexity)
- Account lockout after failed attempts
- Session invalidation on password change
- Audit logging for auth events`,
slots,
validationRules: rules,
contextRequirements: ['entity-definitions', 'api-endpoints'],
};
}
private createDeploymentConfig(): PromptTemplate {
const slots: PromptSlot[] = [
{ name: 'provider', type: 'enum', required: true, options: ['aws', 'gcp', 'azure', 'vercel', 'netlify'], description: 'Cloud provider' },
{ name: 'containerization', type: 'enum', required: true, options: ['docker', 'kubernetes', 'none'], description: 'Container strategy' },
{ name: 'ciCd', type: 'enum', required: true, options: ['githubActions', 'gitlabCi', 'circleCi'], description: 'CI/CD platform' },
{ name: 'monitoring', type: 'array', required: false, description: 'Monitoring tools' },
];
const rules: ValidationRule[] = [
{ type: 'security', rule: 'Secrets via environment variables, never hardcoded', severity: 'error', autoFix: true },
{ type: 'performance', rule: 'Health check endpoints configured', severity: 'error', autoFix: false },
{ type: 'style', rule: 'Immutable infrastructure pattern', severity: 'warning', autoFix: false },
];
return {
id: 'deployment-config',
level: 'feature',
category: 'deployment',
template: `Generate deployment configuration for {{provider}}.
Containerization: {{containerization}}
CI/CD: {{ciCd}}
Monitoring: {{monitoring}}
Requirements:
- Dockerfile with multi-stage builds
- docker-compose for local development
- Kubernetes manifests (if applicable): deployment, service, ingress, configmap, secrets
- CI/CD pipeline: lint, test, build, deploy stages
- Health checks and readiness probes
- Blue-green or canary deployment strategy
- Environment variable management
- Logging and monitoring setup
- SSL/TLS certificate configuration
- CDN configuration for static assets`,
slots,
validationRules: rules,
contextRequirements: ['app-structure', 'api-endpoints'],
};
}
private createComponentTemplate(): PromptTemplate {
return {
id: 'frontend-component',
level: 'implementation',
category: 'frontend',
template: `Generate a {{componentType}} component named {{componentName}} for {{framework}}.
Description: {{description}}
Props: {{props}}
State: {{state}}
Requirements:
- Semantic HTML5 elements
- ARIA labels and roles for accessibility
- Responsive using CSS Grid/Flexbox
- Material Design 3 elevation and spacing tokens
- Keyboard navigation support
- Focus management
- Loading and error states
- CSS custom properties for theming`,
slots: [
{ name: 'componentType', type: 'enum', required: true, options: ['page', 'form', 'card', 'navbar', 'modal', 'table', 'dashboard'], description: 'Component type' },
{ name: 'componentName', type: 'string', required: true, description: 'Component name' },
{ name: 'framework', type: 'string', required: true, description: 'Target framework' },
{ name: 'description', type: 'string', required: true, description: 'Component description' },
{ name: 'props', type: 'string', required: false, description: 'Props interface' },
{ name: 'state', type: 'string', required: false, description: 'State shape' },
],
validationRules: [
{ type: 'accessibility', rule: 'Button/links have discernible text', severity: 'error', autoFix: true },
{ type: 'style', rule: 'Follows BEM naming convention', severity: 'warning', autoFix: false },
],
contextRequirements: ['theme-config', 'component-tree'],
};
}
private createApiEndpoint(): PromptTemplate {
return {
id: 'api-endpoint',
level: 'implementation',
category: 'backend',
template: `Generate a {{method}} endpoint at {{path}} for {{entity}} in {{framework}}.
Description: {{description}}
Auth Required: {{authRequired}}
Request Body: {{requestBody}}
Response: {{responseBody}}
Requirements:
- Input validation with clear error messages
- Authentication/authorization middleware
- Proper HTTP status codes
- Error handling for all edge cases
- Request/Response type definitions
- Unit test coverage`,
slots: [
{ name: 'method', type: 'enum', required: true, options: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], description: 'HTTP method' },
{ name: 'path', type: 'string', required: true, description: 'Endpoint path' },
{ name: 'entity', type: 'string', required: true, description: 'Entity name' },
{ name: 'framework', type: 'string', required: true, description: 'Backend framework' },
{ name: 'description', type: 'string', required: true, description: 'Endpoint description' },
{ name: 'authRequired', type: 'boolean', required: true, description: 'Whether auth is required' },
{ name: 'requestBody', type: 'string', required: false, description: 'Request body schema' },
{ name: 'responseBody', type: 'string', required: false, description: 'Response body schema' },
],
validationRules: [
{ type: 'security', rule: 'SQL injection prevention on query params', severity: 'error', autoFix: true },
{ type: 'security', rule: 'XSS sanitization on responses', severity: 'error', autoFix: true },
],
contextRequirements: ['entity-schema', 'auth-middleware'],
};
}
private createCrudPattern(): PromptTemplate {
return {
id: 'crud-pattern',
level: 'implementation',
category: 'backend',
template: `Generate complete CRUD operations for {{entity}} in {{framework}}.
Fields: {{fields}}
Validations: {{validations}}
Relations: {{relations}}
Include:
- Create: POST /{{entityPlural}} with validation
- Read: GET /{{entityPlural}} with pagination, filtering, sorting
- Read one: GET /{{entityPlural}}/:id with 404 handling
- Update: PUT /{{entityPlural}}/:id with partial update support
- Delete: DELETE /{{entityPlural}}/:id with cascade checks
- Tests for each operation`,
slots: [
{ name: 'entity', type: 'string', required: true, description: 'Entity name' },
{ name: 'entityPlural', type: 'string', required: true, description: 'Pluralized entity name' },
{ name: 'framework', type: 'string', required: true, description: 'Backend framework' },
{ name: 'fields', type: 'string', required: true, description: 'Field definitions' },
{ name: 'validations', type: 'string', required: false, description: 'Validation rules' },
{ name: 'relations', type: 'string', required: false, description: 'Entity relations' },
],
validationRules: [
{ type: 'security', rule: 'Ownership checks on update/delete', severity: 'error', autoFix: false },
],
contextRequirements: ['entity-schema', 'relationships'],
};
}
private createErrorHandling(): PromptTemplate {
return {
id: 'error-handling',
level: 'implementation',
category: 'backend',
template: `Generate standardized error handling middleware for {{framework}}.
Include:
- Global error handler
- Custom error classes (ValidationError, AuthError, NotFoundError, etc.)
- Error response format: { error: { code, message, details } }
- HTTP status code mapping
- Production vs development error detail levels
- Error logging with request context`,
slots: [
{ name: 'framework', type: 'string', required: true, description: 'Backend framework' },
],
validationRules: [
{ type: 'security', rule: 'No stack traces in production errors', severity: 'error', autoFix: true },
],
contextRequirements: [],
};
}
private createTestGeneration(): PromptTemplate {
return {
id: 'test-generation',
level: 'implementation',
category: 'testing',
template: `Generate comprehensive tests for {{target}} using {{framework}}.
Coverage target: >80%
Include:
- Unit tests for all functions
- Integration tests for API endpoints
- Edge case coverage (null, empty, boundary values)
- Error path testing
- Mock strategies for external dependencies
- Test data factories/fixtures`,
slots: [
{ name: 'target', type: 'string', required: true, description: 'Test target (component, endpoint, module)' },
{ name: 'framework', type: 'enum', required: true, options: ['jest', 'pytest', 'mocha', 'vitest', 'cypress'], description: 'Test framework' },
],
validationRules: [
{ type: 'style', rule: 'Tests follow AAA pattern (Arrange, Act, Assert)', severity: 'warning', autoFix: false },
],
contextRequirements: ['entity-schema', 'api-routes'],
};
}
register(template: PromptTemplate): void {
this.templates.set(template.id, template);
}
get(id: string): PromptTemplate | undefined {
return this.templates.get(id);
}
listByCategory(category: string): PromptTemplate[] {
return Array.from(this.templates.values()).filter((t) => t.category === category);
}
listByLevel(level: string): PromptTemplate[] {
return Array.from(this.templates.values()).filter((t) => t.level === level);
}
getAll(): PromptTemplate[] {
return Array.from(this.templates.values());
}
}
|