Architecture Patterns Reference
Overview
This skill provides proven architectural patterns, design templates, and best practices for the PACT Architect phase. Use these patterns when designing system architecture, defining component boundaries, and creating implementation-ready specifications.
Quick Reference: Common Patterns
1. Layered Architecture
When to use: Traditional applications with clear separation of concerns Structure: Presentation → Business Logic → Data Access → Database Benefits: Clear separation, testability, familiar pattern Trade-offs: Can become rigid, vertical slicing challenges
2. Microservices Architecture
When to use: Large-scale systems requiring independent deployment Structure: Independent services with well-defined APIs Benefits: Scalability, technology diversity, fault isolation Trade-offs: Operational complexity, distributed system challenges
3. Event-Driven Architecture
When to use: Systems requiring loose coupling and async processing Structure: Event producers → Message broker → Event consumers Benefits: Decoupling, scalability, flexibility Trade-offs: Eventual consistency, debugging complexity
4. Hexagonal Architecture (Ports & Adapters)
When to use: Applications requiring high testability and technology independence Structure: Core domain logic surrounded by adapters for external systems Benefits: Testability, technology agnostic, clear boundaries Trade-offs: More initial complexity, learning curve
5. CQRS (Command Query Responsibility Segregation)
When to use: Complex domains with different read/write patterns Structure: Separate models and paths for commands and queries Benefits: Performance optimization, scaling flexibility Trade-offs: Increased complexity, eventual consistency challenges
Architectural Decision Workflow
For complex pattern selection and system design, use sequential-thinking to reason through decisions systematically.
When to use sequential-thinking:
- •Choosing between multiple viable architectural patterns
- •Evaluating trade-offs for a specific context
- •Designing component boundaries for complex systems
- •Resolving conflicting requirements (e.g., performance vs. simplicity)
Workflow:
- •
Frame the Decision
- •What architectural question needs answering?
- •What are the constraints and requirements?
- •What patterns are candidates?
- •
Analyze Each Option (use sequential-thinking)
- •How does each pattern address the requirements?
- •What are the trade-offs in this specific context?
- •What risks does each option introduce?
- •
Evaluate Against Principles
- •Does it follow SOLID principles?
- •Does it avoid known anti-patterns?
- •Is it appropriate for the team's expertise?
- •
Document the Decision
- •Record the chosen pattern and rationale
- •Note rejected alternatives and why
- •Identify risks and mitigations
Example sequential-thinking prompt:
"I need to choose between microservices and modular monolith for a mid-size e-commerce platform with a team of 5 developers. Let me think through the trade-offs systematically..."
Decision Tree: Which Reference to Load?
Need diagram templates?
→ See references/c4-templates.md
- •Component diagrams
- •Container diagrams
- •Deployment diagrams
- •ASCII art examples
Designing APIs?
→ See references/api-contracts.md
- •REST API patterns
- •GraphQL patterns
- •API versioning strategies
- •Error handling standards
Avoiding common mistakes?
→ See references/anti-patterns.md
- •Big Ball of Mud
- •God Objects
- •Tight coupling issues
- •Over-engineering patterns
Core Design Principles
Apply these principles to all architectural decisions:
- •Single Responsibility: Each component has one clear purpose
- •Open/Closed: Design for extension without modification
- •Dependency Inversion: Depend on abstractions, not implementations
- •Interface Segregation: Many specific interfaces over one general
- •Separation of Concerns: Isolate different aspects of functionality
- •Loose Coupling: Minimize dependencies between components
- •High Cohesion: Related functionality grouped together
Component Design Workflow
- •Identify Responsibilities: What does this component do?
- •Define Boundaries: What's in scope vs. out of scope?
- •Design Interfaces: How do other components interact?
- •Map Data Flow: How does information move through the system?
- •Consider Non-Functionals: Security, performance, scalability needs
- •Document Decisions: Create clear specifications for implementers
Example: Simple REST API Architecture
┌─────────────────┐
│ API Gateway │ ← Entry point, routing, rate limiting
└────────┬────────┘
│
┌────┴────┐
▼ ▼
┌────────┐ ┌────────┐
│ User │ │Product │ ← Domain services
│Service │ │Service │
└───┬────┘ └───┬────┘
│ │
▼ ▼
┌──────────────────┐
│ Database │ ← Shared or separate DBs
└──────────────────┘
Components:
- •API Gateway: Request routing, authentication, rate limiting
- •User Service: User management, authentication, profiles
- •Product Service: Product catalog, inventory, search
- •Database: Data persistence (consider separate DBs per service)
For complete C4 diagram templates: See references/c4-templates.md
Technology Selection Framework
When choosing technologies, consider:
- •Team Expertise: Does the team know this technology?
- •Community Support: Active development, documentation, plugins?
- •Scalability: Does it meet performance and scale requirements?
- •Maintainability: Can we maintain and debug this long-term?
- •Cost: Licensing, infrastructure, operational costs?
- •Integration: Does it work with existing systems?
Common Architecture Patterns by Use Case
Web Applications:
- •Small-Medium: Layered architecture with MVC
- •Large: Microservices with API gateway
- •Real-time: Event-driven with WebSockets
Data Processing:
- •Batch: Pipeline architecture
- •Stream: Event-driven with message queues
- •Analytics: Lambda architecture (batch + stream)
Mobile Backends:
- •BFF (Backend for Frontend) pattern
- •GraphQL for flexible queries
- •CDN for static content
Enterprise Systems:
- •Service-oriented architecture (SOA)
- •Enterprise service bus (ESB)
- •Monorepo with shared libraries
Interface Design Best Practices
- •Explicit Contracts: Document all inputs, outputs, and side effects
- •Version Management: Plan for API evolution from day one
- •Error Handling: Define standard error formats and codes
- •Idempotency: Design operations to be safely retryable
- •Rate Limiting: Protect services from overload
- •Authentication: Secure all interfaces appropriately
Deployment Patterns
Single Deployment: Simple applications, all components together Blue-Green: Zero-downtime deployments with instant rollback Canary: Gradual rollout to subset of users Rolling: Sequential updates across instances Feature Flags: Deploy code, enable features independently
Scalability Strategies
Vertical Scaling: Increase resources on single machine Horizontal Scaling: Add more machines (requires stateless design) Caching: Redis, CDN, application-level caching Load Balancing: Distribute traffic across instances Database Sharding: Split data across multiple databases Read Replicas: Separate read and write database instances
Security Architecture Basics
- •Defense in Depth: Multiple layers of security
- •Principle of Least Privilege: Minimal permissions required
- •Secure by Default: Security enabled out of the box
- •Input Validation: Validate and sanitize all inputs
- •Authentication & Authorization: Who are you? What can you do?
- •Encryption: In transit (TLS) and at rest
- •Audit Logging: Track security-relevant events
Documentation Standards
Your architecture documentation should include:
- •Context Diagram: System boundaries and external dependencies
- •Container Diagram: High-level technology choices
- •Component Diagram: Internal structure of containers
- •Deployment Diagram: Infrastructure and runtime environment
- •API Specifications: Complete interface definitions
- •Data Model: Entities, relationships, and constraints
- •Decision Log: Why key architectural choices were made
Additional Resources
- •Comprehensive diagram templates:
references/c4-templates.md - •API contract examples:
references/api-contracts.md - •Common pitfalls to avoid:
references/anti-patterns.md
Integration with PACT Workflow
Input from Prepare Phase:
- •Requirements documentation
- •Technology research
- •Constraints and assumptions
- •Stakeholder needs
Output for Code Phase:
- •Component specifications
- •Interface definitions
- •Implementation guidelines
- •Architecture diagrams
- •Technology stack decisions
Quality Gates:
- •All requirements addressed
- •Components have clear responsibilities
- •Interfaces are well-defined
- •Non-functional requirements considered
- •Security built into design
- •Deployment strategy defined
- •Testing approach documented