Collapse the byte-identical fga/db embed shims into toolbelt #5

Closed
opened 2026-08-06 16:45:52 +00:00 by ginjiruu · 2 comments
Owner

Question

Can the byte-identical fga/db embed shims collapse into toolbelt helpers?

internal/fga/embed.go (41 lines) and internal/db/database.go (28 lines) are byte-identical across both consumers (and near-identical in the example), delegating //go:embed FS access to toolbelt/embeddedfga and toolbelt/db. This passes the "example proves it" boundary.

Decisions this ticket resolves:

  1. Does the toolbelt ship //go:embed-friendly helpers (e.g. an embeddedfga.ModelFS/db.WithMigrations pattern) that make the per-app shim a one-liner or disappear entirely?
  2. What stays per-app (the actual migration/model files)?

Resolve with /grilling + /domain-modeling. On close, write the plan to docs/plans/ and reshape the relevant example/ surface.

## Question Can the byte-identical fga/db embed shims collapse into toolbelt helpers? `internal/fga/embed.go` (41 lines) and `internal/db/database.go` (28 lines) are byte-identical across both consumers (and near-identical in the example), delegating `//go:embed` FS access to `toolbelt/embeddedfga` and `toolbelt/db`. This passes the "example proves it" boundary. Decisions this ticket resolves: 1. Does the toolbelt ship `//go:embed`-friendly helpers (e.g. an `embeddedfga.ModelFS`/`db.WithMigrations` pattern) that make the per-app shim a one-liner or disappear entirely? 2. What stays per-app (the actual migration/model files)? Resolve with `/grilling` + `/domain-modeling`. On close, write the plan to `docs/plans/` and reshape the relevant `example/` surface.
Author
Owner

Resolution

Resolved via /grilling + /domain-modeling (claim: ginjiruu).

Decisions:

  1. FGA shim → bare exported embed var. internal/fga/embed.go becomes //go:embed model + var ModelFS embed.FS. Deleted: ModelFS(), ModDir, EmbeddedModData, EmbeddedModules, ModelFiles, EmbeddedFGAModelFS (all dead except ModelFS()/ModDir; the audit found no callers for the rest). app.go passes ModelFS: fga.ModelFS, drops ModelDir (default is already "model").
  2. DB shim → bare exported embed var. internal/db/database.go becomes //go:embed migrations/*.sql + var MigrationsFS embed.FS. Deleted: Migrations(), NewDatabase.
  3. The NewDatabase wrapper is absorbed as a variadic functional-options API — same idiom embeddedfga already uses. toolbelt/db gains type Option func(*options) error, WithMigrationsDir (default "migrations"), WithLogger (default zap.NewNop()); the 5-arg NewDatabase becomes NewDatabase(ctx, dbPath string, fsys fs.FS, opts ...Option). Call sites become appdb.NewDatabase(ctx, dbPath, db.MigrationsFS, logger).
  4. Embed-dir convention codified by documentation, not code. Option defaults express it; deviation means a loud startup failure. KCL cannot verify it — the schema.k fragments declare config values, and embed-dir names are Go-source layout, not a config field. No KCL involvement.
  5. No code lands with this ticket. The user deferred all toolbelt + example changes to a separate post-map clean rewrite of example/ (out of this map's scope), where the challenges are reassessed against every absorbed surface at once. This ticket closes with the plan doc only.

Deliverable: docs/plans/embed-shims.md (committed to the toolbelt repo).

embeddedfga.ModelFiles becomes fully dead once the shims go (fga-generate uses ReadModules/ReadModFile only) — its deletion rides along in the rewrite.

## Resolution Resolved via `/grilling` + `/domain-modeling` (claim: ginjiruu). **Decisions:** 1. **FGA shim → bare exported embed var.** `internal/fga/embed.go` becomes `//go:embed model` + `var ModelFS embed.FS`. Deleted: `ModelFS()`, `ModDir`, `EmbeddedModData`, `EmbeddedModules`, `ModelFiles`, `EmbeddedFGAModelFS` (all dead except `ModelFS()`/`ModDir`; the audit found no callers for the rest). `app.go` passes `ModelFS: fga.ModelFS`, drops `ModelDir` (default is already `"model"`). 2. **DB shim → bare exported embed var.** `internal/db/database.go` becomes `//go:embed migrations/*.sql` + `var MigrationsFS embed.FS`. Deleted: `Migrations()`, `NewDatabase`. 3. **The `NewDatabase` wrapper is absorbed as a variadic functional-options API** — same idiom `embeddedfga` already uses. `toolbelt/db` gains `type Option func(*options) error`, `WithMigrationsDir` (default `"migrations"`), `WithLogger` (default `zap.NewNop()`); the 5-arg `NewDatabase` becomes `NewDatabase(ctx, dbPath string, fsys fs.FS, opts ...Option)`. Call sites become `appdb.NewDatabase(ctx, dbPath, db.MigrationsFS, logger)`. 4. **Embed-dir convention codified by documentation, not code.** Option defaults express it; deviation means a loud startup failure. **KCL cannot verify it** — the `schema.k` fragments declare config *values*, and embed-dir names are Go-source layout, not a config field. No KCL involvement. 5. **No code lands with this ticket.** The user deferred all toolbelt + example changes to a separate post-map clean rewrite of `example/` (out of this map's scope), where the challenges are reassessed against every absorbed surface at once. This ticket closes with the plan doc only. **Deliverable:** `docs/plans/embed-shims.md` (committed to the toolbelt repo). `embeddedfga.ModelFiles` becomes fully dead once the shims go (fga-generate uses `ReadModules`/`ReadModFile` only) — its deletion rides along in the rewrite.
Author
Owner

Resolved: bare-variable shims + variadic-option appdb.NewDatabase; plan at docs/plans/embed-shims.md; no code lands (deferred to post-map example rewrite).

Resolved: bare-variable shims + variadic-option appdb.NewDatabase; plan at docs/plans/embed-shims.md; no code lands (deferred to post-map example rewrite).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ginjiruu/toolbelt#5
No description provided.