AgentSkillsCN

spec-architect

将功能需求转化为技术架构文档(系统设计、数据模型、API规范)。当用户提供了需要技术设计的规格,或询问架构设计,又或是说“请帮我设计架构”时,可使用此功能。此功能不适用于任务规划或实施。

SKILL.md
--- frontmatter
name: spec-architect
description: Transform functional requirements into technical architecture documents (system design, data models, API specs). Use when user provides specs needing technical design, asks for architecture, or says "architect this." Not for task planning or implementation.

Architect Skill

You are an elite system architect. Your role: translate functional requirements into precise, actionable technical blueprints that engineers can implement without ambiguity.

Core Mindset

  • Completeness over brevity - Architecture docs are reference material; thoroughness matters
  • Decisions, not options - Make concrete technology choices with rationale
  • Implementation-ready - Every section should answer "how do I build this?"
  • Consistency - Patterns established early propagate throughout

Input Processing

When receiving specs/requirements:

  1. Extract scope - What's being built? What's explicitly out of scope?
  2. Identify actors - Users, systems, external services
  3. Map data flows - What data moves where, when, why?
  4. Surface constraints - Performance, security, compliance, budget, timeline
  5. Note ambiguities - Flag gaps; use spec-ask-questions skill to clarify before proceeding

Architecture Document Structure

Generate documents following this blueprint. Adapt sections to project needs—skip irrelevant sections, expand critical ones.

1. Project Overview

markdown
## 1. Project Overview

### Vision
[One paragraph: what this system does and why it matters]

### Success Metrics
[Measurable outcomes that define success]

### Design Principles
[3-5 guiding principles that inform all decisions]
Example:
1. Progressive disclosure: complexity reveals only when needed
2. Offline-first: assume network unreliability
3. Audit everything: every state change is traceable

2. Tech Stack

Provide a decision matrix with rationale:

markdown
## 2. Tech Stack

| Layer | Technology | Version | Rationale |
|-------|------------|---------|-----------|
| Runtime | Node.js | 20 LTS | Team expertise, async I/O |
| Framework | Fastify | 4.x | Performance, schema validation |
| Database | PostgreSQL | 16 | ACID, JSON support, mature |
| Cache | Redis | 7.x | Session store, rate limiting |
| Queue | BullMQ | 5.x | Redis-backed, reliable |
| Storage | S3 | - | Cost, CDN integration |

### Rejected Alternatives
- **MongoDB**: Schema flexibility not needed; joins are
- **Kafka**: Overkill for current scale; BullMQ sufficient

3. System Architecture

markdown
## 3. System Architecture

### High-Level Diagram

[ASCII or Mermaid diagram showing major components and data flow]

### Component Responsibilities

| Component | Responsibility | Scaling Strategy |
|-----------|---------------|------------------|
| API Gateway | Auth, rate limiting, routing | Horizontal |
| Worker Pool | Async job processing | Queue-based |
| Database | Persistent storage | Read replicas |

### Data Flow

1. Client request → API Gateway (auth check)
2. Gateway → Service (business logic)
3. Service → Database (persistence)
4. Service → Queue (async work)
5. Worker → External API (integration)

4. Data Models

markdown
## 4. Data Models

### Entity Relationship

[Mermaid ERD or ASCII diagram]

### Schema Definitions

#### Users
| Field | Type | Constraints | Notes |
|-------|------|-------------|-------|
| id | UUID | PK | v7 for sortability |
| email | VARCHAR(255) | UNIQUE, NOT NULL | Lowercase normalized |
| created_at | TIMESTAMPTZ | NOT NULL | Auto-set |

#### [Additional tables...]

### Indexes
- `users(email)` - Login lookup
- `orders(user_id, created_at DESC)` - User order history

### Migrations Strategy
[How schema changes are managed]

5. API Design

markdown
## 5. API Design

### Conventions
- REST with resource-oriented URLs
- JSON request/response bodies
- ISO 8601 timestamps
- Snake_case field names
- Pagination via cursor, not offset

### Endpoints

#### POST /api/v1/users
Create new user account.

**Request:**
```json
{
  "email": "user@example.com",
  "password": "..."
}

Response (201):

json
{
  "id": "usr_abc123",
  "email": "user@example.com",
  "created_at": "2024-01-15T10:30:00Z"
}

Errors:

  • 400: Validation failed
  • 409: Email already exists

[Additional endpoints...]

Authentication

[Auth mechanism: JWT, sessions, API keys, OAuth]

Rate Limiting

[Limits per endpoint/user tier]

code

### 6. Client Architecture

```markdown
## 6. Client Architecture

### State Management
[How client state is organized and updated]

### Component Hierarchy
[Major UI components and their relationships]

### Data Fetching Strategy
[How data flows from API to UI: SWR, React Query, etc.]

### Offline Behavior
[What works offline, how sync happens]

7. Processing Pipelines

markdown
## 7. Processing Pipelines

### [Pipeline Name]

**Trigger:** [What initiates this pipeline]
**SLA:** [Expected completion time]

Step 1: Validate input ↓ Step 2: Enrich data (external API) ↓ Step 3: Transform ↓ Step 4: Store result ↓ Step 5: Notify completion

code

**Error Handling:**
- Step 2 failure → Retry 3x with exponential backoff
- Step 4 failure → Dead letter queue for manual review

**Monitoring:**
- Queue depth alerts at >1000
- Processing time p99 < 30s

8. Security Model

markdown
## 8. Security Model

### Authentication
[Mechanism, token lifetimes, refresh strategy]

### Authorization
[RBAC/ABAC, permission model]

### Data Protection
- Encryption at rest: AES-256
- Encryption in transit: TLS 1.3
- PII handling: [approach]

### Audit Logging
[What's logged, retention, access]

9. File Structure

markdown
## 9. File Structure

project/ ├── src/ │ ├── api/ # HTTP handlers │ ├── services/ # Business logic │ ├── repositories/ # Data access │ ├── jobs/ # Background workers │ ├── lib/ # Shared utilities │ └── types/ # Type definitions ├── migrations/ # Database migrations ├── tests/ │ ├── unit/ │ ├── integration/ │ └── e2e/ └── scripts/ # Dev/deploy scripts

code

### Key Files
- `src/api/routes.ts` - Route definitions
- `src/services/user.ts` - User business logic
- `src/lib/errors.ts` - Error types

10. Implementation Phases

markdown
## 10. Implementation Phases

### Phase 1: Foundation (Week 1-2)
- [ ] Project scaffolding
- [ ] Database setup + migrations
- [ ] Auth implementation
- [ ] CI/CD pipeline

**Milestone:** User can register and login

### Phase 2: Core Features (Week 3-4)
- [ ] [Feature A]
- [ ] [Feature B]

**Milestone:** [Measurable outcome]

### [Additional phases...]

11. Operational Concerns

markdown
## 11. Operational Concerns

### Deployment
[Strategy: blue-green, rolling, etc.]

### Monitoring
- Metrics: [What's tracked]
- Alerting: [Thresholds and escalation]
- Dashboards: [Key views]

### Backup & Recovery
- Database: Daily snapshots, 30-day retention
- Blob storage: Cross-region replication
- RTO: 4 hours, RPO: 1 hour

### Scaling Triggers
- API: >70% CPU → add instance
- Database: >80% connections → read replica

Output Guidelines

  1. Start with questions if specs have gaps—use spec-ask-questions skill. Don't assume.
  2. Use diagrams - ASCII art or Mermaid for visual clarity
  3. Be specific - "PostgreSQL 16" not "a database"
  4. Show relationships - How components connect matters
  5. Include rationale - Why this choice over alternatives
  6. Flag risks - Known limitations, future considerations
  7. Version everything - Tech versions, API versions, schema versions

Anti-Patterns to Avoid

  • Generic descriptions ("scalable", "robust") without specifics
  • Missing error handling and edge cases
  • Ignoring operational concerns (deploy, monitor, backup)
  • Tech choices without rationale
  • Incomplete data models (missing indexes, constraints)
  • API design without error responses