This is a 5-year-old subscription management system that's changed hands between three teams. It has... "historical decisions."
There are two activities in this module:
- Activity 2A: Architecture Analysis - Understand the system
- Activity 2B: Refactoring Planning - Plan improvements (do this after 2A)
Your task: Understand the architecture well enough to explain it to others.
As a new engineer joining the team
I need to understand our subscription management system
So that I can contribute to features and fix bugs confidently
Background:
Our subscription service handles:
- User subscriptions and account management
- Payment processing (Stripe, PayPal, Apple IAP)
- Entitlements and feature flags
- Integration with multiple payment providers
- Webhook handling for payment events
- Scheduled jobs (renewals, expirations, reminders)
It's been around for 5 years. The original team is long gone.
Your mission: Figure out how this thing works.
-
Map the architecture
- Create a visual diagram of the system
- Identify key components and their relationships
- Document the request flow
-
Document your findings
- What are the major subsystems?
- How do they communicate?
- Where are the external dependencies?
- What assumptions did AI make (right or wrong)?
-
Capture questions
- What's unclear?
- What seems risky?
- What would you want to ask the original authors?
cd modules/02-codebase-understanding/legacy-code
npm install
npm run dev # Starts server at http://localhost:3001Frontend interfaces available:
- http://localhost:3001/ - User subscription page (basic jQuery interactions)
- http://localhost:3001/admin - Admin panel (300+ lines of jQuery - the main refactoring target!)
The system has jQuery-based UIs on the frontend and an Express API backend. Both are worth exploring!
AI will confidently make up functionality that doesn't exist.
This is the biggest pitfall in codebase exploration. AI tools are trained to be helpful and will:
- Infer features that "should" be there
- Describe standard patterns as if they're in this specific codebase
- Fill in gaps with reasonable assumptions
Your job: Verify every claim against the actual code.
-
Ask for file names and line numbers
- ❌ "The authentication uses JWT"
- ✅ "Can you show me where JWT is used? Which file and line?"
-
Check the code yourself
- When AI describes a feature, open the file
- Read the actual implementation
- Look for what's NOT there
-
Look for missing pieces
- AI might describe error handling that doesn't exist
- AI might explain retry logic that's not implemented
- AI might describe validation that's missing
-
Test your understanding
- If AI says "payment retries happen after 24 hours", find that 24
- If AI says "webhooks validate signatures", find that validation
- If actual code doesn't match, AI was wrong
AI is good at:
- Explaining general flow (request → service → response)
- Identifying patterns (this looks like MVC)
- Suggesting where to look next
- Generating initial architecture diagrams
You must verify:
- Whether specific features actually exist
- Exact implementation details
- What's missing or incomplete
- Edge cases and error handling
- Integration details
Remember: More context ≠ Better results
"Here's all 50 files. Explain the architecture."
[Dumps entire codebase]
This will give you generic, surface-level analysis.
Phase 1: Entry Point (5 min)
- Start with
server.js - Ask AI: "What does this entry point tell us about the system's structure?"
- Identify the main routes and middleware
Phase 2: Follow One Path (10 min)
- Pick one feature: "Create a subscription"
- Trace: Route → Controller → Service → Model
- Ask targeted questions about each layer
- Document the flow
Phase 3: Expand Deliberately (10 min)
- Explore related services
- Understand external integrations
- Check webhook handlers
- Map background jobs
Phase 4: Synthesize (5 min)
- Create the full architecture diagram
- Document assumptions and questions
- Note what AI got wrong
Phase 5: Systematic Verification (Critical!)
After getting AI's explanation, verify systematically:
-
For each feature AI described, find the code
- Open the file AI mentioned
- Read the actual implementation
- Check if it matches AI's description
-
Look for what's missing
- Does AI mention error handling? Is it really there?
- Does AI describe authentication? Check if it exists
- Does AI explain retry logic? Find the retry code
-
Test specific claims
- AI says "retries after 24 hours"? grep for "24" or check constants
- AI says "validates webhook signatures"? Find that validation
- AI says "uses Redis for caching"? Check if Redis exists
-
Document hallucinations
- What did AI claim that wasn't true?
- What features did AI assume existed?
- Where did AI fill gaps with "standard" patterns?
Try exploring the codebase yourself first! Use AI to help, but develop your own exploration strategy.
If you get stuck:
- Refer to the Writing Good Prompts Guide for help on how to structure prompts
- Check PROMPT_EXAMPLES.md to see example approaches for architecture analysis
After you finish: If you haven't already, review PROMPT_EXAMPLES.md to compare your approach and see effective exploration patterns.
Your architecture diagram should show:
- API routes and their purposes
- Service layer organization
- Data models and relationships
- External service integrations
- Request lifecycle (HTTP → response)
- Payment processing flow
- Webhook handling flow
- Background job triggers
- Payment providers (Stripe, PayPal, Apple)
- Database (what type?)
- Notification services
- Logging/monitoring
- Subscription creation process
- Payment retry logic
- Entitlement management
- Cancellation handling
- Identified all API endpoints
- Understood service layer responsibilities
- Mapped database models and relationships
- Documented payment provider integrations
- Understood webhook handling
- Identified background jobs
- Found the authentication/authorization flow
- Located error handling patterns
- Noted testing strategy (or lack thereof)
- Documented assumptions and questions
Create a document (Markdown or visual diagram) that includes:
-
System Architecture Diagram
- Visual representation of components
- Use tools like: Paper, whiteboard, Excalidraw, Mermaid, or just ASCII art
-
Component Descriptions
- What each major component does
- How it interacts with others
-
Request Flows
- Trace 2-3 key user journeys through the system
-
External Integrations
- What external services are used
- How failures are handled
-
Open Questions
- What's still unclear
- What seems risky
- What needs investigation
-
AI Accuracy Report
- What did AI explain correctly?
- What assumptions did AI make that were wrong?
- Where did AI's suggestions need verification?
┌─────────────┐
│ Client │
└──────┬──────┘
│ HTTP
┌──────▼───────────────────────────────┐
│ Express Server │
│ ┌────────────────────────────────┐ │
│ │ Routes Layer │ │
│ │ /subscriptions /webhooks │ │
│ └─────────┬──────────────────────┘ │
│ │ │
│ ┌─────────▼──────────────────────┐ │
│ │ Service Layer │ │
│ │ SubscriptionService │ │
│ │ PaymentService │ │
│ │ EntitlementService │ │
│ └─────────┬──────────────────────┘ │
│ │ │
│ ┌─────────▼──────────────────────┐ │
│ │ Data Layer │ │
│ │ Models: User, Subscription │ │
│ └─────────┬──────────────────────┘ │
└────────────┼──────────────────────────┘
│
┌────────┴────────┐
│ │
┌───▼─────┐ ┌─────▼──────┐
│Database │ │ External │
│ │ │ Services │
│(Postgres│ │ (Stripe, │
│ or Mongo│ │ PayPal) │
└─────────┘ └────────────┘
After 20 minutes of exploration:
- Post your diagram (whiteboard, paper, screen)
- Add comments to diagrams
- What surprised you about this codebase?
- Where did AI help your understanding?
- Where did AI confidently explain something that turned out to be wrong?
- Did you give AI too much context at any point? What happened?
- How would you explain this system to a new teammate?
- What would you want to refactor first (and why)?
- Compare your architecture diagrams. What did different groups choose to highlight or omit? What does this say about the nature of "understanding" a codebase?
- Does using an AI to explain a codebase prevent you from developing the critical skill of reading and interpreting code yourself?
- Inconsistent error handling
- Mixed promise/callback patterns
- Hard-coded configuration values
- Incomplete webhook handlers
- Database queries in route handlers
- No input validation in some places
- Copy-pasted code with slight variations
- Comments like "TODO: fix this properly"
These aren't bugs—they're archaeology! Every "weird" thing has a story.
After completing your architecture analysis, move on to:
Activity 2B: Refactoring Planning - Use your understanding to plan improvements
Remember: The goal isn't to judge the code. It's to understand it.