context-forge
Version:
AI orchestration platform with autonomous teams, enhancement planning, migration tools, 25+ slash commands, checkpoints & hooks. Multi-IDE: Claude, Cursor, Windsurf, Cline, Copilot
256 lines (234 loc) • 6.59 kB
Markdown
# Framework Detection Patterns
## Overview
This document defines the patterns used to detect various frameworks and their versions.
## Pattern Structure
```typescript
interface FrameworkPattern {
framework: string;
files: string[]; // Required files
dependencies?: string[]; // npm dependencies
devDependencies?: string[]; // npm dev dependencies
content?: ContentPattern[]; // File content patterns
structure?: string[]; // Directory structure
priority: number; // Detection priority (higher = check first)
variants?: VariantPattern[]; // Framework variants (e.g., Next.js for React)
}
interface ContentPattern {
file: string;
pattern: RegExp;
weight: number; // Contribution to confidence
}
interface VariantPattern {
name: string;
dependencies?: string[];
files?: string[];
content?: ContentPattern[];
}
```
## Framework Patterns
### React
```typescript
{
framework: 'react',
files: ['package.json'],
dependencies: ['react', 'react-dom'],
content: [
{ file: '**/*.{js,jsx,ts,tsx}', pattern: /from ['"]react['"]/, weight: 10 },
{ file: '**/*.{js,jsx,ts,tsx}', pattern: /React\.Component/, weight: 5 }
],
structure: ['src'],
priority: 100,
variants: [
{
name: 'next.js',
dependencies: ['next'],
files: ['next.config.js', 'next.config.mjs'],
content: [{ file: 'pages/**/*', pattern: /export default/, weight: 10 }]
},
{
name: 'gatsby',
dependencies: ['gatsby'],
files: ['gatsby-config.js'],
structure: ['src/pages']
},
{
name: 'create-react-app',
files: ['public/index.html', 'src/App.js', 'src/App.tsx'],
devDependencies: ['react-scripts']
}
]
}
```
### Vue
```typescript
{
framework: 'vue',
files: ['package.json'],
dependencies: ['vue'],
content: [
{ file: '**/*.vue', pattern: /<template>/, weight: 20 },
{ file: '**/*.{js,ts}', pattern: /from ['"]vue['"]/, weight: 10 },
{ file: '**/*.{js,ts}', pattern: /createApp|Vue\.component/, weight: 15 }
],
priority: 95,
variants: [
{
name: 'nuxt',
dependencies: ['nuxt'],
files: ['nuxt.config.js', 'nuxt.config.ts'],
structure: ['pages', 'components']
},
{
name: 'vue-cli',
files: ['vue.config.js'],
structure: ['src/components', 'src/views']
},
{
name: 'vite-vue',
devDependencies: ['@vitejs/plugin-vue'],
files: ['vite.config.js', 'vite.config.ts']
}
]
}
```
### Angular
```typescript
{
framework: 'angular',
files: ['angular.json', 'package.json'],
dependencies: ['@angular/core', '@angular/common'],
content: [
{ file: '**/*.ts', pattern: /@Component\({/, weight: 20 },
{ file: '**/*.ts', pattern: /from ['"]@angular/, weight: 10 }
],
structure: ['src/app'],
priority: 90
}
```
### Express
```typescript
{
framework: 'express',
files: ['package.json'],
dependencies: ['express'],
content: [
{ file: '**/*.{js,ts}', pattern: /require\(['"]express['"]\)/, weight: 15 },
{ file: '**/*.{js,ts}', pattern: /from ['"]express['"]/, weight: 15 },
{ file: '**/*.{js,ts}', pattern: /app\.(get|post|put|delete|use)\(/, weight: 10 }
],
priority: 80
}
```
### Django
```typescript
{
framework: 'django',
files: ['manage.py', 'requirements.txt'],
content: [
{ file: 'manage.py', pattern: /django/, weight: 30 },
{ file: 'requirements.txt', pattern: /django/i, weight: 20 },
{ file: '**/*.py', pattern: /from django/, weight: 10 },
{ file: 'settings.py', pattern: /INSTALLED_APPS/, weight: 15 }
],
structure: ['apps', 'templates'],
priority: 85
}
```
### Ruby on Rails
```typescript
{
framework: 'rails',
files: ['Gemfile', 'config/routes.rb'],
content: [
{ file: 'Gemfile', pattern: /gem ['"]rails['"]/, weight: 30 },
{ file: 'config/routes.rb', pattern: /Rails\.application\.routes/, weight: 20 }
],
structure: ['app/controllers', 'app/models', 'app/views'],
priority: 85
}
```
### Laravel
```typescript
{
framework: 'laravel',
files: ['composer.json', 'artisan'],
content: [
{ file: 'composer.json', pattern: /"laravel\/framework"/, weight: 30 },
{ file: 'artisan', pattern: /Laravel/, weight: 20 }
],
structure: ['app/Http/Controllers', 'resources/views'],
priority: 80
}
```
### NestJS
```typescript
{
framework: 'nestjs',
files: ['package.json', 'nest-cli.json'],
dependencies: ['@nestjs/core', '@nestjs/common'],
content: [
{ file: '**/*.ts', pattern: /@Module\({/, weight: 20 },
{ file: '**/*.ts', pattern: /@Controller\(/, weight: 15 },
{ file: '**/*.ts', pattern: /from ['"]@nestjs/, weight: 10 }
],
priority: 85
}
```
### Spring Boot
```typescript
{
framework: 'spring-boot',
files: ['pom.xml', 'build.gradle'],
content: [
{ file: 'pom.xml', pattern: /spring-boot-starter/, weight: 30 },
{ file: 'build.gradle', pattern: /org\.springframework\.boot/, weight: 30 },
{ file: '**/*.java', pattern: /@SpringBootApplication/, weight: 25 },
{ file: '**/*.java', pattern: /@RestController/, weight: 15 }
],
structure: ['src/main/java', 'src/main/resources'],
priority: 80
}
```
### FastAPI
```typescript
{
framework: 'fastapi',
files: ['requirements.txt', 'pyproject.toml'],
content: [
{ file: 'requirements.txt', pattern: /fastapi/i, weight: 25 },
{ file: 'pyproject.toml', pattern: /fastapi/, weight: 25 },
{ file: '**/*.py', pattern: /from fastapi import/, weight: 20 },
{ file: '**/*.py', pattern: /FastAPI\(\)/, weight: 15 }
],
priority: 75
}
```
## Confidence Calculation
### Base Confidence Score:
- File match: +30 points
- Dependency match: +20 points per dependency (max 40)
- Content match: Based on weight
- Structure match: +10 points per directory
### Confidence Levels:
- 90-100: Very High (primary framework)
- 70-89: High (likely framework)
- 50-69: Medium (possible framework)
- 30-49: Low (some indicators)
- 0-29: Very Low (minimal indicators)
### Adjustments:
- Multiple framework indicators: -10 points each
- Missing expected files: -20 points
- Conflicting patterns: -15 points
## Version Detection
### Strategies by Framework:
1. **Package.json**: `dependencies` version
2. **Lock files**: Exact version from lock
3. **Config files**: Version in comments/settings
4. **Import analysis**: Version-specific imports
5. **File headers**: Version in generated files
### Priority Order:
1. Lock files (most accurate)
2. Package files (declared version)
3. Configuration files
4. Import statements
5. File content patterns