원클릭으로
code-archaeology
Systematic techniques for reading and understanding unfamiliar legacy code without documentation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Systematic techniques for reading and understanding unfamiliar legacy code without documentation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Transform markdown notes into engaging technical blog posts for both programmers and non-technical readers
Map dependencies and coupling in legacy codebase to understand what breaks when you change something and identify refactoring risks
Create detailed implementation plans with bite-sized tasks for engineers with zero codebase context
Creating documentation from legacy code when none exists, focusing on what future maintainers need to know
Maintain skills wiki health - check links, naming, cross-references, and coverage
TDD for process documentation - test with subagents before writing, iterate until bulletproof
| name | Code Archaeology |
| description | Systematic techniques for reading and understanding unfamiliar legacy code without documentation |
| when_to_use | when encountering unfamiliar legacy code and need to understand what it does, why it exists, and how it works |
| version | 1.0.0 |
| languages | all |
Legacy code is code without context. Code archaeology is the systematic process of excavating that context from the code itself, its history, and its runtime behavior.
Core principle: Read code like a detective, not a compiler. Look for clues about intent, not just mechanics.
Use code archaeology when:
Before diving into details, get the big picture:
Identify Entry Points
Map the Territory
Find the Documentation
Quick mapping command:
# Find all entry points
find . -name "main.*" -o -name "*Controller*" -o -name "*Handler*" -o -name "Program.cs" -o -name "Startup.cs"
# See directory structure
tree -L 3 -I 'node_modules|vendor|__pycache__|bin|obj'
# Find tests (they document behavior)
find . -name "*test*" -o -name "*spec*" -o -name "*.Tests" -o -name "*.Test"
Understanding flow is key to understanding purpose:
Pick a Concrete Example
Trace Forward (from input)
Input → Where does it enter?
→ How is it transformed?
→ Where does it go?
→ What's the output?
Trace Backward (from output)
Output → Where is it produced?
→ What data creates it?
→ Where does that data come from?
→ Keep going to the source
Example: Understanding authentication:
Forward: POST /login → router → authController.login() → UserService.authenticate() → Database
Backward: JWT token ← TokenService ← User object ← Database query ← Credentials validation
What are the domain concepts?
Look for Nouns
Look for Verbs
Find the Boundaries
Visualization helps:
Presentation Layer (HTTP, UI)
↓
Business Logic Layer (Services, Use Cases)
↓
Data Layer (Database, External APIs)
Code shows HOW. History shows WHY.
Git Archaeology
# When was this added?
git log --follow --diff-filter=A -- path/to/file.py
# Why was it changed?
git log -p -- path/to/file.py
# Who knows about it?
git blame path/to/file.py
# Find related changes
git log --all --grep="auth"
Look for Patterns
Run the Code
Start from entry points, drill down:
Good for:
Process:
Start from utilities, build up:
Good for:
Process:
Survey everything shallowly first:
Good for:
Process:
# Find all uses of a function
grep -r "authenticate" --include="*.py" --include="*.js" --include="*.cs"
# Find all classes/types
grep -r "^class " --include="*.py" --include="*.js" --include="*.ts"
grep -r "^\s*public class " --include="*.cs"
# Find configuration
find . -name "*.config" -o -name ".env*" -o -name "settings*" -o -name "appsettings*.json" -o -name "web.config"
# Count lines by directory (complexity proxy)
find . \( -name "*.py" -o -name "*.js" -o -name "*.cs" \) -exec wc -l {} + | sort -n
Run code with instrumentation:
# Python: Add logging to understand flow
import logging
logging.basicConfig(level=logging.DEBUG)
def mystery_function(data):
logging.debug(f"mystery_function called with: {data}")
result = complex_operation(data)
logging.debug(f"mystery_function returning: {result}")
return result
// C#: Add logging to understand flow
using Microsoft.Extensions.Logging;
public class MyService
{
private readonly ILogger<MyService> _logger;
public string MysteryFunction(string data)
{
_logger.LogDebug("MysteryFunction called with: {Data}", data);
var result = ComplexOperation(data);
_logger.LogDebug("MysteryFunction returning: {Result}", result);
return result;
}
}
Use debugger:
Common legacy patterns:
| Pattern | What it means |
|---|---|
| Singleton | Global state (often problematic) |
| Factory | Multiple implementations of same interface |
| Strategy | Pluggable behavior |
| Template Method | Framework with customization points |
| Null checks everywhere | Missing contracts, defensive programming |
| Try/catch around everything | Unstable dependencies or unknown errors |
| Mistake | Reality |
|---|---|
| "Reading code is slow, I'll just fix it" | Understanding saves hours of debugging. Read first. |
| "I understand what this function does" (after 30 seconds) | Functions exist in context. Understand their role in the system. |
| "This is bad code, I'll rewrite it" | It's solving a problem you don't understand yet. Archaeology first. |
| "I'll read it all linearly" | 100k LOC linearly = weeks. Use strategies. |
| "Comments and docs are outdated, I'll ignore them" | Even outdated docs have clues. They show original intent. |
Goal: Understand how login works
Archaeology process:
1. Entry point: POST /api/login endpoint
2. Trace: router.js → authController.login() → AuthService.authenticate()
3. Data flow: {email, password} → validate → query DB → generate JWT
4. Git history: Added in commit abc123 "Implement JWT authentication"
5. Why: Comments mention "replaced session-based auth for API scalability"
6. Pattern: Token-based stateless authentication
7. Tests: test/auth.test.js shows expected behavior
Mental model: Stateless auth using JWT, validates credentials, returns token for subsequent requests.
Goal: Understand how authentication middleware works
Archaeology process:
1. Entry point: Program.cs or Startup.cs → app.UseAuthentication()
2. Trace: Middleware pipeline → [Authorize] attribute → AuthenticationHandler
3. Data flow: HTTP request → Extract token → Validate → Create ClaimsPrincipal → Controller
4. Git history: Added in commit def456 "Switch to JWT bearer authentication"
5. Why: Comments mention "migrated from cookie auth to support mobile clients"
6. Pattern: ASP.NET Core authentication middleware with JWT bearer
7. Tests: AuthenticationTests.cs shows token validation scenarios
Mental model: Middleware-based authentication, token validation happens early in pipeline, user identity flows through HttpContext.User to controllers.
Code:
def calculate_price(item, user):
base = item.price
if user.is_premium:
base *= 0.9
if user.referral_count > 5:
base *= 0.95
if item.category == "seasonal":
base *= 1.2
return round(base, 2)
Archaeology:
Git log:
- Line 1-2: Original implementation
- Line 3-4: "Add premium discount per marketing request"
- Line 5-6: "Incentivize referrals" (commit by PM)
- Line 7-8: "Seasonal markup for inventory management"
Pattern: Accumulation of business rules over time
Why complex: Different stakeholders, different times
Mental model: Pricing is business-driven, not technical. Don't "simplify" without understanding business constraints.