skills/architectural-analysis/SKILL.md
Deep architectural audit focused on finding dead code, duplicated functionality, architectural anti-patterns, type confusion, and code smells. Use when user asks for architectural analysis, find dead code, identify duplication, or assess codebase health.
npx skillsauth add pedronauck/skills architectural-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Perform comprehensive architectural audit focused on structural issues, dead code, duplication, and systemic problems.
# Get directory structure
find . -type d -not -path "*/node_modules/*" -not -path "*/.git/*"
# Count files by type
find . -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" | wc -l
index.ts, main.ts, app.ts)index.ts files)Use Glob to find all source files. Create todo list with one item per file to analyze.
For EACH file in the todo list:
For each export, search if it's imported/used anywhere:
# Search for imports of this export
grep -r "import.*ExportName" . --include="*.ts" --include="*.tsx"
grep -r "from.*filename" . --include="*.ts" --include="*.tsx"
# Search for direct usage
grep -r "ExportName" . --include="*.ts" --include="*.tsx"
Dead Code (mark for removal):
Possibly Dead (needs verification):
Internal Dead Code:
Not dead if:
window or global scopeFile: path/to/file.ts
Status: [DEAD|POSSIBLY_DEAD|USED]
Exports: [list]
Dead Exports:
- ExportName - No imports found
- AnotherExport - Only used in test for deprecated feature
Confidence: [HIGH|MEDIUM|LOW]
Update todo list.
Search for common patterns that suggest duplication:
Manual Pattern Recognition:
Grep-Based Detection:
# Find similar function signatures
grep -r "function validateEmail" . --include="*.ts"
grep -r "async.*fetch.*api" . --include="*.ts"
grep -r "export.*UserForm" . --include="*.tsx"
For each potential duplication:
Exact Duplication (CRITICAL):
Similar Logic (HIGH):
Conceptual Duplication (MEDIUM):
Type Duplication (HIGH):
Duplication Group: Email Validation
Type: Exact Duplication
Instances:
- src/utils/validators.ts:42 - validateEmail()
- src/lib/email.ts:15 - isValidEmail()
- src/components/forms/validation.ts:67 - checkEmailFormat()
Analysis: All three implement same regex check
Recommendation: Keep utils/validators.ts version, remove others
Impact: 3 places to update when logic changes
Search for files that do too much:
# Find large files
find . -name "*.ts" -exec wc -l {} + | sort -rn | head -20
Analyze large files:
Look for:
Use grep to trace import chains:
# Check what file imports
grep "^import.*from" src/services/auth.ts
# Check what imports this file
grep -r "from.*auth" src/ --include="*.ts"
Identify:
Check architecture layers:
Singleton Abuse:
Anemic Domain Models:
Shotgun Surgery:
Feature Envy:
Search for problematic type usage:
# Find 'any' usage
grep -r ": any" . --include="*.ts" --include="*.tsx" -n
# Find 'unknown' usage
grep -r ": unknown" . --include="*.ts" -n
# Find type assertions
grep -r "as any" . --include="*.ts" -n
grep -r "as unknown" . --include="*.ts" -n
# Find @ts-ignore
grep -r "@ts-ignore" . --include="*.ts" -n
grep -r "@ts-expect-error" . --include="*.ts" -n
For each file with type issues:
any used?Look for:
Check for:
any from missing type annotations# Find functions with many lines
# (manual inspection of large files)
Flag functions over 50 lines - likely doing too much.
Search for functions with 4+ parameters:
Look for:
Search for:
Should be named constants.
# Find commented code blocks
grep -r "^[[:space:]]*//.*function\|class\|const" . --include="*.ts"
Commented code should be deleted (use git history).
Look for:
usr, msg, tmp)Create report at .audits/architectural-analysis-[timestamp].md:
# Architectural Analysis Report
**Date**: [timestamp]
**Files Analyzed**: X
**Dead Code Files**: Y
**Duplication Groups**: Z
---
## Executive Summary
- **Dead Code**: X files, Y exports completely unused
- **Duplicated Functionality**: Z duplication groups
- **Architectural Anti-Patterns**: W issues
- **Type Issues**: V problematic usages
- **Code Smells**: U instances
**Estimated Cleanup**: Remove ~X lines of dead code, consolidate Y duplications
---
## Dead Code
### Completely Dead Files (DELETE)
| File | Reason | Confidence |
|------|--------|------------|
| `src/old/legacy-processor.ts` | No imports found | HIGH |
| `src/utils/unused-helper.ts` | Exported but never used | HIGH |
| `src/temp/temp-service.ts` | Temporary file left behind | HIGH |
**Total Lines**: X,XXX lines can be deleted
### Dead Exports (REMOVE)
| File | Export | Reason |
|------|--------|--------|
| `src/utils/format.ts` | `formatOldDate()` | Replaced by `formatDate()`, no usage |
| `src/services/auth.ts` | `oldLogin()` | Deprecated, no usage found |
### Possibly Dead (VERIFY)
| File | Export | Reason | Verification Needed |
|------|--------|--------|---------------------|
| `src/lib/api.ts` | `fetchOldApi()` | Only used in commented code | Check if truly deprecated |
### Internal Dead Code
- `src/services/user.ts:125` - Private method `_validateLegacy()` never called
- `src/components/form.tsx:89` - Variable `tempData` assigned but never read
---
## Duplicated Functionality
### CRITICAL: Exact Duplicates
#### Duplication Group 1: Email Validation
**Instances**: 3
**Files**:
- `src/utils/validators.ts:42` - `validateEmail(email: string)`
- `src/lib/email.ts:15` - `isValidEmail(email: string)`
- `src/components/forms/validation.ts:67` - `checkEmailFormat(email: string)`
**Analysis**: All three use identical regex pattern `/^[^\s@]+@[^\s@]+\.[^\s@]+$/`
**Lines Duplicated**: ~15 lines × 3 = 45 lines
**Recommendation**:
- Keep: `src/utils/validators.ts:validateEmail()`
- Remove: Other two implementations
- Update: All imports to use validators version
#### Duplication Group 2: API Error Handling
**Instances**: 4
**Files**: [list]
**Analysis**: [similar]
### HIGH: Similar Logic
#### Duplication Group: Date Formatting
**Instances**: 2
**Files**:
- `src/utils/date.ts:30` - `formatDate()` - Uses date-fns
- `src/lib/format.ts:45` - `formatDateTime()` - Uses native Date
**Analysis**: Both format dates but use different libraries
**Recommendation**: Standardize on date-fns, remove native version
### Type Duplication
#### Type Group: User Interface
**Instances**: 3
**Files**:
- `src/types/user.ts` - `User` interface
- `src/models/user.ts` - `UserModel` interface (identical fields)
- `src/api/types.ts` - `UserData` interface (identical fields)
**Recommendation**: Use single `User` type from `src/types/user.ts`
---
## Architectural Anti-Patterns
### God Objects
#### `src/services/application-manager.ts` (850 lines)
**Responsibilities**: Database, auth, config, logging, caching, validation
**Issue**: Violates SRP, does everything
**Recommendation**: Split into:
- `database.service.ts`
- `auth.service.ts`
- `config.service.ts`
- `logging.service.ts`
### Circular Dependencies
#### Cycle 1: `auth.ts` ↔ `user.ts`
- `auth.ts` imports `getUserById` from `user.ts`
- `user.ts` imports `validateToken` from `auth.ts`
**Issue**: Creates tight coupling, makes testing hard
**Recommendation**: Extract shared types to separate file
### Tight Coupling
#### `components/UserForm.tsx` → `services/database.ts`
**Issue**: UI component directly importing database layer
**Recommendation**: Use service layer abstraction
### Layer Violations
#### `models/User.ts` imports from `components/`
**Issue**: Model layer should not know about view layer
**Recommendation**: Remove dependency, pass data via props
---
## Type Issues
### `any` Usage (X instances)
| File | Line | Context | Severity |
|------|------|---------|----------|
| `src/api/client.ts` | 45 | `response: any` | HIGH |
| `src/utils/parse.ts` | 23 | `data: any` | HIGH |
**Total `any` usages**: X
**Recommendation**: Define proper types for all cases
### Type Assertions (Y instances)
| File | Line | Assertion | Issue |
|------|------|-----------|-------|
| `src/lib/api.ts` | 67 | `as User` | Unsafe cast, no validation |
| `src/utils/parse.ts` | 89 | `as unknown as T` | Double cast to bypass types |
**Issue**: Type safety bypassed, runtime errors possible
### @ts-ignore Comments (Z instances)
| File | Line | Reason | Should Fix |
|------|------|--------|------------|
| `src/legacy/old.ts` | 34 | "Type error in legacy code" | Refactor or remove file |
---
## Code Smells
### Long Functions (>50 lines)
| File | Function | Lines | Issue |
|------|----------|-------|-------|
| `src/services/processor.ts` | `processData()` | 127 | Does too much, hard to test |
**Recommendation**: Extract smaller functions
### Complex Conditionals
| File | Line | Issue |
|------|------|-------|
| `src/utils/validator.ts` | 45 | Nested 4 levels deep |
| `src/lib/parser.ts` | 89 | Boolean expression spans 3 lines |
### Magic Numbers
| File | Line | Magic Value | Should Be |
|------|------|-------------|-----------|
| `src/config/limits.ts` | 12 | `86400` | `SECONDS_PER_DAY` |
| `src/utils/format.ts` | 34 | `1000` | `MS_PER_SECOND` |
### Commented-Out Code
**Files with commented code**: X
- `src/old/legacy.ts` - 45 lines of commented code
- `src/services/auth.ts` - Old implementation commented out
**Recommendation**: Delete all commented code (use git history)
---
## Statistics
**Dead Code**:
- Files: X
- Exports: Y
- Lines: Z (estimated)
**Duplication**:
- Groups: X
- Files affected: Y
- Duplicated lines: ~Z
**Architectural Issues**:
- God objects: X
- Circular dependencies: Y
- Layer violations: Z
**Type Issues**:
- `any` usage: X
- Type assertions: Y
- @ts-ignore: Z
**Code Smells**:
- Long functions: X
- Complex conditionals: Y
- Magic numbers: Z
---
## Impact Assessment
### Code Cleanup Potential
- **Dead code removal**: ~X,XXX lines
- **Duplication consolidation**: ~Y,YYY lines
- **Total reduction**: ~Z,ZZZ lines (AA% of codebase)
### Maintainability Improvement
- Fewer places to update when fixing bugs
- Clearer code responsibilities
- Better type safety
- Reduced cognitive load
### Risk Areas
- High coupling in `services/` directory
- Type safety compromised in `api/` layer
- Architectural violations in `components/`
Provide concise summary:
# Architectural Analysis Complete
## Dead Code Found
- **X completely dead files** - Can be deleted immediately
- **Y unused exports** - Can be removed
- **~Z,ZZZ lines** of dead code identified
## Top Dead Files
1. `src/old/legacy-processor.ts` - No imports
2. `src/temp/temp-service.ts` - Temporary file
3. `src/utils/unused-helper.ts` - Exported but never used
## Duplication Found
- **X duplication groups** identified
- **Most duplicated**: Email validation (3 copies)
- **~Y,YYY lines** of duplicated code
## Architectural Issues
- **Z god objects** doing too much
- **W circular dependencies** found
- **V layer violations** detected
## Type Issues
- **X `any` usages** - Should have proper types
- **Y type assertions** - Bypassing type safety
- **Z @ts-ignore comments** - Masking errors
## Code Smells
- **X long functions** (>50 lines)
- **Y complex conditionals** (3+ nesting)
- **Z magic numbers** - Should be constants
## Cleanup Potential
Removing dead code and consolidating duplication could eliminate **~X,XXX lines** (Y% of codebase)
**Full Report**: `.audits/architectural-analysis-[timestamp].md`
A complete architectural analysis includes:
development
Deep review of branch diffs, working trees, or GitHub PRs at any size. Use when the user asks for CodeRabbit-grade review, an incremental re-review after new pushes, publication of findings to a PR, a cross-LLM peer-review verdict round, or conformance review against spec artifacts. Don't use for applying fixes, reviewing specs or PRDs as documents, or quick single-file feedback.
tools
Orchestrate Claude and Codex worker TUIs from a controller agent through herdr panes and the herdr socket CLI. Use when delegating bounded tasks to herdr worker panes, running user-activated plan-first delegations (Claude Code plan mode, Codex Plan mode), waiting on native agent status (idle, working, blocked, done), or verifying worker reports. Workers launch as interactive TUIs via herdr agent start — never through headless runners (compozy exec, claude -p, codex exec). Not for cmux workspaces (see cmux-orchestration) and not for end-user herdr control.
tools
TanStack Query, Router, and Form patterns for React. Use when writing useQuery/queryOptions, mutations, caching, file-based routes, search params, loaders, or TanStack Form validation. Don't use for TanStack Start, TanStack DB/collections, Zustand client state, or non-TanStack routing.
development
Use when the user wants to design, redesign, shape, critique, audit, polish, clarify, distill, harden, optimize, adapt, animate, colorize, extract, or otherwise improve a frontend interface. Covers websites, landing pages, dashboards, product UI, app shells, components, forms, settings, onboarding, and empty states. Handles UX review, visual hierarchy, information architecture, cognitive load, accessibility, performance, responsive behavior, theming, anti-patterns, typography, fonts, spacing, layout, alignment, color, motion, micro-interactions, UX copy, error states, edge cases, i18n, and reusable design systems or tokens. Also use for bland designs that need to become bolder or more delightful, loud designs that should become quieter, live browser iteration on UI elements, or ambitious visual effects that should feel technically extraordinary. Not for backend-only or non-UI tasks.