clean-architecture-go

Enforce clean-architecture boundaries in Go projects with Gin and Gorm.

Updated Jul 7, 2024
One-click install
npx skills add https://github.com/manorfm/toToggles --skill clean-architecture-go
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clean-architecture-go
Source: https://github.com/manorfm/toToggles/tree/main/server/.agents/skills/clean-architecture-go
Command: npx skills add https://github.com/manorfm/toToggles --skill clean-architecture-go

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The Go backend often drifts away from clean architecture patterns, creating tangled code and slow maintenance. This skill codifies strict, repeatable rules to apply Clean Architecture within the toToogle project, ensuring proper boundaries between Entity, Repository Interface, Database (Gorm), Usecase, Handler, and Router.

Core Features & Use Cases

  • Enforces layered boundaries and explicit data flow across Entity → Repository Interface → Database (Gorm) → Usecase → Handler → Router.
  • Enforces dependency injection via constructors (e.g., NewXUsecase(repo)) and discourages global state to improve testability and maintainability.
  • Guides ULID generation in the BeforeCreate hook for entities to ensure consistent ID patterns.
  • Recommends unit testing with testify and standard Go testing practices to validate business rules.
  • Documents ORM mappings with GORM tags and aligns with sqlite as the supported database in examples.

Quick Start

Apply these rules when implementing any Go backend component for the toToogle project to maintain strict clean-architecture compliance.

Frequently Asked Questions about clean-architecture-go

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce clean architecture in a Go project using Gin and Gorm?

Enforce clean architecture in Go by guiding the AI to follow a layered structure across Entity, Repository Interface, Database, Usecase, Handler, and Router boundaries to prevent tangled code and slow maintenance.

How do I structure dependency injection in a Go usecase layer?

Structure dependency injection in Go via constructors like NewXUsecase(repo), discouraging global state to improve testability and maintainability across the usecase layer and its dependencies.

How do I generate ULID for entities in Gorm before creating records?

Generate ULID for entities in Gorm by implementing the BeforeCreate hook, ensuring consistent ID patterns for database records during the creation lifecycle.

How do I write unit tests for Go usecase business logic?

Write unit tests for Go usecase business logic using testify and standard Go testing practices to validate rules and maintain strict clean architecture compliance.

How do I map Go entities to database tables using Gorm tags?

Map Go entities to database tables using Gorm tags for ORM compatibility, aligning with sqlite as the supported database in examples to document schema mappings explicitly.