Detect and document coding patterns, conventions, and styles used in the codebase.
Analyzes codebases to detect and document naming conventions, architecture patterns, and coding styles.
/plugin marketplace add adelabdelgawad/fullstack-agents/plugin install adelabdelgawad-fullstack-agents-plugins-fullstack-agents@adelabdelgawad/fullstack-agentsDetect and document coding patterns, conventions, and architectural styles in the codebase.
/analyze patternsFile naming:
# Python files
ls api/v1/*.py api/services/*.py api/repositories/*.py 2>/dev/null | head -10
# TypeScript files
ls app/**/*.tsx components/**/*.tsx 2>/dev/null | head -10
Class naming:
grep -rh "^class " --include="*.py" | head -20
Function naming:
grep -rh "^def \|^async def " --include="*.py" | head -20
Repository pattern:
grep -rl "class.*Repository" --include="*.py" | head -5
grep -rh "self.repository\." --include="*.py" | head -5
Service pattern:
grep -rl "class.*Service" --include="*.py" | head -5
Session management:
grep -rh "session: AsyncSession" --include="*.py" | head -5
grep -rh "Depends(get_session)" --include="*.py" | head -5
Component patterns:
# Server vs Client components
grep -rl '"use client"' --include="*.tsx" | wc -l
grep -rL '"use client"' app/\(pages\)/**/page.tsx 2>/dev/null | wc -l
# Context usage
grep -rl "createContext\|useContext" --include="*.tsx" | head -5
# SWR usage
grep -rl "useSWR" --include="*.tsx" | head -5
Import style:
# Absolute vs relative imports
grep -rh "^from \.\|^import \." --include="*.py" | head -5
grep -rh "^from [a-z]" --include="*.py" | head -5
String formatting:
grep -rh 'f".*{.*}"' --include="*.py" | head -5 # f-strings
grep -rh '\.format(' --include="*.py" | head -5 # .format()
grep -rh '% ' --include="*.py" | head -5 # % formatting
## Pattern Analysis Report
**Generated:** {timestamp}
### Naming Conventions
| Type | Pattern | Examples |
|------|---------|----------|
| Python files | snake_case | `user_service.py`, `order_repository.py` |
| TypeScript files | kebab-case | `products-table.tsx`, `add-product-sheet.tsx` |
| Python classes | PascalCase | `UserService`, `ProductRepository` |
| Python functions | snake_case | `get_user_by_id`, `create_order` |
| TypeScript functions | camelCase | `fetchProducts`, `handleSubmit` |
| Constants | UPPER_SNAKE | `MAX_RETRIES`, `DEFAULT_PAGE_SIZE` |
| Database tables | snake_case (singular) | `user`, `product`, `order_item` |
### Architecture Patterns
#### Backend (FastAPI)
| Pattern | Detected | Implementation |
|---------|----------|----------------|
| **Repository Pattern** | Yes | `api/repositories/*.py` |
| **Service Layer** | Yes | `api/services/*.py` |
| **Single Session Per Request** | Yes | Session via Depends() |
| **Domain Exceptions** | Yes | `api/exceptions.py` |
| **DTO Pattern (Schemas)** | Yes | `api/schemas/*.py` |
| **CamelModel** | Yes | All response schemas |
**Session Flow:**
```python
# Detected pattern
Router (Depends(get_session))
→ Service.method(session)
→ Repository.method(session)
→ session.execute(query)
| Pattern | Detected | Implementation |
|---|---|---|
| SSR + SWR Hybrid | Yes | Pages fetch, SWR for updates |
| Server Components | Yes | Pages are server components |
| Context for State | Yes | Entity-specific contexts |
| Server Actions | Partial | Some use API routes |
| URL State (nuqs) | Yes | Filters, pagination in URL |
Data Flow:
// Detected pattern
Page (Server) → fetch initial data
→ Client Component (useSWR with fallbackData)
→ Context (CRUD mutations)
→ API Routes → Backend
| Aspect | Pattern | Consistency |
|---|---|---|
| Imports | Absolute | 100% |
| String formatting | f-strings | 95% |
| Type hints | Present | 90% |
| Docstrings | Google style | 60% |
| Line length | 88 (Black) | 100% |
| Aspect | Pattern | Consistency |
|---|---|---|
| Imports | Absolute (@/) | 100% |
| Quotes | Double | 100% |
| Semicolons | Yes | 100% |
| Component style | Function | 100% |
| Exports | Named | 95% |
Model Pattern:
class Entity(Base):
__tablename__ = "entity"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
name_en: Mapped[str] = mapped_column(String(64), nullable=False)
name_ar: Mapped[str] = mapped_column(String(64), nullable=False)
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime, onupdate=func.now())
Detected entity features:
Endpoint Structure:
/api/v1/{entities} GET (list), POST (create)
/api/v1/{entities}/{id} GET (single), PUT (update), DELETE (soft delete)
Response Pattern:
# List response
{
"items": [...],
"total": 100,
"page": 1,
"limit": 10,
"pages": 10
}
# Single response
{
"id": 1,
"nameEn": "...", # camelCase
"nameAr": "...",
"isActive": true,
"createdAt": "2024-01-01T00:00:00Z"
}
Based on analysis, here's a pattern guide for new code:
Model in db/models.py:
is_active for soft deletecreated_at, updated_atSchemas in api/schemas/{entity}_schemas.py:
{Entity}Create for creation{Entity}Update for updates{Entity}Response(CamelModel) for responsesRepository in api/repositories/{entity}_repository.py:
Service in api/services/{entity}_service.py:
Router in api/v1/{entities}.py:
Page in app/(pages)/setting/{entity}/page.tsx:
Table in _components/table/{entity}-table.tsx:
Context in context/{entity}-context.tsx:
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences