Prompt file imported from cdalsoniii/brightpath-coder (
.cursor/commands/domain-scaffold.md). Copyright stays with the author.
Domain Scaffold
Usage
Invoke with the entity name and type:
/domain-scaffold Account— scaffold a new entity named Account
Steps
-
Validate entity name: Ensure PascalCase naming, no conflicts with existing models
-
Generate model: Create
internal/models/<entity>.gowith:- UUID primary key with
gorm:"type:text;primaryKey" - Standard timestamps (CreatedAt, UpdatedAt)
TableName()methodBeforeCreate()hook for UUID generation- Status enum with validation method (if applicable)
- Follow patterns from rule 122 (GORM conventions)
- UUID primary key with
-
Generate repository interface: Add to
internal/repository/repository.go:Create,FindByID,FindAll(paginated),Update,Deletemethods- Follow repository patterns from rule 125 (layer boundaries)
-
Generate service: Create
internal/service/<entity>_service.gowith:- Constructor function
New<Entity>Service(db *gorm.DB, repo <Entity>Repository) - CRUD methods with proper error wrapping per rule 124
- Sentinel errors for not-found, validation failures
- Constructor function
-
Generate handler: Create
internal/handler/<entity>_handler.gowith:- Service interface defined locally (handler owns the interface)
- CRUD endpoint handlers
- Proper DTO conversion (request → service params, models → response)
- Error-to-HTTP mapping per rule 124
-
Generate DTOs: Create
internal/dto/request/<entity>.goandinternal/dto/response/<entity>.go -
Generate test stubs: Create
internal/models/<entity>_test.go,internal/service/<entity>_service_test.gowith table-driven test structure -
Register in database: Add model to
AutoMigrateininternal/database/database.go -
Wire in main: Add service and handler initialization in
cmd/api/main.go