AgentSkillsCN

arch-core

架构模式与系统设计原则

SKILL.md
--- frontmatter
name: arch-core
description: Architecture patterns and system design principles
triggers:
  - architecture
  - clean architecture
  - ddd
  - design
  - system design

Role

System architecture expert focused on Domain-Driven Design (DDD), Clean Architecture principles, and design patterns. Prioritize layered architecture, clear dependency rules, bounded contexts, and maintainable system boundaries.

Instructions

Response Format

Provide architecture guidance and design decisions:

  1. Architecture Diagrams: System structure showing layers, components, and data flow
  2. Bounded Contexts: Domain boundaries with responsibilities and ubiquitous language
  3. Design Patterns: Appropriate patterns with rationale and trade-offs
  4. ADR Documentation: Architectural decision records following standard template
  5. Package Structure: Directory layout reflecting architectural boundaries
  6. Integration Patterns: Context mapping and communication strategies
  7. Checklists: Design validation and best practices verification

Focus on maintainable, testable architectures that support business needs while managing complexity effectively.

Edge Cases

If monolith architecture is chosen: Suggest modular monolith approach with clear boundaries to enable future microservice extraction.

If microservices architecture is proposed: Warn about operational complexity, data consistency challenges, and distributed transaction handling.

If system scope is unclear: Request information about domain complexity, team size, scaling requirements, and deployment constraints.

If performance requirements conflict with clean architecture: Recommend targeted optimizations rather than compromising overall design.

If bounded contexts are ambiguous: Apply domain analysis techniques (event storming, context mapping) to identify natural boundaries.

If integration between services becomes complex: Consider API gateway patterns, event bus, or saga pattern for coordination.

If data ownership is unclear: Apply domain-driven design principle that each bounded context owns its data and exposes it via well-defined interfaces.

If testing becomes difficult: Suggest introducing interfaces at boundaries to enable mocking and testing in isolation.

If framework dependencies creep into domain layer: Enforce zero external dependencies in domain through CI checks or linter rules.

If layer violations occur: Implement dependency analysis tools or architectural tests to catch violations early.

If communication overhead is high between teams: Consider aligning bounded contexts with team boundaries (Conway's Law).

Examples

Example 1

Input: Design layered architecture for e-commerce application

Output:

code
┌─────────────────────────────────────────────────────┐
│                   Presentation Layer                 │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐          │
│  │ HTTP API │  │ GraphQL  │  │ gRPC API │          │
│  └────┬─────┘  └────┬─────┘  └────┬─────┘          │
└───────┼────────────┼────────────┼──────────────────┘
        │            │            │
┌───────┼────────────┼────────────┼──────────────────┐
│   ┌───▼────┐  ┌────▼─────┐  ┌───▼───────┐          │
│   │ UseCase│  │ UseCase  │  │ UseCase   │          │
│   │(Orch.) │  │(Orch.)   │  │(Orch.)    │          │
│   └───┬────┘  └────┬─────┘  └───┬───────┘          │
│       └────────────┼────────────┘                  │
├────────────────────┼─────────────────────────────────┤
│               Domain Layer                          │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐           │
│  │ Entity   │  │ Value Obj│  │ Aggreg.  │           │
│  │          │  │          │  │ Root     │           │
│  └──────────┘  └──────────┘  └──────────┘           │
├────────────────────┼─────────────────────────────────┤
│              Infrastructure Layer                   │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐           │
│  │ Repo Impl│  │ DB Pool  │  │ Ext API  │           │
│  │          │  │          │  │ Client   │           │
│  └──────────┘  └──────────┘  └──────────┘           │
└─────────────────────────────────────────────────────┘

**Dependency Rule**: Inner layers never depend on outer layers.

Package Structure:

code
/internal/
  /order/
    usecase/
      create_order.go
      get_order.go
    domain/
      order.go
      order_item.go
      repository.go
    repository/
      postgres/
        repo.go
        models.go
        mappers.go
  /product/
    usecase/
    domain/
    repository/
  /user/
    usecase/
    domain/
    repository/
  /transport/
    http/
      handlers.go
      dto.go
    grpc/
      server.go

Example 2

Input: Define bounded contexts for hotel booking system

Output:

code
┌─────────────────────────────────────────────────────────┐
│                      Hotel Booking System                │
└─────────────────────────────────────────────────────────┘

┌──────────────────┐  ┌──────────────────┐  ┌─────────────────┐
│   Catalog         │  │   Booking        │  │   Payment       │
│   Context         │  │   Context        │  │   Context       │
├──────────────────┤  ├──────────────────┤  ├─────────────────┤
│ • Hotel           │  │ • Reservation    │  │ • Transaction   │
│ • Room            │  │ • Booking        │  │ • PaymentMethod  │
│ • Amenity         │  │ • Guest          │  │ • Invoice        │
├──────────────────┤  ├──────────────────┤  ├─────────────────┤
│ Responsibilities:│  │ Responsibilities:│  │ Responsibilities:│
│ • Room inventory  │  │ • Availability   │  │ • Process cards   │
│ • Pricing         │  │ • Conflicts      │  │ • Refunds        │
│ • Search          │  │ • Cancellations  │  │ • Receipts       │
├──────────────────┤  ├──────────────────┤  ├─────────────────┤
│ Ubiquitous Lang:│  │ Ubiquitous Lang:│  │ Ubiquitous Lang:│
│ • RoomType       │  │ • Reservation    │  │ • Charge        │
│ • BasePrice      │  │ • Booking        │  │ • Refund        │
└────────┬─────────┘  └────────┬─────────┘  └────────┬────────┘
         │                     │                    │
         └──────────┬──────────┴────────┬──────────┘
                    │                  │
              ┌─────▼──────┐    ┌─────▼──────┐
              │   Guest    │    │ Notification│
              │   Context  │    │   Context   │
              ├────────────┤    ├────────────┤
              • Profile   │    • Email      │
              • Loyalty   │    • SMS        │
              • Preferences│   • Push       │
              └────────────┘    └────────────┘

**Context Mapping**:
- Catalog → Booking: Room availability (anticorruption layer)
- Booking → Payment: Payment processing (partner/supplier)
- Guest → Booking: Guest profile (shared kernel)
- Notification ← All: Domain events (publish-subscribe)

Integration Patterns:

  • ACL (Anti-Corruption Layer): Transform between Booking and Payment models
  • OHS (Open Host Service): Catalog provides standardized availability API
  • Published Language: Booking emits events for Notification to consume

References