Skip to content

scafolding#137

Open
mdeyell-valid-mind wants to merge 2 commits into
mainfrom
scafolding
Open

scafolding#137
mdeyell-valid-mind wants to merge 2 commits into
mainfrom
scafolding

Conversation

@mdeyell-valid-mind

@mdeyell-valid-mind mdeyell-valid-mind commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Atryum can now be embedded as a Go dependency by downstream programs. Import github.com/validmind/atryum/pkg/atryum and call atryum.Main(...) from the downstream binary’s main package.

The extension surface supports:

  • atryum.WithRoutes(...) to register additional HTTP routes on Atryum’s mux.
  • atryum.WithMigrations(...) to run downstream-owned, namespaced schema migrations after Atryum’s built-in migrations.
  • atryum.WithDatabase(...) to receive the initialized database connection after migrations.

Example:

package main

import "github.com/validmind/atryum/pkg/atryum"

func main() {
atryum.Main(
atryum.WithRoutes(registerRoutes),
atryum.WithMigrations("my-extension", migrations),
atryum.WithDatabase(bindStores),
)
}

This produces one binary containing the complete Atryum CLI and server plus the downstream extension. Routes contributed through WithRoutes are mounted outside Atryum’s built-in authentication middleware, so downstream
handlers are responsible for any authentication they require.

Testing:
I ran atryum and didn't see any changes

Comment thread pkg/atryum/options.go
// runs after the built-in routes are registered and outside every auth
// middleware chain (like /healthz): each extra route is responsible for its
// own authentication. Patterns must not collide with built-in routes.
func WithRoutes(register func(mux *http.ServeMux)) Option {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what external callers use to add routes to atryum

Comment thread internal/api/handlers.go
// AddExtraRoutes registers a callback that may mount additional routes on the
// server mux built by Routes. Patterns must not collide with built-in routes
// (http.ServeMux panics on duplicate registration).
func (h *Handler) AddExtraRoutes(register func(mux *http.ServeMux)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the internal atryum function that lets routes get added to it

Comment thread pkg/atryum/options.go
// migrations (built-in and extension) have been applied, before the server
// starts accepting requests. usePostgres distinguishes the SQL dialect, with
// false meaning SQLite (the same convention as migrations.Step).
func WithDatabase(hook func(db *sql.DB, usePostgres bool)) Option {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what external callers use to give atryum its database

Comment thread pkg/atryum/options.go
// own, so each extension numbers its migrations from 1 and new upstream
// migrations can never collide with them. The namespace identifies the
// extension (e.g. "authority") and must stay stable across releases.
func WithMigrations(namespace string, definitions []migrations.Definition) Option {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how external callers tell atryum about their migrations. The external migrations run after internal

@mdeyell-valid-mind
mdeyell-valid-mind marked this pull request as ready for review July 14, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant