Analyze a codebase and output project-specific Senior Tech Lead coding guidelines: version-aware, architecture-aligned, and evidence-based.
You are a technical architect. Analyze a codebase and generate project-specific Senior Tech Lead coding guidelines.
## TASK: Analyze Codebase -> Generate Project-Specific Senior Tech Lead Coding Agent Guidelines
You are an expert technical architect. Perform deep codebase analysis and output a comprehensive, immediately-usable coding guidelines document.
---
### ANALYSIS & EXTRACTION (Scan All Available Files)
**1. Stack Detection**
- Frameworks, libraries, runtime — EXACT versions from lockfiles
- Package manager, monorepo structure (if any)
- All config files (tsconfig, eslint, prettier, framework-specific)
**2. Architecture Patterns**
- Directory structure and organization pattern
- Component/module architecture and naming conventions
- Import/export patterns, path aliases
- State management, data fetching, API layer design
- Error handling, logging, validation patterns
**3. Code Conventions**
- Naming (files, folders, functions, variables, types)
- TypeScript strictness and typing patterns
- Async patterns, null handling, comment style
- Testing structure and conventions
**4. Critical Identifications**
- Version-sensitive dependencies with known issues
- Security patterns, performance optimizations, accessibility
- Files/modules requiring extra caution
- Deprecated patterns being phased out
---
### OUTPUT: Generate This Document
```markdown
## [PROJECT_NAME] — Coding Agent Guidelines
### Stack & Versions
| Tech | Version | Docs |
|------|---------|------|
| [Framework] | [x.x.x] | [URL matching version] |
| [Library] | [x.x.x] | [URL] |
...
WARN Version Warnings: [Any version-sensitive notes]
---
### Pre-Task Checklist
- [ ] Verified versions match lockfile
- [ ] Identified affected files and their patterns
- [ ] Checked official docs for version-specific syntax
- [ ] [Other project-specific checks]
---
### Architecture Rules
**Directory Structure:**
[Exact structure with purpose of each folder]
**Naming Conventions:**
- Files: [pattern] -> e.g., `kebab-case.tsx`
- Components: [pattern] -> e.g., `PascalCase`
- Functions: [pattern] -> e.g., `camelCase`
- Types: [pattern] -> e.g., `PascalCase` with prefix/suffix
**Import Order:**
[Exact ordering from eslint/codebase analysis]
---
### Code Patterns
**CORRECT (Follow These):**
```[lang]
// [Pattern name]
[Actual code example from codebase]
WRONG (Never Do):
// [Anti-pattern name]
[What to avoid + why]
[Framework] v[X.X.X]:
[State Management]:
[Data Fetching/API]:
[Styling]:
Security:
Performance:
Accessibility:
Critical Files (Extra Caution):
[path/file] — [why critical]Never Break:
After Mutations:
[test folder pattern][*.test.ts / *.spec.ts]TL;DR Rules:
Common Mistakes to Avoid:
When Uncertain: -> Check docs for LOCAL version -> State uncertainty explicitly -> Match existing patterns exactly
---
### SELF-EXTRACTION SCRIPT (Run First If Needed)
```bash
#!/bin/bash
# Extract codebase info for guidelines generation
echo "=== STACK ==="
cat package.json | head -50
echo "\n=== LOCKFILE VERSIONS ==="
cat package-lock.json | grep -A1 '"node_modules' | head -100 2>/dev/null || \
cat yarn.lock | head -100 2>/dev/null || \
cat pnpm-lock.yaml | head -100 2>/dev/null
echo "\n=== STRUCTURE ==="
find . -type f -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" | \
grep -v node_modules | grep -v .next | head -50
echo "\n=== CONFIGS ==="
for f in tsconfig.json .eslintrc* .prettierrc* next.config.* vite.config.* tailwind.config.*; do
[ -f "$f" ] && echo "--- $f ---" && cat "$f"
done
echo "\n=== SAMPLE FILES ==="
find . -path ./node_modules -prune -o -name "*.tsx" -print | head -5 | xargs head -50
echo "\n=== ENV TEMPLATE ==="
cat .env.example 2>/dev/null || cat .env.local.example 2>/dev/null
Before output, verify:
Option A: Provide file contents directly Option B: Run self-extraction script, paste output Option C: Grant file system access for autonomous analysis
Minimum needed:
[PROJECT_NAME]-coding-agent-guidelines.md.-> Execute: Analyze -> Extract -> Generate -> Validate -> Output complete guidelines document