go-ai-ready-boilerplate / rules
Cursor rule1 starsChanged 4 months agoMITView on GitHub
Hexagonal architecture: layer boundaries and dependency direction
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,527 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/01-project-overview.mdcCursor rule
- .cursor/rules/03-workflow.mdcCursor rule
- .cursor/rules/04-testing.mdcCursor rule
- .cursor/rules/05-coding-standards.mdcCursor rule
- .cursor/rules/06-commit-protocol.mdcCursor rule
- .cursor/rules/07-documentation.mdcCursor rule
- .cursor/rules/08-testing-standards.mdcCursor rule
- .cursor/rules/karpathy-guidelines.mdcCursor rule
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-bulk-archive-changeSkill
- openspec-continue-changeSkill
- openspec-exploreSkill
- openspec-ff-changeSkill
- openspec-new-changeSkill
- openspec-onboardSkill
- openspec-sync-specsSkill
- openspec-verify-changeSkill
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-bulk-archive-changeSkill
- openspec-continue-changeSkill
- openspec-exploreSkill
- openspec-ff-changeSkill
- openspec-new-changeSkill
- openspec-onboardSkill
- openspec-sync-specsSkill
- openspec-verify-changeSkill
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-bulk-archive-changeSkill
- openspec-continue-changeSkill
- openspec-exploreSkill
- openspec-ff-changeSkill
- openspec-new-changeSkill
- openspec-onboardSkill
- openspec-sync-specsSkill
- openspec-verify-changeSkill
The file
We split this 02-architecture.mdc into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 37
All dependencies are constructor-injected in main.go.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Hexagonal architecture: layer boundaries and dependency direction"
globs:
alwaysApply: true
---
# Rule: Architecture (hexagonal boundaries)
## The model
A **port** is the core's socket to the outside world - nothing more. The
core (application) owns its boundary; adapters are the only "outside"
things that plug into it.
```
OUTSIDE WORLD - adapters
┌───────────────────────────────────────────────────────────┐
│ driver adapters (http, consumer) - plug in │
│ driven adapters (repositories, publishers)- plug in │
└───────────────────────────────────────────────────────────┘
│ ▲
Driver-Port Driven-Port
(ports/driver) (ports/driven)
▼ │
┌───────────────────────────────────────────────────────────┐
│ CORE - application/usecases (do stuff) │
│ domain underneath │
└───────────────────────────────────────────────────────────┘
```
## Hard architectural rules (enforced by `make arch` / go-arch-lint - never bypass them)
1. `internal/domain/**` imports nothing outside the standard library.
2. `internal/application/ports/**` imports `internal/domain` only - ports are pure interfaces (+ port-level input structs).
3. `internal/application/usecases/**` imports ports/domain/pkg - never adapters.
4. Driver adapters (`internal/adapters/http/**`, `internal/adapters/consumer/**`) call the core ONLY through **driver ports** (`internal/application/ports/driver/**`) - never a concrete use case, and never repository or driven adapters (not even in tests).
5. Driven adapters (`internal/adapters/repositories/**`, `internal/adapters/publishers/**`) implement **driven ports** (`internal/application/ports/driven/**`) - never import use cases or driver adapters directly; compose in `main.go` wiring instead.
6. Constructors (`NewXxx`) for use cases and driven adapters MUST always return their port interface (e.g. `NewCreateTaskUsecase(...) driver.TaskCreator`, `NewStore() repositories.TaskRepository`, `NewPublisher(...) events.TaskEventPublisher`) - callers wire interfaces, never concrete structs.
7. `config/` and `pkg/` import nothing project-internal except where shown in `.go-arch-lint.yml`.
8. All dependencies are constructor-injected in `main.go`. No globals, no service locators, no init()-based wiring.
## How to add a feature slice (copy the canonical `task` slice exactly)
1. `internal/domain/<aggregate>.go` - entity, invariants, errors, domain events (pure Go, stdlib only). One file per aggregate.
2. `internal/application/ports/driver/usecases/<capability>.go` - one **driver port** interface per capability, behavior-named (e.g. `TaskCreator`, `TaskLister`).
3. `internal/application/ports/driven/repositories/<repository>.go` - the **driven port** interface the core needs (e.g. `task_repository.go`). Add `events/publisher.go`, `cache.go`, ... in subfolders as new needs appear.
4. `internal/application/usecases/<domain>/` - one standalone struct per use case (grouped per domain: `task/`, `audit/`) with its own `NewXxx` constructor returning the driver port interface. The composition root (`main.go`) inits them directly and passes each to the adapters that need it - no facade/service aggregator in between.
5. `internal/adapters/repositories/<backend>/<table>.go` - implementation(s) of driven repository ports (e.g. `memory/store.go`, `postgres/tasks.go` returning `repositories.TaskRepository`).
6. `internal/adapters/publishers/<backend>/<publisher>.go` - implementation(s) of driven event ports (e.g. `memory/publisher.go` returning `events.TaskEventPublisher`).
7. `internal/adapters/http/` - HTTP driver adapter: bootstrap in `server.go`, error envelope in `errors.go`, subpackages per concern (`health/`, `middleware/`, `task/`).
8. `internal/adapters/consumer/` - event consumer driver adapter: consumes inbound messages/events and calls driver ports.
9. `main.go` - wire: driven adapters -> use cases -> driver ports -> driver adapters.
10. Tests at every layer (see 04-testing.md); update `docs/openapi.yaml` + `docs/architecture.md`.
## Conventions
- Each package has a doc comment stating its single responsibility; keep it true.
- Ports are owned by the core (application), not by the implementer (adapters).
- Driver adapters only call driver ports; driven adapters only implement driven ports.
- Interfaces stay small (per capability); composite ports are assembled from granular ones.
- Neither side of an adapter pair may bypass ports to reach the other side.
- Features stay vertically coherent: all layers present or none (no orphan domain types).
- Errors carry domain meaning; adapters map them (see the HTTP error envelope in `docs/architecture.md`).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

