๐ Tutorial 2: Working with Existing Projects
Learning Goal: Master analyzing existing codebases, discovering implicit architectural decisions, and creating comprehensive documentation for established projects.
Prerequisites:
- Completed Tutorial 1: Your First MCP Analysis
- Understanding of basic MCP concepts
- Access to an existing codebase
Time Required: 45 minutes
๐ What You'll Learnโ
- Project Discovery - Systematically analyze existing codebases
- Implicit Decision Detection - Find undocumented architectural choices
- ADR Generation from Code - Create documentation for existing decisions
- Gap Analysis - Identify missing documentation and decisions
- Legacy Integration - Work with existing documentation and patterns
๐ก Resuming Previous Work? Use @.mcp-server-context.mdโ
Quick Context Recoveryโ
If you're returning to a project you've analyzed before, the .mcp-server-context.md file is your best friend. Instead of re-running analysis or trying to remember what you discovered, simply ask:
@.mcp-server-context.md What was I working on? Show me the active intents
and what analysis has been done on this project.
The AI will tell you:
- What ADRs were suggested or created
- Which tools you used last time
- Patterns that were discovered
- Your last architecture score
- Recommended next steps
Real Exampleโ
You (after a week away):
@.mcp-server-context.md I'm back to work on the microservices migration project.
What's the current status and what should I focus on?
AI Response:
Based on the context file, you were working on:
1. **Active Intent**: Microservices communication strategy (started 7 days ago)
- Status: 60% complete
- Last action: Analyzed API gateway options
2. **Discovered Patterns**:
- Monolithic architecture (95% confidence)
- REST API design (88% confidence)
3. **Current Score**: 72/100 (up 8 points from initial)
4. **Next Steps**:
- Complete ADR for service communication
- Define service boundaries
- Plan data consistency strategy
Why This Matters for Existing Projectsโ
Existing projects often involve:
- Long analysis sessions spread across days/weeks
- Multiple team members working on different aspects
- Complex decision trees that need to be remembered
- Historical context that's easy to lose
The context file solves all of these problems automatically!
๐ Step 1: Comprehensive Project Discoveryโ
Understanding What You're Working Withโ
When analyzing an existing project, you need to understand:
- Technology stack and dependencies
- Architectural patterns and design choices
- Existing documentation and standards
- Team conventions and practices
- Live infrastructure and deployment state (using research-driven analysis)
Research-Driven Discoveryโ
Before running deep analysis, use research-driven tools to query your live environment:
{
"tool": "perform_research",
"parameters": {
"question": "What is the complete technology stack, deployment infrastructure, and architectural patterns in this existing project?",
"projectPath": ".",
"adrDirectory": "./adrs"
}
}
What the Research-Orchestrator Does:
- Scans Project Files: Analyzes package.json, requirements.txt, go.mod, etc.
- Queries Knowledge Graph: Checks existing ADRs for documented decisions
- Probes Live Environment: Detects Docker, Podman, kubectl, oc (OpenShift), ansible
- Assigns Confidence Score: Tells you how reliable the findings are
- Falls Back to Web Search: If confidence < 60%, searches for best practices
Example Output:
## Research Results
**Confidence**: 92.0% โ (High confidence, no web search needed)
### Technology Stack
- **Backend**: Node.js 20.x with Express.js 4.18.x
- **Database**: PostgreSQL 15.x (found in docker-compose.yml)
- **Frontend**: React 18.x with TypeScript
- **Container Orchestration**: Docker Compose (local), Kubernetes (production)
### Infrastructure Capabilities Detected
โ docker - Container runtime available
โ docker-compose - Multi-container orchestration
โ kubectl - Kubernetes CLI configured
โ oc - OpenShift CLI detected (Red Hat ecosystem)
โ podman - Not installed
โ ansible - Configuration management available
### Architectural Insights
- Microservices architecture with 3 services
- Event-driven communication via message queue
- RESTful API design with versioning
- Documented in ADR-001, ADR-003, ADR-007
Run Deep Analysisโ
Start with a comprehensive ecosystem analysis:
{
"tool": "analyze_project_ecosystem",
"parameters": {
"projectPath": ".",
"enhancedMode": true,
"knowledgeEnhancement": true,
"learningEnabled": true,
"includeEnvironment": true,
"recursiveDepth": "comprehensive"
}
}
What to Look For:
- Detected Technologies - Languages, frameworks, databases
- Architecture Patterns - MVC, microservices, monolith, etc.
- Code Organization - Directory structure and module organization
- Dependencies - External libraries and their versions
- Configuration - Environment setup and deployment configs
Exercise: Project Inventoryโ
Take 10 minutes to review the analysis results and answer:
- What is the primary technology stack?
- What architectural pattern is being used?
- Are there any outdated dependencies or technologies?
- What's the overall complexity level?
- Are there any obvious architectural concerns?
๐ Step 2: Discover Existing ADRsโ
Check for Current Documentationโ
Many projects have some architectural documentation, even if not formal ADRs.
{
"tool": "discover_existing_adrs",
"parameters": {
"adrDirectory": "./adrs",
"projectPath": "."
}
}
Common ADR Locations to Check:
././adrs/./decisions/./architecture/architecture/decisions/- Root-level
ARCHITECTURE.mdorDECISIONS.md
If No ADRs Foundโ
Don't worry! This is common. The tool will help you discover implicit decisions that should be documented.
If ADRs Existโ
Great! You can enhance and expand the existing documentation. Note:
- Format consistency - Are they using a standard template?
- Completeness - Do they cover all major decisions?
- Currency - Are they up to date with current implementation?
๐ Step 3: Identify Implicit Architectural Decisionsโ
Discover Hidden Decisionsโ
Every codebase contains implicit architectural decisions that aren't documented. Let's find them:
{
"tool": "suggest_adrs",
"parameters": {
"projectPath": ".",
"analysisScope": "all",
"maxSuggestions": 10
}
}
Common Implicit Decisions Include:
- Database choice and schema design
- Authentication and authorization approach
- API design patterns (REST, GraphQL, etc.)
- Error handling strategies
- Logging and monitoring approaches
- Testing strategies and frameworks
- Deployment and infrastructure choices
Prioritize by Impactโ
The tool will suggest decisions, but you should prioritize based on:
- Business Impact - Decisions affecting user experience or business goals
- Technical Risk - Decisions with significant technical debt or complexity
- Team Confusion - Areas where team members frequently ask questions
- Change Frequency - Parts of the system that change often
Exercise: Decision Mappingโ
Create a simple priority matrix:
| Decision | Business Impact | Technical Risk | Priority |
|---|---|---|---|
| Database Architecture | High | Medium | 1 |
| API Authentication | High | High | 1 |
| Frontend State Management | Medium | Low | 3 |
๐ Step 4: Generate ADRs for Key Decisionsโ
Start with High-Priority Decisionsโ
Pick your top 3 decisions and create ADRs for them. Here's how to approach different types:
Example 1: Database Decisionโ
If your analysis revealed PostgreSQL usage, create an ADR:
{
"tool": "generate_adr_from_decision",
"parameters": {
"decisionData": {
"title": "Database Technology Selection - PostgreSQL",
"context": "The application requires persistent data storage with ACID compliance, complex queries, and JSON support for flexible schema evolution.",
"decision": "PostgreSQL as the primary database",
"rationale": "PostgreSQL provides ACID compliance, excellent JSON support, mature ecosystem, strong performance for complex queries, and good scaling options. The team has existing expertise.",
"consequences": [
"Excellent data integrity and consistency",
"Rich query capabilities with JSON support",
"Mature tooling and monitoring ecosystem",
"Requires PostgreSQL-specific knowledge for optimization",
"More complex setup than simple NoSQL options"
]
},
"adrDirectory": "./adrs",
"templateFormat": "standard"
}
}
Example 2: API Authenticationโ
{
"tool": "generate_adr_from_decision",
"parameters": {
"decisionData": {
"title": "API Authentication Strategy - JWT with Refresh Tokens",
"context": "The API needs secure authentication that works across web and mobile clients, supports stateless scaling, and provides good user experience.",
"decision": "JWT access tokens with refresh token rotation",
"rationale": "JWT tokens enable stateless authentication suitable for microservices, refresh tokens provide security through rotation, widely supported across platforms, and enables horizontal scaling.",
"consequences": [
"Stateless authentication enables horizontal scaling",
"Standardized approach works across all client types",
"Refresh token rotation improves security",
"Requires careful token expiration management",
"Need secure storage for refresh tokens on clients"
]
},
"adrDirectory": "./adrs"
}
}
Exercise: Create Your First ADRโ
Choose one decision from your priority list and create an ADR:
- Identify the decision from your analysis
- Research the context - Why was this choice needed?
- Document the rationale - What factors influenced the decision?
- List consequences - Both positive and negative outcomes
- Generate the ADR using the tool
๐ Step 5: Validate Against Current Implementationโ
Research-Driven ADR Validationโ
Use the new research-driven validation to check if documented decisions match actual infrastructure:
{
"tool": "validate_all_adrs",
"parameters": {
"projectPath": ".",
"adrDirectory": "./adrs",
"includeEnvironmentCheck": true,
"minConfidence": 0.6
}
}
Research-Driven Validation Process:
- Reads each ADR to extract the documented decision
- Researches live environment using research-orchestrator:
- Scans project files for actual implementation
- Queries knowledge graph for related decisions
- Checks live infrastructure (Docker, Kubernetes, OpenShift, etc.)
- Compares with confidence scoring
- Reports gaps, drift, or confirmation
Example Validation Report:
## ADR Validation Report - Research Confidence: 85.0% โ
### ADR-001: PostgreSQL Database Selection
**Status**: โ VALIDATED
- PostgreSQL 15.x running in Docker container
- Connection string found in .env.example
- Migration scripts present in db/migrations/
- Research Confidence: 95.0% โ
### ADR-003: Kubernetes Deployment
**Status**: โ ๏ธ DRIFT DETECTED
- ADR specifies Kubernetes, but OpenShift (oc) is primary tool
- Kubernetes manifests exist but unused
- OpenShift templates in openshift/ directory are actively used
- **Recommendation**: Update ADR or create ADR-008 for OpenShift migration
- Research Confidence: 88.0% โ
### ADR-007: Redis Caching
**Status**: โ NOT IMPLEMENTED
- No Redis container in docker-compose.yml
- No Redis client in package.json
- Caching code commented out in src/cache/
- Research Confidence: 92.0% โ
### Environment Infrastructure Detected
โ docker, kubectl, oc, ansible
Why This Matters:
- Prevents documentation rot - Keep ADRs aligned with reality
- Discovers undocumented changes - Find OpenShift adoption without ADR
- Identifies incomplete implementations - Redis decision never executed