aif-architecture
npx skills add https://github.com/lee-to/ai-factory --skill aif-architecture
Agent 安装分布
Skill 文档
Architecture – Generate Architecture Guidelines
Generate .ai-factory/ARCHITECTURE.md with architecture decisions tailored to the project.
Workflow
Step 0: Load Project Context
Read .ai-factory/DESCRIPTION.md if it exists to understand:
- Tech stack (language, framework, database, ORM)
- Project size and complexity
- Core features and requirements
- Non-functional requirements
If .ai-factory/DESCRIPTION.md does not exist:
â ï¸ No project description found.
Run /aif first to set up project context, or describe your project manually:
- What are you building?
- Tech stack (language, framework, database)?
- Team size?
- Expected scale?
Allow standalone usage â if user provides manual input, use that instead.
Step 1: Analyze & Recommend
Based on project context, evaluate against the decision matrix and recommend an architecture:
If $ARGUMENTS specifies an architecture (e.g., /aif-architecture clean):
- Use that architecture directly, skip to Step 2
If no specific architecture requested:
- Evaluate the project against the decision matrix (see Knowledge Base below)
- Consider: team size, domain complexity, scale requirements, tech stack
- Present recommendation via
AskUserQuestion:
Based on your project context:
- [reason 1 from project analysis]
- [reason 2 from project analysis]
Which architecture pattern should we use?
1. [Recommended pattern] (Recommended) â [why it fits]
2. [Alternative 1] â [brief reason]
3. [Alternative 2] â [brief reason]
4. [Alternative 3] â [brief reason]
Architecture options:
- Clean Architecture â strict dependency inversion, good for complex business logic
- Domain-Driven Design (DDD) â bounded contexts, good for complex domains with multiple subdomains
- Microservices â independent deployment, good for large teams with clear domain boundaries
- Modular Monolith â single deployment with strong module boundaries, good default for most projects
- Layered Architecture â simple layers (presentation â business â data), good for smaller projects
Step 2: Generate .ai-factory/ARCHITECTURE.md
mkdir -p .ai-factory
Generate .ai-factory/ARCHITECTURE.md with the following structure, adapted to the project’s tech stack and language:
# Architecture: [Pattern Name]
## Overview
[1-2 paragraphs: what this architecture is and why it was chosen for THIS project]
## Decision Rationale
- **Project type:** [from DESCRIPTION.md]
- **Tech stack:** [language, framework]
- **Key factor:** [primary reason for this choice]
## Folder Structure
\`\`\`
[folder structure adapted to the project's tech stack]
[use actual framework conventions â e.g., Next.js app/ dir, Laravel app/ dir, Go cmd/ dir]
\`\`\`
## Dependency Rules
[What depends on what. Inner vs outer layers. Module boundaries.]
- â
[allowed dependency direction]
- â [forbidden dependency direction]
## Layer/Module Communication
[How layers or modules communicate with each other]
- [pattern 1]
- [pattern 2]
## Key Principles
1. [Principle 1 â adapted to this project]
2. [Principle 2]
3. [Principle 3]
## Code Examples
### [Example 1 title]
\`\`\`[language]
[code example in the project's language/framework]
\`\`\`
### [Example 2 title]
\`\`\`[language]
[code example showing dependency rule]
\`\`\`
## Anti-Patterns
- â [What NOT to do in this architecture]
- â [Common mistake to avoid]
Rules for generation:
- Adapt ALL examples to the project’s language and framework (don’t use TypeScript examples for a Go project)
- Use the project’s actual conventions (import paths, naming, etc.)
- Keep it practical â focus on rules that affect day-to-day development
- Folder structure should extend from what already exists in the project, not replace it
Step 3: Update DESCRIPTION.md
If .ai-factory/DESCRIPTION.md exists, add an ## Architecture section (or update if it already exists):
## Architecture
See `.ai-factory/ARCHITECTURE.md` for detailed architecture guidelines.
Pattern: [chosen pattern name]
Step 4: Update AGENTS.md
If AGENTS.md exists in the project root, add .ai-factory/ARCHITECTURE.md to the “AI Context Files” table:
| .ai-factory/ARCHITECTURE.md | Architecture decisions and guidelines |
Only add if not already present.
Step 5: Confirm
â
Architecture document generated!
Pattern: [chosen pattern]
File: .ai-factory/ARCHITECTURE.md
Key rules:
- [rule 1]
- [rule 2]
- [rule 3]
All workflow skills (/aif-plan, /aif-implement) will now follow these architecture guidelines.
Knowledge Base
Reference material for architecture evaluation and generation. This content informs the generation â it is NOT output directly.
Decision Matrix
| Factor | Layered | Clean Architecture | Modular Monolith | DDD | Microservices |
|---|---|---|---|---|---|
| Team size | 1-5 | 1-15 | 5-30 | 5-30 | 20+ |
| Domain complexity | Low | Medium-High | Medium-High | High | High |
| Scale requirements | Low | Moderate | Moderate-High | Moderate-High | Very High |
| Deploy independence | â | â | Partial | Partial | â |
| Initial velocity | â Fast | Medium | â Fast | Medium | â Slow |
| Operational complexity | â Low | â Low | â Low | Medium | â High |
Quick Decision Guide
New project, small team? â Modular Monolith or Layered
Complex business logic, many rules? â Clean Architecture
Multiple subdomains, large team? â DDD
Independent scaling + large org? â Microservices
Simple CRUD app? â Layered Architecture
Unclear requirements? â Start simple, refactor when patterns emerge
Clean Architecture
Core Principle: Dependencies point inward. Inner layers know nothing about outer layers.
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Frameworks & Drivers â
â âââââââââââââââââââââââââââââââââââââââââââââââââââ â
â â Interface Adapters â â
â â âââââââââââââââââââââââââââââââââââââââââââ â â
â â â Application Layer â â â
â â â âââââââââââââââââââââââââââââââââââ â â â
â â â â Domain Layer â â â â
â â â â (Entities & Business Rules) â â â â
â â â âââââââââââââââââââââââââââââââââââ â â â
â â âââââââââââââââââââââââââââââââââââââââââââ â â
â âââââââââââââââââââââââââââââââââââââââââââââââââââ â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Folder Structure (TypeScript example):
src/
âââ domain/ # Core business logic (no dependencies)
â âââ entities/
â âââ value-objects/
â âââ repositories/ # Interfaces only
âââ application/ # Use cases (depends on domain)
â âââ use-cases/
â âââ services/
âââ infrastructure/ # External concerns (implements interfaces)
â âââ database/
â âââ external/
â âââ config/
âââ presentation/ # UI/API layer
âââ api/
âââ controllers/
âââ dto/
Dependency Rules:
- Domain â nothing (pure business logic)
- Application â Domain only
- Infrastructure â Application + Domain (implements interfaces)
- Presentation â Application (calls use cases)
Domain-Driven Design (DDD)
Core Principle: Software structure mirrors the business domain. Bounded contexts define clear boundaries.
Strategic Patterns:
- Bounded Contexts: explicit boundaries around domain models
- Context Mapping: how contexts communicate (Shared Kernel, Customer/Supplier, Anti-Corruption Layer)
Tactical Patterns:
- Entities: identity-based objects
- Value Objects: immutable, equality by value
- Aggregates: consistency boundaries (all invariants enforced through aggregate root)
- Domain Events: communicate state changes between contexts
Folder Structure (TypeScript example):
src/
âââ contexts/
â âââ ordering/
â â âââ domain/ # Entities, VOs, events, repository interfaces
â â âââ application/ # Use cases, command/query handlers
â â âââ infrastructure/ # Repository implementations, external adapters
â â âââ api/ # HTTP handlers, DTOs
â âââ inventory/
â â âââ ...
â âââ shipping/
â âââ ...
âââ shared/
âââ kernel/ # Shared base classes, interfaces
Microservices
When to Use:
- Large teams needing independent deployment
- Different scaling requirements per service
- Polyglot persistence needs
When NOT to Use:
- Small team (< 10 people)
- Unclear domain boundaries
- Startups exploring product-market fit
Communication Patterns:
- Synchronous (HTTP/gRPC): queries, real-time validation
- Asynchronous (Events/Messages): side effects, eventual consistency
Data Patterns:
- Database per Service
- Saga Pattern for distributed transactions
Modular Monolith
Core Principle: Single deployment unit with strong module boundaries. Best of both worlds â simple ops, future extraction ready.
Folder Structure (TypeScript example):
src/
âââ modules/
â âââ users/
â â âââ api/ # HTTP handlers
â â âââ domain/ # Business logic
â â âââ infra/ # Database, external
â â âââ index.ts # Public API only
â âââ orders/
â â âââ ...
â âââ payments/
â âââ ...
âââ shared/ # Truly shared code
â âââ kernel/
â âââ utils/
âââ main.ts # Composition root
Module Communication Rules:
- Modules expose explicit public API via index file
- Other modules use ONLY the public API
- Never reach into module internals
Layered Architecture
Core Principle: Separate concerns into horizontal layers. Each layer only depends on the layer directly below it.
Folder Structure (TypeScript example):
src/
âââ routes/ # Presentation layer (HTTP handlers)
âââ controllers/ # Request/response handling
âââ services/ # Business logic layer
âââ models/ # Data models
âââ repositories/ # Data access layer
âââ utils/ # Cross-cutting utilities
Dependency Rules:
- Routes â Controllers â Services â Repositories â Database
- No skipping layers (routes should not call repositories directly)