gs-feature-architecture
2
总安装量
1
周安装量
#72677
全站排名
安装命令
npx skills add https://github.com/gilbertopsantosjr/fullstacknextjs --skill gs-feature-architecture
Agent 安装分布
amp
1
cline
1
opencode
1
cursor
1
kimi-cli
1
codex
1
Skill 文档
Feature Architecture (Clean Architecture OOP)
Layer Overview
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Presentation Layer (src/features/, src/app/) â
â Server Actions (thin adapters), Components, Pages â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â Application Layer (src/backend/application/) â
â Use Cases, DTOs, Application Services â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â Infrastructure Layer (src/backend/infrastructure/) â
â Repository Implementations, External Services, DI Container â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â Domain Layer (src/backend/domain/) â
â Entities, Value Objects, Repository Interfaces, Domain Events â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
The Dependency Rule
CRITICAL: Dependencies only point inward. Inner layers NEVER import from outer layers.
Domain â Application â Infrastructure â Presentation
| Layer | Can Import From | CANNOT Import From |
|---|---|---|
| Domain | Nothing | Application, Infrastructure, Presentation |
| Application | Domain | Infrastructure, Presentation |
| Infrastructure | Domain, Application | Presentation |
| Presentation | All layers | – |
Implementation Order
Always implement from inside-out (Domain first):
- Entity – Domain object with private constructor, validate(), factory methods
- Repository Interface – Contract in Domain layer
- Use Case – Business logic with constructor injection
- DTO – Data transfer object with
static fromEntity() - Repository Implementation – DynamoDB/external service in Infrastructure
- DI Registration – Wire dependencies in Container
- Action Adapter – Thin server action (3-5 lines)
- Components – UI consuming DTOs
Directory Structure
src/
âââ backend/
â âââ domain/
â â âââ <feature>/
â â âââ entities/
â â â âââ <Entity>.ts # Entity class with validate()
â â âââ repositories/
â â â âââ I<Entity>Repository.ts # Interface only
â â âââ value-objects/
â â â âââ <ValueObject>.ts # Immutable value types
â â âââ exceptions/
â â âââ <Feature>Exceptions.ts # Domain exceptions
â â
â âââ application/
â â âââ <feature>/
â â âââ use-cases/
â â â âââ Create<Entity>UseCase.ts
â â â âââ Update<Entity>UseCase.ts
â â â âââ Delete<Entity>UseCase.ts
â â â âââ Get<Entity>UseCase.ts
â â âââ dtos/
â â âââ <Entity>DTO.ts # Static fromEntity()
â â
â âââ infrastructure/
â â âââ <feature>/
â â â âââ repositories/
â â â âââ DynamoDB<Entity>Repository.ts
â â âââ di/
â â âââ container.ts # DI Container
â â âââ tokens.ts # Injection tokens
â â
â âââ shared/
â âââ exceptions/
â â âââ BaseException.ts
â âââ types/
â âââ index.ts
â
âââ features/
â âââ <feature>/
â âââ actions/
â â âââ create-<entity>-action.ts # Thin adapter
â â âââ update-<entity>-action.ts
â â âââ index.ts
â âââ components/
â â âââ <Component>.tsx
â â âââ <Component>-client.tsx
â âââ index.ts # Public exports (DTOs, actions)
â
âââ app/
âââ (dashboard)/
âââ <feature>/
âââ page.tsx
Layer Responsibilities
Domain Layer (Innermost)
- Entities: Business objects with behavior, private constructor,
create(),fromPersistence(),validate(),toDTO() - Repository Interfaces: Contracts for data access (e.g.,
ICategoryRepository) - Value Objects: Immutable objects representing concepts (e.g.,
Money,Email) - Domain Exceptions: Business rule violations
- NO external dependencies, NO frameworks
Application Layer
- Use Cases: Single-responsibility business operations with
execute()method - DTOs: Data structures for crossing boundaries,
static fromEntity() - Application Services: Orchestration when needed
- Uses constructor injection for dependencies
- NO direct database access, NO HTTP concerns
Infrastructure Layer
- Repository Implementations: DynamoDB, external APIs
- DI Container: Dependency injection setup
- External Service Adapters: Email, payment, etc.
- Throws exceptions on errors (no
{success, data?, error?}pattern)
Presentation Layer
- Server Actions: Thin adapters (3-5 lines), resolve Use Case from DI, execute, return
- Components: React components receiving DTOs
- Pages: Route definitions
- Zod Schemas: Input shape validation only (not business rules)
Data Flow
User Action
â
Component (client)
â
Server Action (thin adapter)
â
âââ Resolve Use Case from DI Container
âââ Execute Use Case
âââ Return DTO
â
Use Case (Application Layer)
â
âââ Create/Load Entity
âââ Entity.validate() (business rules)
âââ Repository.save(entity)
â
Repository Implementation (Infrastructure)
â
DynamoDB
Quick Reference
| Need to… | Go to… |
|---|---|
| Add business rules | src/backend/domain/<feature>/entities/<Entity>.ts â validate() |
| Add data access contract | src/backend/domain/<feature>/repositories/I<Entity>Repository.ts |
| Add business operation | src/backend/application/<feature>/use-cases/ |
| Add data shape for UI | src/backend/application/<feature>/dtos/<Entity>DTO.ts |
| Implement repository | src/backend/infrastructure/<feature>/repositories/ |
| Add API endpoint | src/features/<feature>/actions/ (thin adapter) |
| Add UI element | src/features/<feature>/components/ |
| Add page route | src/app/ |
| Add input validation | src/features/<feature>/schemas/ (Zod for shape only) |
Naming Conventions
| Layer | Type | Convention | Example |
|---|---|---|---|
| Domain | Entities | PascalCase | Category.ts |
| Domain | Interfaces | IPascalCase | ICategoryRepository.ts |
| Domain | Exceptions | PascalCase + Exception | CategoryNotFoundException.ts |
| Application | Use Cases | VerbNounUseCase | CreateCategoryUseCase.ts |
| Application | DTOs | PascalCase + DTO | CategoryDTO.ts |
| Infrastructure | Implementations | PrefixPascalCase | DynamoDBCategoryRepository.ts |
| Presentation | Actions | kebab-case | create-category-action.ts |
| Presentation | Components | PascalCase | CategoryCard.tsx |
| Presentation | Schemas | PascalCase + Schema | CreateCategorySchema.ts |
Import Restrictions (Dependency Rule)
// â VIOLATION: Domain importing from Application
// src/backend/domain/category/entities/Category.ts
import { CategoryDTO } from '@/backend/application/category/dtos' // WRONG!
// â VIOLATION: Domain importing from Infrastructure
// src/backend/domain/category/entities/Category.ts
import { getDynamoDbTable } from '@/backend/infrastructure/database' // WRONG!
// â VIOLATION: Application importing from Infrastructure
// src/backend/application/category/use-cases/CreateCategoryUseCase.ts
import { DynamoDBCategoryRepository } from '@/backend/infrastructure' // WRONG!
// â
CORRECT: Application imports from Domain
// src/backend/application/category/use-cases/CreateCategoryUseCase.ts
import { Category } from '@/backend/domain/category/entities'
import type { ICategoryRepository } from '@/backend/domain/category/repositories'
// â
CORRECT: Infrastructure imports from Domain and Application
// src/backend/infrastructure/category/repositories/DynamoDBCategoryRepository.ts
import type { ICategoryRepository } from '@/backend/domain/category/repositories'
import { Category } from '@/backend/domain/category/entities'
// â
CORRECT: Presentation imports from all inner layers
// src/features/category/actions/create-category-action.ts
import { CreateCategoryUseCase } from '@/backend/application/category/use-cases'
import { DIContainer, TOKENS } from '@/backend/infrastructure/di'
Detection Commands
# Domain importing from outer layers (CRITICAL VIOLATION)
grep -rn "from '@/backend/application\|from '@/backend/infrastructure\|from '@/features/" src/backend/domain/
# Application importing from Infrastructure (VIOLATION)
grep -rn "from '@/backend/infrastructure" src/backend/application/
# Backend importing Next.js (VIOLATION)
grep -rn "from 'next/\|from 'react\|'use server'" src/backend/
# Fat server actions (direct DB access - VIOLATION)
grep -rn "getDynamoDbTable\|getModel" src/features/*/actions/
# Direct instantiation instead of DI (VIOLATION)
grep -rn "new.*UseCase(\|new.*Repository(" src/features/
# Entity without private constructor (VIOLATION)
grep -rn "export class" src/backend/domain/*/entities/ -A5 | grep -v "private constructor"
Related Skills
- create-domain-module – Generate complete feature with Clean Architecture
- zod-validation – Input shape validation in Presentation layer
- dynamodb-onetable – Repository implementation patterns
- nextjs-server-actions – Thin adapter action patterns
- nextjs-web-client – Component patterns with DTOs
- evaluate-domain-module – Assess Clean Architecture compliance