architecture
npx skills add https://github.com/alexanderstephenthompson/claude-hub --skill architecture
Agent 安装分布
Skill 文档
Architecture Skill
Version: 3.0 Source: Architecture Principles + Project Structure Profiles
How to structure a project â both logically (module design, dependency flow) and physically (folder layout, naming, type-specific conventions).
Scope and Boundaries
This skill covers: Module design, dependency flow, folder structure, naming conventions, and project-type-specific layouts.
This skill does NOT cover: Code quality within files (see code-quality), documentation standards (see documentation), or build/deploy configuration.
Relationship to other skills:
- Works alongside
code-quality(file-level conventions) anddocumentation(docs standards) - Consumed by clean-team
:auditcommand (with focus:structure) - Referenced by clean-team, implement-team, and diagnose-team agents
North Star
Goal: Small changes stay local.
A typical feature should touch 1-2 modules, ship quickly, and not require coordinated edits across the system. If you find yourself editing 5+ files across multiple layers for a simple change, that’s a design smell.
Core Principles
1. Explicit Over Magic
Prefer readable wiring over convention-heavy frameworks. When someone reads your code, the control flow should be obvious. No @AutoInject() decorators that hide what depends on what â use explicit constructor parameters.
2. Boundaries Are Sacred
Modules communicate only through contracts (APIs, props, events). No reaching into another module’s internals. Import from the module’s public API, never from internal files.
3. Own Your Data
Each module owns its schema/state. Other modules read via APIs or props, never direct access. If OrderModule needs user data, it calls UserModule.getUserById() â it doesn’t query the users table directly.
4. Optimize for Refactoring
If code is hard to move or rename, it’s a design smell. Loose coupling enables safe refactoring.
The 3 Layers
01-presentation/ â 02-logic/ â 03-data/
| Layer | Responsibility | Examples |
|---|---|---|
| Presentation | What users see and interact with | Components, pages, styles |
| Logic | How it’s built, business rules | Services, use cases, validation |
| Data | How it persists, external sources | Repositories, models, adapters |
Valid Dependency Flow
Presentation â Logic â Data â
Data â Logic â (blocked)
Logic â Presentation â (blocked)
Presentation â Data â (blocked â no layer skipping)
Module Boundaries
A module is a cohesive unit with a clear public API, hidden implementation, and defined dependencies.
Module Rules
Single Entry Point: Each module exposes its API through an index file. External imports MUST go through it.
No Circular Dependencies: Modules cannot depend on each other in a cycle. Break cycles by extracting shared code, using events, or introducing an interface.
Own Your Data: Each module owns its data exclusively. Cross-module data is accessed via APIs, never direct DB queries.
Coupling Guidelines
| Coupling Type | OK? |
|---|---|
| Type import | Always |
| Function call via public API | Usually |
| Direct instantiation | Carefully |
| Shared mutable state | Avoid |
Full details:
references/module-boundaries.mdâ Module structure, boundary rules, communication patterns, coupling levels, refactoring guidance
Folder Structure
A well-organized project isn’t just tidy â it’s a project where you never have to ask “where does this go?” or “where would I find that?” The structure itself answers those questions. When folders mirror how you think about the project, navigation becomes intuitive rather than a search exercise. You find things where you expect them to be, on the first try.
This matters even more when AI is involved. AI has no memory between sessions â it can’t learn your project’s layout over time the way a human teammate would. Every session starts fresh. A clear, predictable structure means the AI spends less time searching and more time doing useful work. Descriptive folder names, consistent conventions, and logical grouping are context that the AI reads for free on every interaction.
The goal: any file should be findable in 2-3 navigation steps based on intuition alone. If you have to search, the structure failed.
Organize by Feature Within Tiers
For web projects using 3-tier architecture, organize by feature WITHIN each tier â don’t scatter a single feature across global models/, services/, controllers/ directories.
Within 02-logic/:
Prefer: Avoid:
02-logic/ 02-logic/
users/ models/
user.model.ts user.model.ts
user.service.ts order.model.ts
orders/ services/
... user.service.ts
order.service.ts
Feature-based grouping keeps related code together within each tier. Tiers enforce dependency flow (presentation â logic â data), while feature folders enforce cohesion within each tier. These are complementary, not contradictory.
For non-web projects (CLI tools, libraries, scripts) that don’t use 3-tier architecture, apply feature-based grouping at the project root level.
Universal Structural Principles
These apply to every project regardless of type.
Naming Consistency â Pick one casing convention per category and apply it everywhere. All components PascalCase, all utilities camelCase, all configs kebab-case. Consistency makes things findable â when you know the convention, you can predict the file name before you look.
Logical Grouping â Related files live together. If you change one, you’ll likely change the others. Co-locate by default. Only separate when there’s a clear benefit. The test for grouping: “If I’m working on X, what else will I need open?”
Reasonable Depth â No more than 4 levels from root to file. Every level of nesting must earn its place. If a folder contains only one subfolder containing one file â flatten it. Deep nesting isn’t organization, it’s a scavenger hunt.
Clear Entry Point â Someone opening the project for the first time should know where to start within 10 seconds. Root README explains what the project is. The main entry file is named conventionally (index, main, app). Top-level folders tell the story of what the project is.
Clean Root â The project root should contain only what must be there â entry points, top-level config, and the folders that define the project’s structure. Config files that must live at root (.gitignore, package.json, tsconfig.json) get a pass â stray scripts, utilities, and one-off files do not. When in doubt, move it deeper. The root is the first impression.
Self-Documenting Names â Folder names describe what’s inside, not how it’s used. formatters/, validators/, parsers/ are clear. utils/, helpers/, misc/ are dumping grounds. If a folder has more than 10 files with no shared theme, split by what the files actually do.
Project Type Profiles
Type-specific folder structures, naming conventions, and red flags. Each profile is a self-contained reference.
Detection Decision Tree
Does the project contain...
ââ package.json + .tsx/.jsx/.css/.html files?
â ââ YES â Load references/web.md
â
ââ Assets/ + .cs scripts + .unity scene files?
â ââ VRChat SDK present? (Packages/com.vrchat.*, VRCSDK3, UdonSharp)
â â ââ YES â Load references/vrchat.md (overrides Unity)
â ââ No VRC SDK
â ââ Load references/unity.md
â
ââ .blend files + texture images?
â ââ YES â Load references/blender.md
â
ââ .tf files / cdk.json / template.yaml?
â ââ YES â Load references/data-iac.md
â
ââ None of the above?
ââ Use Universal Structural Principles above
Priority rule: When multiple profiles match, use the most specific. VRChat overrides Unity. A project with both application code and IaC should use the application profile for the app and reference data-iac for the infrastructure portion.
Available Profiles
| Profile | Reference File | Best For |
|---|---|---|
| Web (React/Node) | references/web.md |
SPAs, fullstack apps, Node APIs, React projects |
| Unity | references/unity.md |
Unity games, tools, non-VRChat Unity projects |
| VRChat | references/vrchat.md |
VRChat worlds and avatars (extends Unity) |
| Blender | references/blender.md |
3D modeling, texturing, rendering projects |
| Data/IaC (AWS) | references/data-iac.md |
Terraform, CDK, CloudFormation infrastructure |
How to Use
- Detect the project type using the decision tree above
- Load the matching profile from
references/ - Compare the actual structure against the expected layout
- Evaluate using the checklist in
assets/structure-evaluation-checklist.md - Flag deviations as findings â prioritize red flags highest
Adding a New Profile
- Create
references/<type>.mdfollowing the standard template:- Why This Structure Matters â problem, benefit, cost of ignoring
- Detection â file patterns that identify this project type
- Expected Structure â annotated directory tree with principle comments
- Naming Conventions â table of type/convention/example
- Red Flags â 3-column table: Flag | Root Cause | Fix
- When to Reconsider â symptom â problem â action table
- Add a row to the Available Profiles table above
- Add a branch to the Detection Decision Tree
- Add a type-specific section to
assets/structure-evaluation-checklist.md
Pattern Selection
| Pattern | Use When |
|---|---|
| Pure functions | Stateless transformations |
| Module with functions | Grouping related functions |
| Class | State or DI needed |
| Factory | Complex object creation |
| Repository | Data access abstraction |
Default to simplicity: Function â Module â Class â Pattern
Full catalog:
references/design-patterns.mdâ Factory, Builder, Adapter, Facade, Decorator, Strategy, Observer, Command, Repository, Result Type
Testing Strategy
| Type | Purpose | Scope | Volume |
|---|---|---|---|
| Unit | Fast, deterministic, domain-heavy | Single function/component | Heavy |
| Integration | DB, APIs, external services | Module boundaries | Moderate |
| E2E | Critical user paths only | Full stack | Minimal |
Heavy unit tests, moderate integration, minimal E2E. E2E sprawl leads to brittle, slow test suites. Contract tests recommended for API boundaries.
Anti-Patterns
Code Architecture
| Anti-Pattern | Symptom | Fix |
|---|---|---|
| God Object | >500 lines, >10 public exports | Extract cohesive submodules |
| Anemic Domain Model | Getters/setters only, services do all work | Move behavior to entities |
| Shotgun Surgery | Adding a field requires 5+ file changes | Better encapsulation |
Project Structure
| Anti-Pattern | Symptom | Fix |
|---|---|---|
| Cluttered Root | 15+ files at project root, stray scripts alongside config | Move everything that isn’t an entry point or required config into folders |
| God Folder | One folder with 40+ files | Group by domain, feature, or function |
| Ghost Folders | Empty folders with no files and no clear purpose | Delete unless part of an intentional pattern |
| Naming Soup | Mixed casing: UserProfile.tsx, order-utils.ts, payment_service.py |
Pick one convention per file type, enforce it |
| Orphaned Files | Files that nothing imports or references | Verify unused, then delete |
| Deep Nesting | 5+ folder levels to reach a single file | Flatten â levels should reflect real boundaries |
| Mirror Trees | src/ and tests/ with identical structures |
Co-locate unit tests with source; separate tree only for integration/E2E |
| Config Explosion | 10+ config files at root | Consolidate where possible, move to config/ |
When to Extract
Start with a modular monolith (single deployable, clean internal boundaries).
Extract to separate services only when:
| Reason | Example |
|---|---|
| Scale | One part needs independent scaling |
| Team | Separate teams need independent deploy cycles |
| Technology | A component needs a different runtime/language |
Don’t extract for “cleanliness” â that adds operational complexity without benefit.
Observability Basics
Structured Logging: JSON, not string concatenation. Include context ({ userId, timestamp }), not messages ('User ' + userId + ' logged in').
Correlation IDs: Track requests across async operations.
Error Boundaries: Catch and report, don’t swallow silently.
Decision Records
For significant architectural choices, document: Context (problem), Decision (what we chose), Alternatives (what else we considered), Consequences (trade-offs).
Location: Documentation/decisions/
Template:
assets/decision-record-template.md
Scaling Principles
| Project Size | Focus On |
|---|---|
| Small | North Star, Red Flags |
| Growing | Add Testing Strategy, Observability |
| Team | Add Decision Records, Module Ownership |
Red Flags
Stop and reconsider when you see:
| Smell | Problem | Fix |
|---|---|---|
shared/common/utils dumping ground |
Ownership unclear, grows forever | Move to owning module or create focused package |
| Cross-module direct imports | Tight coupling | Use APIs, events, or props |
| Direct database access across modules | Hidden dependencies | Build a read API or service |
| “Quick helper” in wrong module | Boundary violation | Move to correct owner |
| Framework magic hiding control flow | Hard to debug, hard to refactor | Make it explicit |
| Feature touching 5+ unrelated files | Poor separation | Refactor boundaries |
Enforced Rules
These rules are deterministically checked by check.js (clean-team). When updating these standards, update the corresponding check.js rules to match â and vice versa.
| Rule ID | Severity | What It Checks |
|---|---|---|
tier-imports |
error | Imports that violate 01â02â03 dependency direction |
tier-structure |
error | Missing or incomplete 3-tier folder structure in web projects |
References
references/module-boundaries.mdâ Module structure, boundary rules, communication patternsreferences/design-patterns.mdâ Factory, Repository, Adapter, Strategy, Observer, etc.references/migration-patterns.mdâ Strangler Fig, Branch by Abstraction, Parallel Implementationsreferences/web.mdâ Web (React/Node) project structure profilereferences/unity.mdâ Unity project structure profilereferences/vrchat.mdâ VRChat project structure profile (extends Unity)references/blender.mdâ Blender project structure profilereferences/data-iac.mdâ Data/IaC (AWS) project structure profile
Assets
assets/architecture-checklist.mdâ Full architecture review checklistassets/structure-evaluation-checklist.mdâ Project structure evaluation checklist (universal + per-type)assets/decision-record-template.mdâ ADR template
Scripts
scripts/analyze_dependencies.pyâ Map circular dependencies and detect layer violations