arcanea-architecture-patterns
2
总安装量
2
周安装量
#67746
全站排名
安装命令
npx skills add https://github.com/frankxai/arcanea --skill arcanea-architecture-patterns
Agent 安装分布
codex
2
kilo
2
mcpjam
1
zencoder
1
crush
1
cline
1
Skill 文档
The Architecture Patterns Codex
“Architecture is the art of making the complex manageable. Choose patterns that reveal intent, not hide it.”
The Architecture Philosophy
Why Architecture Matters
CODE is what the system DOES.
ARCHITECTURE is what the system IS.
Bad architecture makes good code hard to write.
Good architecture makes bad code easy to fix.
Architecture decisions are expensive to change.
Choose wisely. Change reluctantly.
The Pattern Categories
Structural Patterns
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â STRUCTURAL PATTERNS â
â ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ£
â â
â LAYERED â Horizontal separation of concerns â
â HEXAGONAL â Ports and adapters, domain-centric â
â CLEAN â Dependencies point inward â
â VERTICAL SLICE â Feature-based organization â
â MODULAR MONOLITH â Bounded contexts in single deployment â
â â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Distributed Patterns
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â DISTRIBUTED PATTERNS â
â ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ£
â â
â MICROSERVICES â Independent deployable services â
â EVENT-DRIVEN â Async communication via events â
â CQRS â Separate read and write models â
â EVENT SOURCING â Store events, derive state â
â SAGA â Distributed transactions â
â â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Pattern Deep Dives
The Layered Architecture
âââââââââââââââââââââââââââââââââââââââ
â PRESENTATION LAYER â â UI, Controllers, Views
âââââââââââââââââââââââââââââââââââââââ¤
â APPLICATION LAYER â â Use Cases, Services
âââââââââââââââââââââââââââââââââââââââ¤
â DOMAIN LAYER â â Business Logic, Entities
âââââââââââââââââââââââââââââââââââââââ¤
â INFRASTRUCTURE LAYER â â Database, External APIs
âââââââââââââââââââââââââââââââââââââââ
RULES:
⢠Dependencies flow DOWN only
⢠Each layer knows only layer below
⢠Domain layer has ZERO dependencies
When to Use:
â Traditional business applications
â CRUD-heavy systems
â Teams familiar with MVC patterns
â Moderate complexity
â Highly dynamic requirements
â Event-heavy systems
â Complex business logic
The Hexagonal Architecture (Ports & Adapters)
âââââââââââââââââ
â PRIMARY â
â ADAPTERS â
â (Controllers) â
âââââââââ¬ââââââââ
â
âââââââââ¼ââââââââ
â â
ââââââââ⤠PORTS âââââââââ
â â (Interfaces) â â
â âââââââââ¬ââââââââ â
â â â
â âââââââââ¼ââââââââ â
â â â â
â â DOMAIN â â
â â (Core) â â
â â â â
â âââââââââ¬ââââââââ â
â â â
â âââââââââ¼ââââââââ â
â â â â
ââââââââ⤠PORTS âââââââââ
â (Interfaces) â
âââââââââ¬ââââââââ
â
âââââââââ¼ââââââââ
â SECONDARY â
â ADAPTERS â
â (Repositories)â
âââââââââââââââââ
CORE INSIGHT:
Domain knows nothing about the outside world.
Adapters translate between domain and infrastructure.
When to Use:
â Domain-driven design projects
â Systems needing high testability
â Multiple input/output channels
â Long-lived business applications
â Simple CRUD applications
â Rapid prototypes
â Small teams with tight deadlines
The Clean Architecture
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â FRAMEWORKS & DRIVERS â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â INTERFACE ADAPTERS â â
â â âââââââââââââââââââââââââââââââââââââââââââââââââââ â â
â â â APPLICATION LAYER â â â
â â â âââââââââââââââââââââââââââââââââââââââââââ â â â
â â â â DOMAIN LAYER â â â â
â â â â (Entities & Rules) â â â â
â â â âââââââââââââââââââââââââââââââââââââââââââ â â â
â â â (Use Cases) â â â
â â âââââââââââââââââââââââââââââââââââââââââââââââââââ â â
â â (Controllers, Gateways, Presenters) â â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
â (Web, UI, DB, External Interfaces) â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
THE DEPENDENCY RULE:
Dependencies point INWARD only.
Inner circles know nothing about outer circles.
Vertical Slice Architecture
Traditional (Layered): Vertical Slice:
ââââââââââââââââââââ âââââââ¬ââââââ¬ââââââ
â Controllers â â F â F â F â
âââââââââââââââââââ⤠â E â E â E â
â Services â â A â A â A â
âââââââââââââââââââ⤠â â T â T â T â
â Repositories â â U â U â U â
âââââââââââââââââââ⤠â R â R â R â
â Database â â E â E â E â
ââââââââââââââââââââ â 1 â 2 â 3 â
âââââââ´ââââââ´ââââââ
INSIGHT:
Group by FEATURE, not by layer.
Each slice is independent and complete.
When to Use:
â Feature teams
â Rapid iteration
â Varying complexity per feature
â CQRS systems
â Highly shared logic
â Small applications
â Strong layer conventions required
Distributed Architecture Patterns
Microservices
âââââââââââ âââââââââââ âââââââââââ
â Service â â Service â â Service â
â A ââââââ¶â B ââââââ¶â C â
âââââââââââ âââââââââââ âââââââââââ
â â â
â¼ â¼ â¼
âââââââââââ âââââââââââ âââââââââââ
â DB A â â DB B â â DB C â
âââââââââââ âââââââââââ âââââââââââ
PRINCIPLES:
1. Single responsibility per service
2. Own your data
3. Communicate via well-defined APIs
4. Deploy independently
5. Design for failure
The Microservices Decision:
CONSIDER MICROSERVICES WHEN:
⢠Multiple teams need autonomy
⢠Different scaling requirements per component
⢠Polyglot persistence needed
⢠Independent deployment critical
⢠Organization is distributed
AVOID MICROSERVICES WHEN:
⢠Small team (< 10 developers)
⢠Simple domain
⢠Tight deadlines
⢠Limited DevOps capability
⢠Unknown domain boundaries
Event-Driven Architecture
ââââââââââââ âââââââââââââââ ââââââââââââ
â Producer ââââââââââ¶â Event Bus ââââââââââ¶â Consumer â
ââââââââââââ â (Kafka/RMQ) â ââââââââââââ
âââââââââââââââ
â
âââââââ´ââââââ
â¼ â¼
ââââââââââââ ââââââââââââ
â Consumer â â Consumer â
ââââââââââââ ââââââââââââ
EVENT TYPES:
⢠Domain Events: Something happened (OrderPlaced)
⢠Integration Events: Cross-boundary communication
⢠Commands: Request to do something
⢠Queries: Request for information
CQRS (Command Query Responsibility Segregation)
âââââââââââââââââââââââââââââââââââââââââââââââ
â Client â
âââââââââââââââââââ¬ââââââââââââââââââââââââââââ
â
âââââââââââ´ââââââââââ
â¼ â¼
âââââââââââââââââ âââââââââââââââââ
â COMMANDS â â QUERIES â
â (Write) â â (Read) â
âââââââââ¬ââââââââ âââââââââ¬ââââââââ
â â
â¼ â¼
âââââââââââââââââ âââââââââââââââââ
â Write Model â â Read Model â
â (Normalized) ââââ¶â (Optimized) â
âââââââââââââââââ âââââââââââââââââ
INSIGHT:
Reads and writes have different needs.
Optimize each independently.
Architecture Decision Framework
The SOLID Principles in Architecture
S - Single Responsibility
Each component has one reason to change
O - Open/Closed
Open for extension, closed for modification
L - Liskov Substitution
Components should be replaceable
I - Interface Segregation
Clients shouldn't depend on unused interfaces
D - Dependency Inversion
Depend on abstractions, not concretions
Choosing Your Architecture
START HERE:
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â What is your team size? â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â < 5 developers â Consider Modular Monolith â
â 5-15 developers â Consider Vertical Slices â
â 15+ developers â Consider Microservices â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
THEN ASK:
â¡ How complex is the domain? (Simple â Layered)
â¡ How testable must it be? (High â Hexagonal/Clean)
â¡ How often does it change? (Often â Vertical Slices)
â¡ How independent are components? (Very â Microservices)
â¡ What are the scaling needs? (Variable â CQRS)
The Strangler Fig Pattern
For migrating from legacy:
PHASE 1: Create new system alongside old
ââââââââââââ ââââââââââââ
â Legacy â â New â
â System â â System â
ââââââââââââ ââââââââââââ
PHASE 2: Route new features to new system
ââââââââââââ ââââââââââââ
â Legacy ââââââ¶â New â
â (shrink) â â (grows) â
ââââââââââââ ââââââââââââ
PHASE 3: Migrate remaining features
ââââââââââââ
â New â
â System â
ââââââââââââ
PRINCIPLE: Never big-bang rewrite.
Gradually strangle the old with the new.
Common Anti-Patterns
The Big Ball of Mud
SYMPTOMS:
⢠No clear structure
⢠Everything depends on everything
⢠Changes have unpredictable effects
⢠Only original authors understand it
CAUSES:
⢠No upfront design
⢠Deadline pressure
⢠Lack of refactoring
⢠Knowledge silos
SOLUTION:
⢠Identify bounded contexts
⢠Extract modules gradually
⢠Establish clear interfaces
⢠Apply Strangler Fig
The Distributed Monolith
SYMPTOMS:
⢠Microservices that must deploy together
⢠Shared databases
⢠Synchronous call chains
⢠Coupled release cycles
CAUSES:
⢠Wrong service boundaries
⢠Shared data without events
⢠Missing async patterns
SOLUTION:
⢠Merge tightly coupled services
⢠Introduce event-driven communication
⢠Apply domain-driven design
Quick Reference
Architecture Checklist
â¡ Clear separation of concerns
â¡ Dependencies point in one direction
â¡ Domain logic isolated
â¡ External dependencies abstracted
â¡ Components independently testable
â¡ Scaling strategy defined
â¡ Failure modes understood
â¡ Monitoring and observability planned
Pattern Selection Matrix
| Need | Pattern |
|-------------------------|----------------------|
| Simple CRUD | Layered |
| Complex domain | Hexagonal/Clean |
| Feature teams | Vertical Slices |
| Team autonomy | Microservices |
| Read/write separation | CQRS |
| Audit trail | Event Sourcing |
| Distributed txns | Saga |
| Legacy migration | Strangler Fig |
“The best architecture is the one that makes the right thing easy and the wrong thing hard.”