Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lesson 2: Context-Driven AI Assistance

Why Context Matters

AI editors work best with relevant context. Without architecture context:

  • AI makes assumptions about your system
  • AI doesn't know your constraints
  • AI suggests generic patterns that may not fit

With architecture context:

  • AI understands your system's structure
  • AI knows which components are critical
  • AI provides relevant suggestions

Building Architecture Context

Basic Context

# Build context for current repo
sruja context -r .

# Output context as JSON
sruja context -r . --format json

Cross-Repo Context

# Build context across multiple repos
sruja context -r repoA -r repoB -r repoC

# Useful for monorepos or microservices

Focus Mode

For specific tasks, use focus mode to get a task-scoped briefing:

# Get context focused on a specific file/component
sruja focus --file src/api/main.rs

# Get context for a specific component
sruja focus --component PaymentService

Focus output includes:

  • Blast radius: What depends on this
  • Decisions: Why this was designed this way
  • Boundaries: What this component owns
  • AI instructions: How to work with this component

Context Score

Measure how "AI-ready" your architecture is:

# Get AI-readiness score (0-100)
sruja context-score -r .

The score evaluates 5 dimensions:

DimensionWhat It Measures
DocumentationAre components documented?
RelationshipsAre dependencies explicit?
ConstraintsAre policies defined?
CoverageHow much code is mapped?
FreshnessIs context up-to-date?

Optimizing Context for AI

1. Add Descriptions

container PaymentService {
  description "Handles payment processing and fraud detection"
  // AI now understands what this does
}
container PaymentService {
  requirement "Must comply with PCI-DSS"
  requirement "Must process 1000 TPS"
}

3. Add Intent

intent "Payment Goals" {
  outcome "All payments processed within 5 seconds"
}

4. Document Decisions

PaymentService = container "Payment Service" {
  description "Handles payments"

  adr "ADR-0012: Why we use Stripe instead of PayPal"
  adr "ADR-0015: Why payments are synchronous"
}

Daily Context Sync

For AI editors, run daily sync to keep context fresh:

# Quick sync
sruja sync -r .

# Full with drift check
sruja daily -r .

This updates:

  • .sruja/context.json
  • .cursorrules
  • .copilot-instructions.md
  • CLAUDE.md

Next Steps

Lesson 3 covers patterns for effective AI pair programming with architecture.