CLI Reference

add domain

Add the module root package's domain files and the module-level repository/ skeleton to a module that doesn't have them.

Run this on a module that doesn't yet have a root domain package, for example one you built by hand, or a minimal module stripped down to just a surface.

go tool gpsystem add domain <module> [--db <name>]

Renders the module-level shared skeletons into an existing module: the module root package's domain files (home of the entities, rules and sentinel errors every surface shares; the package is named after the module, so callers write news.Service and news.ErrNotFound) and the skeleton of the module's single repository/ persistence layer. New modules do not need it: add surface stamps both automatically alongside a module's first surface (and skips them when the module root already holds .go files). add domain is for the rest: a module built without the generator, or one whose domain files were deleted.

What it renders

  • internal/modules/<module>/<module>.go: the package documentation, including the import direction rule (http → service → <module> (module root) → repository; the module root never imports a surface package, handlers never import the repository package)
  • internal/modules/<module>/errors.go: an ErrNotFound sentinel via errs.Define, as the example of defining "no such record" errors in the module root (or re-exporting them from the repository) so handlers always check them through their own surface's service package
  • internal/modules/<module>/repository/doc.go: the package skeleton of the module's shared persistence layer (row structs + interface + implementation go here, once per module)

The command is purely additive: it touches no anchors and modifies no existing file, it only creates new files. An existing domain file surfaces as a normal conflict. On success it prints: Domain skeleton added to module "<m>": internal/modules/<m>/{<m>.go,errors.go,repository}.

--db: named connection

By default the repository skeleton is flat (repository/doc.go), bound to the project's default database connection. --db <name> binds it to a named connection added earlier with add db, and renders the skeleton as a connection-named subfolder instead:

go tool gpsystem add db news analytics --connector bun
go tool gpsystem add domain news --db analytics
# -> internal/modules/news/repository/analytics/doc.go

<name> must already exist on the module; the command fails fast, listing the module's available connections, if it does not.

Copyright © 2026