# Step 2: Context Analysis

<step-meta>
number: 2
name: context-analysis
gate: true
</step-meta>

## Mandatory Execution Rules

- READ the complete step file before taking any action
- ANALYZE loaded documents, don't assume or generate requirements
- ALWAYS treat this as collaborative discovery between architectural peers
- FOCUS on understanding project scope and requirements for architecture

## Execution Protocols

- Show your analysis before taking any action
- Present A/P/C menu after generating context analysis
- ONLY save when user chooses [C] Continue
- Update frontmatter `stepsCompleted: [1, 2]` before loading next step
- FORBIDDEN to load next step until [C] is selected

## Purpose

Analyze the project context and identify architectural concerns that will shape the decision.

## Instructions

1. **Extract Technical Constraints** from the PRD:
   - Performance requirements (latency, throughput, scale)
   - Security and compliance requirements
   - Integration requirements with existing systems
   - Technology mandates or restrictions

2. **Map the Current Landscape**:
   - What systems already exist?
   - What are the integration points?
   - What patterns are already in use?

3. **Identify Key Concerns**:
   - Scalability needs
   - Reliability requirements
   - Maintainability considerations
   - Cost constraints

## Actions

- Read: `{planning_artifacts}/*prd*.md`
- Read: `**/project-context.md` (if exists)
- Grep: Search codebase for existing patterns

## Output

Add to session file:

```markdown
## Architecture Context

### Technical Constraints
- Performance: [requirements from PRD]
- Security: [requirements]
- Integration: [required touchpoints]

### Current Landscape
- Existing systems: [list]
- Patterns in use: [list]
- Tech stack: [languages, frameworks]

### Key Concerns
1. [Concern]: [Why it matters]
2. [Concern]: [Why it matters]
```

<!-- GATE -->

## Collaboration Menu (A/P/C)

After generating context analysis, present choices:

- **[A] Advanced Elicitation** - Use discovery protocols to develop deeper insights about project context and architectural implications
- **[P] Party Mode** - Bring multiple perspectives to analyze project requirements from different architectural angles
- **[C] Continue** - Save the content to the document and proceed to pattern selection
- **[R] Revise** - Need to gather more information or clarify constraints

## Advanced Elicitation Mode

When user selects [A]:
1. Ask probing questions about non-obvious constraints
2. Explore edge cases and failure scenarios
3. Identify implicit assumptions in requirements
4. Dig deeper into integration complexity

## Party Mode

When user selects [P]:
1. Present analysis from multiple viewpoints:
   - **Security architect**: What could go wrong?
   - **Performance engineer**: Where are the bottlenecks?
   - **Operations**: How will this run in production?
   - **Developer experience**: How maintainable is this?
2. Synthesize perspectives into unified understanding

## Success Metrics

- Technical constraints extracted from PRD
- Current landscape mapped accurately
- Key concerns identified with rationale
- User confirmed context before proceeding

## Failure Modes

- Generating requirements not found in documents
- Proceeding without user confirmation
- Missing critical constraints from PRD
