AgentSkillsCN

Arch

通过多智能体辩论,从两种不同视角出发,共同探寻最优设计方案。 领域架构师与最佳实践顾问以轮次辩论的形式展开协作。 触发词:arch、architecture、blueprint、设计、架构

SKILL.md
--- frontmatter
id: arch
name: Arch
description: |
  Multi-agent debate to derive optimal design through two perspectives.
  Domain Architect + Best Practice Advisor collaborate in round-based debate.

  Triggers: arch, architecture, blueprint, 설계, 아키텍처
user-invocable: true
version: 2.0.0
triggers:
  - "arch"
  - "architecture"
  - "blueprint"
  - "feature design"
requires: ["spec"]
platform: all
recommended_model: opus
agents:
  debate: archflow:domain-architect, archflow:best-practice-advisor
allowed-tools:
  - Read
  - Write
  - Glob
  - Grep
  - LS
  - Task
  - AskQuestion

Language: This skill is written in English for universal compatibility. Always respond in the user's language unless explicitly requested otherwise. If uncertain about the user's language, ask for clarification.

Arch Workflow

Two perspective sub-agents collaborate to derive optimal design.

💡 Recommended Model

Opus Required - Design quality determines implementation quality

→ Even when cost savings are needed, maintain Opus for this phase

🔄 Tool Fallback

ToolAlternative when unavailable
Read/GrepRequest file path from user → ask for copy-paste
AskQuestion"Please select: 1) OptionA 2) OptionB 3) OptionC" format
TaskUse Self-debate Pattern instead of sub-agent calls

Sub-agent Alternative (when Task tool unavailable)

When the Task tool is unavailable for multi-agent collaboration, use the Self-Debate Pattern:

Phase 1: Initial Prompt Split

code
You will play two roles in sequence to design this feature:

**Role A: Domain Architect**
- Context: Full project structure, requirements document
- Goal: Design that fits this specific project
- Considerations: Existing patterns, technical constraints, team familiarity

**Role B: Best Practice Advisor**
- Context: Feature requirements only (no project context)
- Goal: Ideal design based on universal best practices
- Considerations: Industry standards, scalability, maintainability

Start with Role A. After your design, I will ask you to switch to Role B.

Phase 2: Cross-Review (Round 1)

code
Now switch to Role B (Best Practice Advisor).

Review the Role A design above and provide:
1. What you agree with
2. Concerns or risks
3. Alternative suggestions
4. Can we reach consensus? [Yes / Need discussion]

Phase 3: Counter-Review (Round 2)

code
Now return to Role A (Domain Architect).

Review Role B's feedback and provide:
1. Valid points you can accept
2. Points you must reject (with project-specific reasons)
3. Proposed compromises
4. Final stance: [Agreement / Need user decision]

Phase 4: Synthesis

code
Now synthesize both perspectives into a final design.
Document in "Risks & Tradeoffs" section:
- Chosen approach
- Rejected alternatives and why
- Assumptions made
- Points requiring user decision (if any)

When to use: Only when Task tool is unavailable and multi-perspective design is needed.

📁 Document Structure

code
projectRoot/
  └── docs/
        └── {serviceName}/
              ├── spec.md   # spec skill output
              ├── arch.md      # ← This skill's output
              └── trace.md      # debug skill output

serviceName inference: Automatically extracted from input file path docs/{serviceName}/spec.md

⚠️ Global Rule: Logical Inconsistency Handling

When user feedback conflicts with Phase 0 Goal or existing design decisions:

Step 1: Detect and Report

markdown
⚠️ **Logical Inconsistency Detected**

**Existing Design**: {previously confirmed design content}
**User Feedback**: {new conflicting input}
**Conflict Point**: {which principle/decision is conflicting}

Step 2: Present Decision Options

Use AskQuestion to request resolution:

json
{
  "title": "Resolve Design Inconsistency",
  "questions": [
    {
      "id": "resolution",
      "prompt": "Existing design conflicts with new feedback. How should we proceed?",
      "options": [
        {"id": "keep_original", "label": "Keep original - Ignore new feedback"},
        {"id": "accept_new", "label": "Accept new - Revise design"},
        {"id": "merge", "label": "Merge - Incorporate both (explain how)"},
        {"id": "re_debate", "label": "Re-debate - Restart discussion with new constraints"}
      ]
    }
  ]
}

Processing by choice:

  • keep_original → Log warning, maintain existing design
  • accept_new → Revise design, document reason in Risks & Tradeoffs
  • merge → Request user explanation of merge approach
  • re_debate → Return to Phase 3 and restart debate with new constraints

Role Definitions

AgentRoleContext
domain-architectProject context-based designRequirements MD + project structure
best-practice-advisorBest practice suggestionsFeature request only (no context)

Phase 0: Skill Entry

0-0. Model Guidance (Display at start)

⚠️ This skill strongly recommends using the Opus model. Design quality determines implementation quality, so maintain Opus for this phase even when cost savings are needed.

Input: docs/{serviceName}/spec.md Output: docs/{serviceName}/arch.md

0-1. Collect Input Information

When skill is invoked without input, use AskQuestion to guide information collection:

json
{
  "title": "Start Design Debate",
  "questions": [
    {
      "id": "has_requirements",
      "prompt": "Do you have a requirements document? (docs/{serviceName}/spec.md)",
      "options": [
        {"id": "yes", "label": "Yes - I will provide via @filepath"},
        {"id": "no", "label": "No - Need requirements refinement first"}
      ]
    }
  ]
}

Processing by response:

  • yes → Request file path → Proceed to Phase 1
  • no → Guide to spec skill

0-2. Infer serviceName

Extract serviceName from provided file path:

  • Input: docs/alert/spec.md
  • Extract: serviceName = "alert"
  • Output path: docs/alert/arch.md

Phase 1: Initial Input Collection

Confirm with user:

  • Requirements document path (e.g., @docs/alert/spec.md)
  • Feature description (if additional explanation needed)

If file is already provided → Proceed directly to Phase 2

Phase 2: Parallel Initial Design

2-A: Invoke Domain Architect

Use Task tool to call domain-architect sub-agent:

code
Task(
  subagent_type: "domain-architect",
  description: "Project context-based design",
  prompt: """
    Requirements: {requirements MD content}
    Feature description: {feature description}
    Project structure: {project exploration results}

    Based on the above information, provide a design proposal.
  """
)

Expected output:

  • Design proposal (implementation approach, file structure, dependencies)
  • Project constraint considerations
  • Concerns and tradeoffs

2-B: Invoke Best Practice Advisor

Use Task tool to call best-practice-advisor sub-agent:

code
Task(
  subagent_type: "best-practice-advisor",
  description: "Best practice-based design",
  prompt: """
    Feature description: {feature description only, no project context}

    Provide an ideal design proposal for implementing this feature.
  """
)

Expected output:

  • Ideal design proposal (based on best practices)
  • Recommended patterns and anti-patterns
  • General considerations

Phase 3: Round 1 Debate (Automated)

Forward the following prompt to both agents:

code
From now on, I will relay another LLM's response.
That LLM was also instructed on the same feature definition.

Other agent's design:
{other_agent_response}

Review from your perspective and provide:
1. Points you agree with
2. Concerns
3. Alternative suggestions (if any)
4. Can we reach consensus: [Agree / Need further discussion]

Round 1

  • Domain Architect's design → Forward to Best Practice Advisor
  • Best Practice Advisor returns review feedback

Round 2

  • Best Practice Advisor's review → Forward to Domain Architect
  • Domain Architect returns revision/rebuttal

Phase 4: User Checkpoint

After 2 rounds, must provide interim report to user.

Report Format

ItemDomain ArchitectBest Practice Advisor
Core argument(1-2 sentence summary)(1-2 sentence summary)
Agreed points(list)(list)
Disputed points(list)(list)

Present User Options

Use AskQuestion tool (content dynamically generated based on debate results):

FieldDescription
titleReflect debate topic (e.g., "Alert Scheduling Design Debate")
promptInclude above report format table summary
optionsProvide 4 basic options below, adjust based on situation

Basic options:

  • domain: Adopt Domain Architect's approach - Prioritize project reality
  • best: Adopt Best Practice approach - Prioritize ideal design
  • continue: Continue debate - Proceed with 2 more rounds
  • custom: Specify on disputed points - Directly combine

Option adjustment rules:

  • If both agents agree → Exclude continue
  • If one is clearly superior → Mark that option as default recommendation

Note: Run in Normal mode, not Plan mode. Can both intervene mid-process with AskQuestion + write final file.

Phase 5: Follow-up Processing

Options 1, 2, 4 → Proceed immediately to Phase 6

  • Organize final design reflecting user decision

Option 3 → Additional Debate

  • Proceed with Round 3-4
  • Auto-terminate after 4 rounds (prevent infinite loop)
  • If no consensus → Adopt Domain Architect approach + note Best Practice recommendations

Phase 5.5: Quality Gate Validation

Before writing design document, validate completeness of required fields:

Required Validation Items

ItemValidation CriteriaIf Incomplete
DB SchemaAll tables have full column definitionsEnter question loop
Code MappingAll features mapped to file/class/methodEnter question loop
API SpecAll endpoints have Request/Response definedEnter question loop
Error PolicyMain error scenarios and responses definedEnter question loop

Question Loop on Incomplete Items

json
{
  "title": "Design Information Supplement Required",
  "questions": [
    {
      "id": "missing_info",
      "prompt": "The following information is missing:\n- {list of missing items}\n\nHow would you like to proceed?",
      "options": [
        {"id": "provide", "label": "Provide - I will provide the information"},
        {"id": "infer", "label": "Allow inference - AI can estimate"},
        {"id": "skip", "label": "Skip - I will supplement later"}
      ]
    }
  ]
}
  • provide → Receive user input and supplement
  • infer → AI estimates, note in Assumptions section
  • skip → Mark item as "[TBD]" and proceed

Minimum Completion Criteria (Fail Gate)

If applicable items below are empty, return to debate phase:

ConditionMinimum Requirement
If API existsRequest/Response spec + at least 2 error responses
If Auth existsRole/Permission table with at least 1 entry
If Data (DB) existsCore entity with at least 5 fields defined

⚠️ If any item fails → Guide "Need supplemental information" and re-enter Phase 5.5

When all required items pass → Proceed to Phase 6


Phase 6: Write Design Document

Write implementation-ready design document based on debate results.

Section-by-Section Writing Guide

SectionContentSource
0. SummaryGoal/Non-goals/Success metricsExtract from requirements MD
1. ScopeIn/Out scopeScope confirmed in debate
1.5. Tech StackLanguage, framework, DB, 3rd-party, infraProject exploration or user input
2. Architecture ImpactComponents, Data changesDomain Architect design
3. Code MappingFeature → file/module mappingDomain Architect design + project exploration
4. Implementation PlanImplementation orderAgreed priority
5. Sequence DiagramMain flow visualizationMain agent elaborates
6. API SpecificationEndpoints, Request/ResponseMain agent elaborates
7. Infra/OpsEnvironment variables, deployment changesDomain Architect design
8. Risks & TradeoffsCore debate conclusionBoth arguments + adoption reasoning
9. Error/Auth/Data Checklist3 essential checksError handling, auth, data integrity

Section 1.5 Details (Tech Stack)

Specify project tech stack:

ItemExamples
LanguagePython 3.11 / TypeScript 5.x / Go 1.21 / Java 17
FrameworkFastAPI / NestJS / Spring Boot / Gin
DBPostgreSQL 15 / MySQL 8 / MongoDB 6
ORMSQLAlchemy / Prisma / TypeORM / GORM / None (Raw SQL)
3rd-partyRedis, Kafka, S3, Elasticsearch, etc.
InfraK8s / Docker / AWS / GCP / On-premise

Verify through project exploration or user input

Section 2 Details (Database Changes)

All tables must have full column definitions:

TypeContent to Write
New tableAll column definitions (Column, Type, Constraints, Description)
Existing table modificationFull schema before/after or Current full schema + changes noted

Anti-patterns (Prohibited):

  • "Delete X field from existing table" (→ change mentioned without full schema)
  • "Modify existing table" (→ unclear what columns exist)

Example:

ColumnTypeChangeDescription
idINTEGERMaintainPK
event_typeVARCHAR(100)MaintainEvent type
reference_idVARCHAR(100)NewRelated resource ID
is_readBOOLEANDelete→ Moved to separate table

Section 2 Addition: Database Migration (when manual SQL selected)

When migration method is "manual SQL", record the following for SQL generation in implementation phase:

Change TypeTableContent
CREATE TABLEalert_read_statusNew table
ALTER TABLEalertDelete is_read column
CREATE INDEXalert_read_statusAdd user_id index

Note: Actual SQL will be generated for specific DB type in implementation phase

Section 3 Details (Code Mapping - Integration)

External service integration requires specific call locations:

Required InfoDescription
File pathFull path (e.g., apps/issue/src/services/quality_issue/service.py)
Class nameClass to modify
Method nameMethod to modify (e.g., create_issue(), resolve_issue())
Call locationPoint in method (e.g., "After DB save, before response return")
Code to callCode snippet to add

Anti-patterns (Prohibited):

  • "Call AlertPublisher from Issue service" (→ which method?)
  • "src/services/*.py (modify)" (→ no specific file and method)

Example:

FeatureFileClassMethodAction
Quality Create.../quality_issue/service.pyQualityIssueServicecreate_issue()After DB save call _publish_create_alert()
Quality Resolve.../quality_issue/service.pyQualityIssueServiceresolve_issue()After status change call _publish_resolve_alert()

Section 8 Details (Debate Conclusion)

markdown
## 8. Risks & Tradeoffs (Debate Conclusion)

### Chosen Option
- (adopted design approach)

### Rejected Alternatives
- (unadopted items from Best Practice proposals and reasons)

### Reasoning
- Project constraints: ...
- Best practice adoption: ...
- Future improvement points: ...

### Assumptions
- **Confirmed**: (clearly decided in debate)
- **Estimated**: (assumed due to lack of confirmation)

Save Path

Path: docs/{serviceName}/arch.md

serviceName inferred from input file path:

  • Input: docs/alert/spec.md
  • Output: docs/alert/arch.md

Output Document Template

markdown
# Feature Design Doc: {Feature Name}

> Created: {date}
> Service: {serviceName}
> Requirements document: docs/{serviceName}/spec.md

## 0. Summary

### Goal
(Goal this feature aims to achieve - 1-2 sentences)

### Non-goals
- (Items excluded from this scope)

### Success metrics
- (List of success criteria)

---

## 1. Scope

### In scope
- (Items included in this implementation)

### Out of scope
- (Future improvements or excluded items)

---

## 1.5. Tech Stack

```yaml
tech_stack:
  language: "{language and version}"        # e.g., Python 3.11, TypeScript 5.x
  framework: "{framework}"                  # e.g., FastAPI, NestJS
  database: "{DB type and version}"         # e.g., PostgreSQL 15
  orm: "{ORM package or Raw SQL}"           # e.g., SQLAlchemy, Prisma
  third_party:                              # External services
    - "{service 1}"                         # e.g., Redis
    - "{service 2}"                         # e.g., Kafka
  infra: "{infra}"                          # e.g., K8s, Docker, AWS

2. Architecture Impact

Components

Service / ModuleResponsibilityChange type
{service name}{role}new / modify

Data

Database Schema

yaml
database_schema:
  new_tables:
    - name: "{table_name}"
      description: "{table description}"
      columns:
        - name: "id"
          type: "INTEGER"
          constraints: ["PK", "AUTO_INCREMENT"]
          description: "Primary key"
        - name: "{column_name}"
          type: "{type}"
          constraints: ["{constraint1}", "{constraint2}"]
          description: "{description}"
        - name: "created_at"
          type: "TIMESTAMP"
          constraints: ["NOT NULL", "DEFAULT NOW()"]
          description: "Creation timestamp"

  modified_tables:
    - name: "{table_name}"
      changes:
        - column: "{column_name}"
          type: "{type}"
          action: "ADD"          # ADD | DROP | MODIFY
          description: "{description}"

  indexes:
    - table: "{table_name}"
      columns: ["{column1}", "{column2}"]
      type: "BTREE"              # BTREE | HASH | GIN | etc.
      unique: false

Migration Summary

yaml
migrations:
  - type: "CREATE_TABLE"
    table: "{table}"
    description: "{description}"
  - type: "ALTER_TABLE"
    table: "{table}"
    description: "{change content}"
  - type: "CREATE_INDEX"
    table: "{table}"
    description: "{index description}"

3. Code Mapping

FeatureFileClassMethodAction
{feature}{full file path}{class name}{method name}{call location and code to add}

4. Implementation Plan

📂 Required Reference Files (Must read before implementation)

FileReference Purpose
{file path 1}{What to check in this file - patterns, style, dependencies, etc.}
{file path 2}{reference purpose}
{file path 3}{reference purpose}

⚠️ When running build skill, read above files first to understand patterns

Step-by-Step Implementation

  1. Step 1: {step name}

    • {detailed task 1}
    • {detailed task 2}
  2. Step 2: {step name}

    • {detailed task}
  3. Step 3: {step name}

    • {detailed task}

5. Sequence Diagram

{Flow name}

```mermaid sequenceDiagram participant Client participant API participant Service participant DB

code
Client->>API: {request}
API->>Service: {method call}
Service->>DB: {DB operation}
DB-->>Service: {result}
Service-->>API: {return}
API-->>Client: {response}

```


6. API Specification

yaml
api_endpoints:
  - name: "{API name}"
    method: "{GET|POST|PUT|DELETE}"
    path: "/api/v1/{path}"
    description: "{API description}"
    auth_required: true
    request:
      headers:
        - name: "Authorization"
          type: "string"
          required: true
      params:                    # Query params (GET) or Path params
        - name: "{param}"
          type: "{type}"
          required: true
      body:                      # Request body (POST/PUT)
        content_type: "application/json"
        schema:
          field1: "{type}"
          field2: "{type}"
    response:
      success:
        status: 200
        schema:
          success: "boolean"
          data: "{type or object}"
      errors:
        - status: 400
          code: "INVALID_INPUT"
          message: "{error message}"
        - status: 404
          code: "NOT_FOUND"
          message: "{error message}"

7. Infra/Ops

Environment Variables

VariableDescriptionDefault
{VAR_NAME}{description}{value}

Deployment Changes

  • (If needed)

8. Risks & Tradeoffs (Debate Conclusion)

Chosen Option

  • {adopted design approach}

Rejected Alternatives

  • {unadopted items and reasons}

Reasoning

  • Project constraints: {reason}
  • Best practice adoption: {applied parts}
  • Future improvement points: {what to do later}

Assumptions

  • Confirmed: {clearly decided in debate}
  • Estimated: {assumed due to lack of confirmation - needs verification in implementation}

9. Error/Auth/Data Checklist (3 Essential Checks)

Error Handling

SituationLocationHandling MethodResponse
{exception scenario}{file/method}{try-catch/exception propagation/logging}{HTTP code, error message}

Authorization

ActionRequired PermissionValidation LocationOn Failure
{API/feature}{role/permission}{middleware/service}{403/401 response}

Data Integrity

Validation ItemValidation TimingOn Failure
{FK existence}{before save}{400 + message}
{Duplicate check}{on create}{409 Conflict}
{Range validation}{on input}{422 + details}

⚠️ If this section is empty, 80% of implementation will be unstable - Must complete

code

---

# Completion Guidance

After saving document, inform user:

> ✅ **Design Document Complete**
>
> Saved to: `docs/{serviceName}/arch.md`
>
> **Next Step**: Run `build` skill to begin implementation.
> → Recommended to switch to **Sonnet model** in new session (cost savings)

---

# Integration Flow

[spec] → docs/{serviceName}/spec.md ↓ [arch] → docs/{serviceName}/arch.md ↓ [build] → Implementation ↓ (Bug occurs) ↓ [debug] → docs/{serviceName}/trace.md

code