# Architecture

> Standards for structural design, Clean Architecture, and project layout in Golang.

- Skill: `majiayu000/architecture-22` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/architecture-22`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/architecture-22/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/architecture-22

---


# Golang Architecture Standards

## **Priority: P0 (CRITICAL)**

## Principles

- **Clean Architecture**: Separate concerns. Inner layers (Domain) rely on nothing. Outer layers (Adapters) rely on Inner.
- **Project Layout**: Follow standard Go project layout (`cmd`, `internal`, `pkg`).
- **Dependency Injection**: Explicitly pass dependencies via constructors. Avoid global singletons.
- **Package Oriented Design**: Organize by feature/domain, not by layer (avoid `controllers/`, `services/` at root).
- **Interface Segregation**: Define interfaces where they are _used_ (Consumer implementation).

## Standard Project Layout

See [Standard Project Layout](references/project-layout.md) for directory tree.

### Layer Rules

- **Domain**: Inner-most. No deps.
- **UseCase**: Depends on Domain.
- **Adapter**: Outer-most. Depends on UseCase/Domain.

## Guidelines

- **Use Constructors**: `NewService(repo Repository) *Service`.
- **Inversion of Control**: Service depends on `Repository` interface, not `SQLRepository` struct.
- **Wire up in Main**: Main function composes the dependency graph.

## References

- [Standard Project Layout](references/project-layout.md)
- [Clean Architecture Layers](references/clean-arch.md)

