base

package module
v1.5.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 15 Imported by: 8

README

Base

Base

The embedded, SQLite-first application backend for the Hanzo cloud — per-tenant data, in-process extension runtimes, and Hanzo IAM built in. One Go binary; the storage substrate every multi-tenant Hanzo Go service builds on.

Status License

Quick start

go install github.com/hanzoai/base/examples/base@latest
base serve

Then open the admin dashboard at http://127.0.0.1:8090/_/.

[!NOTE] Base is under active development. Full backward compatibility is not guaranteed before v1.0.0.

What this is

Base is an open source Go backend that gives every Hanzo Go service the same multi-tenant substrate. It includes:

  • embedded in-memory, SQL, and vector data with realtime subscriptions
  • built-in files and users management
  • a convenient Admin dashboard UI
  • GraphQL and a REST-style /v1 API
  • native analytics and AI observability
  • Hanzo IAM as the one and only auth path (OIDC / PKCE)
  • deep integration with the Hanzo AI Cloud for scale on day one

Each org gets its own per-tenant data file with a per-org KMS-derived DEK; replicate streams the WAL to age-encrypted object storage. Per-record validators, computed fields, and access rules run inside the same process via in-process extension runtimes (goja, wazero, pyvm, starkvm).

Use Hanzo App to rapidly iterate and build new apps.

API clients

The easiest way to talk to the Base web API is one of the official SDK clients:

See the full guide at docs.hanzo.ai.

Overview

Use as a standalone app

Download the prebuilt executable for your platform from the Releases page, extract the archive, and run ./base serve.

The prebuilt executables are built from examples/base/main.go and ship with a JavaScript plugin enabled by default, so you can extend Base with JavaScript (see Extend with JavaScript).

Use as a Go framework / toolkit

Base is distributed as a regular Go library, so you can build your own app-specific business logic and still ship a single portable executable.

Minimal example:

  1. Install Go 1.26+ (if you haven't already).

  2. Create a new project directory with the following main.go:

    package main
    
    import (
        "log"
    
        "github.com/hanzoai/base"
        "github.com/hanzoai/base/core"
    )
    
    func main() {
        app := base.New()
    
        app.OnServe().BindFunc(func(se *core.ServeEvent) error {
            // registers a new "GET /hello" route
            se.Router.GET("/hello", func(re *core.RequestEvent) error {
                return re.String(200, "Hello world!")
            })
    
            return se.Next()
        })
    
        if err := app.Start(); err != nil {
            log.Fatal(err)
        }
    }
    
  3. Initialize dependencies: go mod init myapp && go mod tidy.

  4. Start the app: go run main.go serve.

  5. Build a statically linked executable: CGO_ENABLED=0 go build, then start it with ./myapp serve.

See Extend with Go for details.

Building the repo example

To build the minimal standalone executable (like the prebuilt releases), run go build inside examples/base:

  1. Install Go 1.26+ (if you haven't already).
  2. Clone the repo.
  3. Navigate to examples/base.
  4. Run GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build (see the Go environment reference).
  5. Start the executable: ./base serve.

The pure-Go SQLite driver currently supports these build targets:

darwin  amd64      linux   arm64      linux   s390x
darwin  arm64      linux   loong64    windows 386
freebsd amd64      linux   ppc64le    windows amd64
freebsd arm64      linux   riscv64    windows arm64
linux   386        linux   arm
linux   amd64
Testing

Base comes with a mixed bag of unit and integration tests. Run them with the standard go test command:

go test ./...

See the Testing guide to learn how to write your own application tests.

SQLite replication

Base opens SQLite through the encrypted hanzoai/sqlite driver (per-principal CEK). The hanzoai/replicate sidecar streams WAL changes to object storage, encrypted end-to-end with luxfi/age.

K8s sidecar pattern:

  • Init container — restores the latest snapshot from object storage on startup.
  • Sidecar — continuously replicates the WAL while the service runs.

Configure age-identities / age-recipients for end-to-end encryption of replicated data.

Specs

Base implements:

  • HIP-0105 — In-Process Extension Runtime Standard
  • HIP-0107 — Streaming Replication over VFS
  • HIP-0302 — Encrypted SQLite + ZapDB Durability
  • HIP-0111 — Hanzo IAM (the one auth path)

It is the storage backend for every multi-tenant subsystem in HIP-0106.

Architecture

   http request  ->  zip.App  ->  base.App
                                     |
                  per-tenant data/{orgSlug}.db (SQLite or ZapDB)
                                     |
                  KMS-derived DEK   replicate -> S3 (age-encrypted)
                                     |
                  in-process extension runtime (HIP-0105):
                    goja (JS) | wazero (WASM) | pyvm (Python) | starkvm (Starlark)

CLI

The base cli subcommand is a complete HTTP client for operating any running Base-backed daemon from the command line. It works against base, atsd, brokerd, tad, bdd, or any binary that embeds Base.

Targeting a server
# Defaults to http://127.0.0.1:8090 if nothing is set
base cli --url http://localhost:8090 collection list

# Or use environment variables
export BASE_URL=http://localhost:8090
export BASE_TOKEN=eyJhbGciOi...
base cli collection list

Global flags (apply to all subcommands):

Flag Env var Default Description
--url BASE_URL http://127.0.0.1:8090 Server URL
--token BASE_TOKEN ~/.config/base/token Auth token
--tenant Sets X-Org-Id header
--format table on TTY, json otherwise table, json, or yaml
Authentication
# Login as a regular user
base cli login --email user@example.com --password secret123

# Login as superuser
base cli login --email admin@example.com --password secret123 --superuser

# Check who you are
base cli whoami

The token is stored at ~/.config/base/token (or $XDG_CONFIG_HOME/base/token) with mode 0600.

Collections
# List all collections
base cli collection list

# Show a specific collection's schema
base cli collection get users

# Export schema as JSON (always JSON, ignores --format)
base cli collection schema users > schema.json
Records
# List records with filtering and sorting
base cli record list posts --filter "title~'hello'" --limit 10 --sort "-created"

# Get a single record
base cli record get posts abc123

# Create a record
base cli record create posts '{"title":"Hello","body":"World"}'

# Update a record
base cli record update posts abc123 '{"title":"Updated"}'

# Delete a record
base cli record delete posts abc123
Crons
# List registered cron schedules
base cli crons list
Using from a downstream daemon

Any Base-backed daemon can expose these subcommands without duplicating code. For example, in a downstream main.go:

package main

import (
    "log"

    "github.com/hanzoai/base"
    "github.com/hanzoai/base/cmd"
)

func main() {
    app := base.New()

    // ... register domain-specific hooks and routes ...

    // Register system commands for a flattened CLI:
    // `ats collection list` instead of `ats cli collection list`
    app.RootCmd.AddCommand(cmd.NewSuperuserCommand(app))
    app.RootCmd.AddCommand(cmd.NewServeCommand(app, true))
    cmd.AddCLISubcommands(app.RootCmd)

    if err := app.Execute(); err != nil {
        log.Fatal(err)
    }
}

Then operate the running daemon:

ats collection list
ats record list trades --filter "status='settled'" --limit 20
ats crons list
ats daemon status
Registration patterns

Flattened (recommended for domain daemons) — commands at the root level:

app.RootCmd.AddCommand(cmd.NewSuperuserCommand(app))
app.RootCmd.AddCommand(cmd.NewServeCommand(app, true))
cmd.AddCLISubcommands(app.RootCmd)  // collection, record, login, whoami, crons, daemon
app.Execute()

Nested (default via app.Start()) — commands under a cli parent:

app.Start()  // registers serve, superuser, cli (with all subcommands)
// Access via: myapp cli collection list
Daemon lifecycle

The daemon subcommand manages the process lifecycle:

myapp daemon start              # local: nohup spawn
myapp daemon stop               # local: kill
myapp daemon status             # local: pgrep
myapp daemon logs --follow      # local: tail -f
myapp daemon restart            # local: stop + start

myapp daemon status --env dev              # K8s: kubectl get pods
myapp daemon restart --env test --yes      # K8s: rollout restart

K8s actions require --env (dev, test, main) and are dry-run by default. Pass --yes to execute.

Security

Report security vulnerabilities to security@hanzo.ai. All reports are addressed promptly, and you'll be credited in the fix release notes.

Contributing

Base is free and open source under the MIT License.

  • Open an issue for bugs and feature requests.
  • Read CONTRIBUTING.md before sending a PR.
  • For new features, open an issue to discuss the design first.

Bug fixes, optimizations, documentation improvements, and new OAuth2 providers are always welcome.

Hanzo — the Open AI Cloud

Open source · every language · on-chain settlement. hanzo.ai · docs.hanzo.ai

SDKs in every languagePython (flagship) · TypeScript · Go · Rust · C++ · Swift · Kotlin · umbrella

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "(untracked)"

Version of Base

Functions

This section is empty.

Types

type Base

type Base struct {
	core.App

	// RootCmd is the main console command
	RootCmd *cobra.Command
	// contains filtered or unexported fields
}

Base defines a Base app launcher.

It implements core.App via embedding and all of the app interface methods could be accessed directly through the instance (eg. Base.DataDir()).

func New

func New() *Base

New creates a new Base instance with the default configuration. Use NewWithConfig if you want to provide a custom configuration.

Note that the application will not be initialized/bootstrapped yet, aka. DB connections, migrations, app settings, etc. will not be accessible. Everything will be initialized when Base.Start is executed. If you want to initialize the application before calling Base.Start, then you'll have to manually call [Base.Bootstrap].

func NewWithConfig

func NewWithConfig(config Config) *Base

NewWithConfig creates a new Base instance with the provided config.

Note that the application will not be initialized/bootstrapped yet, aka. DB connections, migrations, app settings, etc. will not be accessible. Everything will be initialized when Base.Start is executed. If you want to initialize the application before calling Base.Start, then you'll have to manually call [Base.Bootstrap].

func (*Base) Execute

func (base *Base) Execute() error

Execute initializes the application (if not already) and executes the base.RootCmd with graceful shutdown support.

This method differs from base.Start() by not registering the default system commands!

func (*Base) Start

func (base *Base) Start() error

Start starts the application, aka. registers the default system commands (serve, cli) and executes base.RootCmd.

Superuser management lives in Hanzo IAM; there is no local-password management CLI to register.

type Config

type Config struct {
	// hide the default console server info on app startup
	HideStartBanner bool

	// optional default values for the console flags
	DefaultDev           bool
	DefaultDataDir       string // if not set, it will fallback to "./base_/data"
	DefaultEncryptionEnv string
	DefaultQueryTimeout  time.Duration // default to core.DefaultQueryTimeout (in seconds)

	// optional DB configurations
	DataMaxOpenConns int                // default to core.DefaultDataMaxOpenConns
	DataMaxIdleConns int                // default to core.DefaultDataMaxIdleConns
	AuxMaxOpenConns  int                // default to core.DefaultAuxMaxOpenConns
	AuxMaxIdleConns  int                // default to core.DefaultAuxMaxIdleConns
	DBConnect        core.DBConnectFunc // default to core.dbConnect
}

Config is the Base initialization config struct.

Directories

Path Synopsis
cmd
cli
typegen command
Command typegen generates TypeScript type definitions from a running Hanzo Base instance.
Command typegen generates TypeScript type definitions from a running Hanzo Base instance.
Package core is the backbone of Base.
Package core is the backbone of Base.
validators
Package validators implements some common custom Base validators.
Package validators implements some common custom Base validators.
examples
base command
Command pitr-restore reads archived WAL frames out of S3 or GCS and replays them into a fresh SQLite file for point-in-time recovery.
Command pitr-restore reads archived WAL frames out of S3 or GCS and replays them into a fresh SQLite file for point-in-time recovery.
Package iam is the canonical import path for Hanzo IAM client types and helpers.
Package iam is the canonical import path for Hanzo IAM client types and helpers.
Package mails implements various helper methods for sending common emails like forgotten password, verification, etc.
Package mails implements various helper methods for sending common emails like forgotten password, verification, etc.
Package network archive layer.
Package network archive layer.
plugins
bootnode
Package bootnode is the Go port of the Python bootnode backend (bootnode/api/), built natively on Hanzo Base as a plugin.
Package bootnode is the Go port of the Python bootnode backend (bootnode/api/), built natively on Hanzo Base as a plugin.
bootnode/auth
Package auth ports the bootnode authentication surface: the multi-network OAuth2 callback (lux-web3 shared client id) and bootnode-issued API keys.
Package auth ports the bootnode authentication surface: the multi-network OAuth2 callback (lux-web3 shared client id) and bootnode-issued API keys.
bootnode/kube
Package kube is a dependency-free Kubernetes REST client scoped to exactly what the bootnode plugin needs: server-side-apply of namespaced custom resources (bootno.de/v1 Network, NodeFleet, KMSSecret).
Package kube is a dependency-free Kubernetes REST client scoped to exactly what the bootnode plugin needs: server-side-apply of namespaced custom resources (bootno.de/v1 Network, NodeFleet, KMSSecret).
bootnode/models
Package models defines the Base collections backing the bootnode plugin.
Package models defines the Base collections backing the bootnode plugin.
bootnode/workers
Package workers ports the bootnode background workers.
Package workers ports the bootnode background workers.
calendar
Package calendar is the native Base + IAM booking backend that speaks Cal.com's API-v2 shapes, so a public booking page rendered with Cal's <Booker> atom talks straight to Base.
Package calendar is the native Base + IAM booking backend that speaks Cal.com's API-v2 shapes, so a public booking page rendered with Cal's <Booker> atom talks straight to Base.
cloudsql
Package cloudsql implements Hanzo Cloud SQL — a serverless PostgreSQL integration plugin for Hanzo Base.
Package cloudsql implements Hanzo Cloud SQL — a serverless PostgreSQL integration plugin for Hanzo Base.
commerce
Package commerce is a thin, typed Go client for the Hanzo Commerce HTTP API (Square-backed billing at commerce.hanzo.ai).
Package commerce is a thin, typed Go client for the Hanzo Commerce HTTP API (Square-backed billing at commerce.hanzo.ai).
extbench/fixtures/native-go
Package nativego is the native-Go extbench fixture.
Package nativego is the native-Go extbench fixture.
extruntime
Package extruntime defines the pluggable extension runtime interface used by Base's extension subsystem.
Package extruntime defines the pluggable extension runtime interface used by Base's extension subsystem.
functions
Package functions implements serverless function management for Hanzo Base via OpenFaaS. It provides per-tenant function deployment, invocation, and lifecycle management through the Base API surface.
Package functions implements serverless function management for Hanzo Base via OpenFaaS. It provides per-tenant function deployment, invocation, and lifecycle management through the Base API surface.
ghupdate
Package ghupdate implements a new command to selfupdate the current Base executable with the latest GitHub release.
Package ghupdate implements a new command to selfupdate the current Base executable with the latest GitHub release.
gojavm
Package gojavm adapts zip's embedded JavaScript runtime (github.com/zap-proto/zip/js) to base's extruntime.Runtime SPI, so a manifest with `"runtime": "goja"` loads here.
Package gojavm adapts zip's embedded JavaScript runtime (github.com/zap-proto/zip/js) to base's extruntime.Runtime SPI, so a manifest with `"runtime": "goja"` loads here.
ha
Package ha registers writer/replica HA for a Base app.
Package ha registers writer/replica HA for a Base app.
jsvm
Package jsvm implements pluggable utilities for binding a JS goja runtime to the Base instance (loading migrations, attaching to app hooks, etc.).
Package jsvm implements pluggable utilities for binding a JS goja runtime to the Base instance (loading migrations, attaching to app hooks, etc.).
migratecmd
Package migratecmd adds a new "migrate" command support to a Base instance.
Package migratecmd adds a new "migrate" command support to a Base instance.
platform
KMS bridge for the base/platform plugin.
KMS bridge for the base/platform plugin.
pyvm
Package pyvm is the CPython (cgo) extension runtime for Base.
Package pyvm is the CPython (cgo) extension runtime for Base.
replicate
Package replicate adds automatic SQLite WAL replication to Base apps.
Package replicate adds automatic SQLite WAL replication to Base apps.
scheduler
Package scheduler implements a scheduled function execution plugin for Base.
Package scheduler implements a scheduled function execution plugin for Base.
starkvm
Package starkvm wraps Google's go.starlark.net Starlark interpreter as an extruntime.Runtime.
Package starkvm wraps Google's go.starlark.net Starlark interpreter as an extruntime.Runtime.
tasks
Package tasks implements a durable task execution plugin for Base.
Package tasks implements a durable task execution plugin for Base.
v8vm
Package v8vm is the V8 (via cgo) extension runtime for Base.
Package v8vm is the V8 (via cgo) extension runtime for Base.
vault
Package vault provides per-user encrypted SQLite shards with CRDT sync and on-chain anchoring.
Package vault provides per-user encrypted SQLite shards with CRDT sync and on-chain anchoring.
waitlist
Package waitlist registers a viral, points-based waiting-list plugin on a Base app.
Package waitlist registers a viral, points-based waiting-list plugin on a Base app.
wasmvm
Package wasmvm implements the wazero-backed extension runtime for Base.
Package wasmvm implements the wazero-backed extension runtime for Base.
zap
Package zap provides a ZAP binary protocol transport for Hanzo Base.
Package zap provides a ZAP binary protocol transport for Hanzo Base.
sdk
go
Package store implements the canonical per-tenant SQLite storage model described in hanzo/ARCHITECTURE.md §5: a composable org / app / project / user isolation hierarchy (see the tenant-data-hierarchy HIP).
Package store implements the canonical per-tenant SQLite storage model described in hanzo/ARCHITECTURE.md §5: a composable org / app / project / user isolation hierarchy (see the tenant-data-hierarchy HIP).
encreplica
Package encreplica is a replicate.ReplicaClient that PQ-encrypts every LTX segment with a per-tenant age key BEFORE it touches durable storage, and decrypts on read — the SOLE at-rest boundary for the replica stream, using the SAME key as the whole-file path (store.TenantKey).
Package encreplica is a replicate.ReplicaClient that PQ-encrypts every LTX segment with a per-tenant age key BEFORE it touches durable storage, and decrypts on read — the SOLE at-rest boundary for the replica stream, using the SAME key as the whole-file path (store.TenantKey).
kmskeyring
Package kmskeyring binds store.RootSource to Hanzo KMS.
Package kmskeyring binds store.RootSource to Hanzo KMS.
replicator
Package replicator gives Base's per-tenant SQLite substrate continuous streaming replication and point-in-time restore via hanzoai/replicate — the HA / resilience layer (Pillar 2): a pod dying or rescheduling restores each tenant DB from its replica (bounded RPO, no data loss).
Package replicator gives Base's per-tenant SQLite substrate continuous streaming replication and point-in-time restore via hanzoai/replicate — the HA / resilience layer (Pillar 2): a pod dying or rescheduling restores each tenant DB from its replica (bounded RPO, no data loss).
Package tests provides common helpers and mocks used in Base application tests.
Package tests provides common helpers and mocks used in Base application tests.
tools
auth/internal/jwk
Package jwk implements some common utilities for interacting with JWKs (mostly used with OIDC providers).
Package jwk implements some common utilities for interacting with JWKs (mostly used with OIDC providers).
cache
Package cache provides caching primitives for Hanzo Base, built on github.com/luxfi/cache.
Package cache provides caching primitives for Hanzo Base, built on github.com/luxfi/cache.
claims
Package claims provides the canonical 3-header identity contract for every Base-derived service.
Package claims provides the canonical 3-header identity contract for every Base-derived service.
cron
Package cron is a thin alias over Hanzo Tasks (tools/tasks) kept for backward compatibility.
Package cron is a thin alias over Hanzo Tasks (tools/tasks) kept for backward compatibility.
filesystem/blob
Package blob defines a lightweight abstration for interacting with various storage services (local filesystem, S3, etc.).
Package blob defines a lightweight abstration for interacting with various storage services (local filesystem, S3, etc.).
filesystem/internal/fileblob
Package fileblob provides a blob.Bucket driver implementation.
Package fileblob provides a blob.Bucket driver implementation.
filesystem/internal/s3blob
Package s3blob provides a blob.Bucket S3 driver implementation.
Package s3blob provides a blob.Bucket S3 driver implementation.
filesystem/internal/s3blob/s3
Package s3 implements a lightweight client for interacting with the REST APIs of any S3 compatible service.
Package s3 implements a lightweight client for interacting with the REST APIs of any S3 compatible service.
filesystem/internal/s3blob/s3/tests
Package tests contains various tests helpers and utilities to assist with the S3 client testing.
Package tests contains various tests helpers and utilities to assist with the S3 client testing.
tasks
Package tasks provides a durable task client for Hanzo Tasks.
Package tasks provides a durable task client for Hanzo Tasks.
template
Package template is a thin wrapper around the standard html/template and text/template packages that implements a convenient registry to load and cache templates on the fly concurrently.
Package template is a thin wrapper around the standard html/template and text/template packages that implements a convenient registry to load and cache templates on the fly concurrently.
tokenizer
Package tokenizer implements a rudimentary tokens parser of buffered io.Reader while respecting quotes and parenthesis boundaries.
Package tokenizer implements a rudimentary tokens parser of buffered io.Reader while respecting quotes and parenthesis boundaries.
types
Package types implements some commonly used db serializable types like datetime, json, etc.
Package types implements some commonly used db serializable types like datetime, json, etc.
Package uireact embeds the Base admin bundle (React 19 + Vite, @hanzo/ui true-black design system).
Package uireact embeds the Base admin bundle (React 19 + Vite, @hanzo/ui true-black design system).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL