architecture-selection
npx skills add https://github.com/rsmdt/the-startup --skill architecture-selection
Agent 安装分布
Skill 文档
Architecture Pattern Selection
Systematic guidance for selecting and implementing architecture patterns that match requirements, team capabilities, and scalability needs.
When to Activate
- Designing new system architectures
- Evaluating monolith vs microservices vs serverless
- Planning scalability strategies
- Selecting technology stacks
- Creating architecture documentation
- Reviewing architecture decisions
Architecture Patterns
Monolithic Architecture
A single deployable unit containing all functionality.
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Monolithic Application â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â âââââââââââââââ âââââââââââââââ âââââââââââââââ â
â â Web UI â â API Layer â â Admin UI â â
â ââââââââ¬âââââââ ââââââââ¬âââââââ ââââââââ¬âââââââ â
â â â â â
â ââââââââââââââââââ¼âââââââââââââââââ â
â â â
â âââââââââââââââââââââââââ´ââââââââââââââââââââââââââââ â
â â Business Logic Layer â â
â â ââââââââââââ ââââââââââââ ââââââââââââ â â
â â â Orders â â Users â â Products â â â
â â ââââââââââââ ââââââââââââ ââââââââââââ â â
â âââââââââââââââââââââââââ¬ââââââââââââââââââââââââââââ â
â â â
â âââââââââââââââââââââââââ´ââââââââââââââââââââââââââââ â
â â Data Access Layer â â
â âââââââââââââââââââââââââ¬ââââââââââââââââââââââââââââ â
â â â
ââââââââââââââââââââââââââââ¼âââââââââââââââââââââââââââââââââââ
â
ââââââââ´âââââââ
â Database â
âââââââââââââââ
When to Use:
- Small team (< 10 developers)
- Simple domain
- Rapid iteration needed
- Limited infrastructure expertise
Trade-offs:
| Pros | Cons |
|---|---|
| Simple deployment | Limited scalability |
| Easy debugging | Large codebase to manage |
| Single codebase | Technology lock-in |
| Fast development initially | Team coupling |
| Transactional consistency | Full redeploy for changes |
Microservices Architecture
Independently deployable services organized around business capabilities.
ââââââââââ ââââââââââ ââââââââââ ââââââââââ
â Web UI â âMobile â â Admin â âExternalâ
âââââ¬âââââ âââââ¬âââââ âââââ¬âââââ âââââ¬âââââ
â â â â
ââââââââââââââ´âââââââââââââ´âââââââââââââ
â
ââââââââââ´âââââââââ
â API Gateway â
ââââââââââ¬âââââââââ
â
ââââââââââââââââââââ¼âââââââââââââââââââ
â â â
âââââ´ââââ ââââââ´ââââ âââââ´ââââ
â Order â â User â âProductâ
âServiceâ âService â âServiceâ
ââââââââ⤠âââââââââ⤠âââââââââ¤
â DB â â DB â â DB â
âââââââââ ââââââââââ âââââââââ
â â â
ââââââââââââââââââââ´âââââââââââââââââââ
â
ââââââââââ´âââââââââ
â Message Bus â
âââââââââââââââââââ
When to Use:
- Large team (> 20 developers)
- Complex, evolving domain
- Independent scaling needed
- Different tech stacks for different services
- High availability requirements
Trade-offs:
| Pros | Cons |
|---|---|
| Independent deployment | Operational complexity |
| Technology flexibility | Network latency |
| Team autonomy | Distributed debugging |
| Targeted scaling | Data consistency challenges |
| Fault isolation | More infrastructure |
Event-Driven Architecture
Services communicate through events rather than direct calls.
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Event Bus / Broker â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â â
â OrderPlaced UserCreated PaymentReceived â
â â
ââââââââ¬âââââââââââââââ¬âââââââââââââââ¬ââââââââââââââââââââââââ
â â â
â¼ â¼ â¼
âââââââââââââââ âââââââââââââââ âââââââââââââââ
â Order â â User â â Payment â
â Service â â Service â â Service â
â â â â â â
â Publishes: â â Publishes: â â Publishes: â
â OrderPlaced â â UserCreated â â PaymentRcvd â
â â â â â â
â Subscribes: â â Subscribes: â â Subscribes: â
â PaymentRcvd â â OrderPlaced â â OrderPlaced â
âââââââââââââââ âââââââââââââââ âââââââââââââââ
When to Use:
- Loose coupling required
- Asynchronous processing acceptable
- Complex workflows spanning multiple services
- Audit trail needed
- Event sourcing scenarios
Trade-offs:
| Pros | Cons |
|---|---|
| Temporal decoupling | Eventual consistency |
| Natural audit log | Complex debugging |
| Scalability | Message ordering challenges |
| Extensibility | Infrastructure requirements |
| Resilience | Learning curve |
Serverless Architecture
Functions executed on-demand without managing servers.
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Client â
ââââââââââââââââââââââââââââââ¬ââââââââââââââââââââââââââââââââ
â
ââââââââââââââââââââââââââââââ´ââââââââââââââââââââââââââââââââ
â API Gateway â
ââââââââââââââââââââââââââââââ¬ââââââââââââââââââââââââââââââââ
â
ââââââââââââââââââââââââââ¼âââââââââââââââââââââââââ
â â â
â¼ â¼ â¼
ââââââââââââ ââââââââââââ ââââââââââââ
â Function â â Function â â Function â
â GetUser â âCreateOrderâ â SendEmailâ
ââââââ¬ââââââ ââââââ¬ââââââ ââââââ¬ââââââ
â â â
â¼ â¼ â¼
ââââââââââââ ââââââââââââ ââââââââââââ
â Database â â Queue â â Email â
â â â â â Service â
ââââââââââââ ââââââââââââ ââââââââââââ
When to Use:
- Variable/unpredictable workloads
- Event-triggered processing
- Cost optimization for low traffic
- Rapid development needed
- Short-running operations
Trade-offs:
| Pros | Cons |
|---|---|
| No server management | Cold start latency |
| Pay-per-use | Execution time limits |
| Auto-scaling | Vendor lock-in |
| Rapid deployment | Complex local development |
| Reduced ops burden | Stateless constraints |
Pattern Selection Guide
| Factor | Monolith | Microservices | Event-Driven | Serverless |
|---|---|---|---|---|
| Team Size | Small (<10) | Large (>20) | Any | Any |
| Domain Complexity | Simple | Complex | Complex | Simple-Medium |
| Scaling Needs | Uniform | Varied | Async | Unpredictable |
| Time to Market | Fast initially | Slower start | Medium | Fast |
| Ops Maturity | Low | High | High | Medium |
C4 Model
Hierarchical way to document architecture at multiple levels of detail.
Level 1: System Context
Shows system in its environment with external actors and systems.
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â System Context Diagram â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â â
â ââââââââââââ ââââââââââââ â
â â Customer â â Admin â â
â â [User] â â [User] â â
â ââââââ¬ââââââ ââââââ¬ââââââ â
â â â â
â â Places orders â Manages â
â â â products â
â â¼ â¼ â
â ââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â E-Commerce System â â
â â [Software System] â â
â âââââââââââââ¬ââââââââââââââââââ¬âââââââââââââââââââ â
â â â â
â â â â
â â¼ â¼ â
â âââââââââââââââââ âââââââââââââââââ â
â â Payment â â Email â â
â â Gateway â â Provider â â
â â [External] â â [External] â â
â âââââââââââââââââ âââââââââââââââââ â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Level 2: Container
Shows the high-level technology choices and how containers communicate.
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Container Diagram â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â â
â ââââââââââââââââââââ ââââââââââââââââââââ â
â â Web App â â Mobile App â â
â â [React SPA] â â [React Native] â â
â ââââââââââ¬ââââââââââ ââââââââââ¬ââââââââââ â
â â â â
â â HTTPS â â
â âââââââââââââ¬ââââââââââââââââ â
â â¼ â
â âââââââââââââââââââââââââ â
â â API Gateway â â
â â [Kong] â â
â âââââââââââââ¬ââââââââââââ â
â â â
â ââââââââââââââââââ¼âââââââââââââââââ â
â â â â â
â â¼ â¼ â¼ â
â âââââââââââ âââââââââââ âââââââââââ â
â â Order â â User â â Product â â
â â Service â â Service â â Service â â
â â [Node] â â [Node] â â [Go] â â
â ââââââ¬âââââ ââââââ¬âââââ ââââââ¬âââââ â
â â â â â
â â¼ â¼ â¼ â
â âââââââââââ âââââââââââ âââââââââââ â
â â Orders â â Users â âProducts â â
â â DB â â DB â â DB â â
â â[Postgresâ â[Postgresâ â [Mongo] â â
â âââââââââââ âââââââââââ âââââââââââ â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Level 3: Component
Shows internal structure of a container.
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Component Diagram: Order Service â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â API Layer â â
â â âââââââââââââââ âââââââââââââââ âââââââââââââââ â â
â â â OrdersCtrl â â HealthCtrl â â MetricsCtrl â â â
â â ââââââââ¬âââââââ âââââââââââââââ âââââââââââââââ â â
â âââââââââââ¼ââââââââââââââââââââââââââââââââââââââââââââââ â
â â â
â âââââââââââ¼ââââââââââââââââââââââââââââââââââââââââââââââ â
â â â¼ Domain Layer â â
â â âââââââââââââââ âââââââââââââââ âââââââââââââââ â â
â â âOrderService â â OrderCalc â â Validators â â â
â â ââââââââ¬âââââââ âââââââââââââââ âââââââââââââââ â â
â âââââââââââ¼ââââââââââââââââââââââââââââââââââââââââââââââ â
â â â
â âââââââââââ¼ââââââââââââââââââââââââââââââââââââââââââââââ â
â â â¼ Infrastructure Layer â â
â â âââââââââââââââ âââââââââââââââ âââââââââââââââ â â
â â â OrderRepo â âPaymentClientâ â EventPub â â â
â â âââââââââââââââ âââââââââââââââ âââââââââââââââ â â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Level 4: Code
Shows implementation details (class diagrams, sequence diagrams).
Use standard UML when needed at this level.
Scalability Patterns
Horizontal Scaling
Add more instances of the same component.
Load Balancer
â
âââââââââââââââââ¼ââââââââââââââââ
â â â
â¼ â¼ â¼
âââââââââââ âââââââââââ âââââââââââ
âInstance â âInstance â âInstance â
â 1 â â 2 â â 3 â
âââââââââââ âââââââââââ âââââââââââ
Requirements:
- Stateless services
- Shared session storage
- Database can handle connections
Caching
Reduce load on slow resources.
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Caching Layers â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â â
â Browser Cache â CDN â App Cache â Database Cache â
â â
â Examples: â
â - Browser: Static assets, API responses â
â - CDN: Static content, cached API responses â
â - App: Redis/Memcached for sessions, computed dataâ
â - Database: Query cache, connection pooling â
â â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Cache Invalidation Strategies:
- TTL (Time to Live): Simplest, eventual consistency
- Write-through: Update cache on write
- Write-behind: Async update for performance
- Cache-aside: App manages cache explicitly
Database Scaling
| Strategy | Use Case | Trade-off |
|---|---|---|
| Read Replicas | Read-heavy workloads | Replication lag |
| Sharding | Large datasets | Query complexity |
| Partitioning | Time-series data | Partition management |
| CQRS | Different read/write patterns | System complexity |
Reliability Patterns
| Pattern | Purpose | Implementation |
|---|---|---|
| Circuit Breaker | Prevent cascade failures | Fail fast after threshold |
| Bulkhead | Isolate failures | Separate thread pools |
| Retry | Handle transient failures | Exponential backoff |
| Timeout | Bound wait times | Don’t wait forever |
| Rate Limiting | Prevent overload | Throttle requests |
Circuit Breaker States:
ââââââââââ
â CLOSED â ââââ Failure Threshold ââ⺠ââââââââââ
â(normal)â â OPEN â
ââââââââââ â(failingâ
â² ââââââ¬ââââ
â â
Success Timeout
Threshold â
â â¼
ââââââ´âââââ âââââââââââ
âHALF-OPENâ ââââ Test Request ââââââ â â
âââââââââââ âââââââââââ
Technology Selection
Selection Criteria
| Criterion | Questions |
|---|---|
| Fit | Does it solve the actual problem? |
| Maturity | Production-proven? Community size? |
| Team Skills | Can the team use it effectively? |
| Performance | Meets requirements? Benchmarks? |
| Operations | How hard to deploy, monitor, debug? |
| Cost | License, infrastructure, learning curve? |
| Lock-in | Exit strategy? Standards compliance? |
| Security | Track record? Compliance certifications? |
Evaluation Matrix
| Technology | Fit | Maturity | Skills | Perf | Ops | Cost | Score |
|------------|-----|----------|--------|------|-----|------|-------|
| Option A | 4 | 5 | 3 | 4 | 4 | 3 | 3.8 |
| Option B | 5 | 3 | 4 | 5 | 2 | 4 | 3.8 |
| Option C | 3 | 4 | 5 | 3 | 5 | 5 | 4.2 |
Weights: Fit(25%), Maturity(15%), Skills(20%), Perf(15%), Ops(15%), Cost(10%)
Architecture Decision Records (ADRs)
ADR Template
# ADR-[NUMBER]: [TITLE]
## Status
[Proposed | Accepted | Deprecated | Superseded by ADR-XXX]
## Context
[What is the issue we're facing? What decision needs to be made?]
## Decision
[What is the change we're proposing/making?]
## Consequences
### Positive
- [Benefit 1]
- [Benefit 2]
### Negative
- [Trade-off 1]
- [Trade-off 2]
### Neutral
- [Observation]
## Alternatives Considered
### Alternative 1: [Name]
- Pros: [...]
- Cons: [...]
- Why rejected: [...]
Anti-Patterns
| Anti-Pattern | Problem | Solution |
|---|---|---|
| Big Ball of Mud | No clear architecture | Establish bounded contexts |
| Distributed Monolith | Microservices without independence | True service boundaries |
| Resume-Driven | Choosing tech for experience | Match tech to requirements |
| Premature Optimization | Scaling before needed | Start simple, measure, scale |
| Ivory Tower | Architecture divorced from reality | Evolutionary architecture |
| Golden Hammer | Same solution for every problem | Evaluate each case |
References
- Pattern Examples – Detailed implementations
- ADR Repository – Example decision records