base

package module
v1.5.98 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 15 Imported by: 8

README

Base

Base

Base is a backend in one Go binary: collections of records behind a REST API at /v1, with realtime updates, files, per-collection access rules and JavaScript hooks, stored in SQLite. Identity comes from Hanzo IAM, and with IAM on, each org's data lives in a database file of its own.

Run it

You need Go 1.26.8 or newer.

git clone --depth 1 https://github.com/hanzoai/base
cd base/examples/base
CGO_ENABLED=0 go build

Describe a collection in a migration. Base applies migrations when it starts.

mkdir -p base_/migrations
cat > base_/migrations/1_notes.js <<'EOF'
migrate((app) => {
  app.save(new Collection({
    type: "base",
    name: "notes",
    listRule: "",
    viewRule: "",
    createRule: "",
    fields: [{ name: "text", type: "text", required: true }],
  }))
})
EOF
./base serve --http 127.0.0.1:8090
Server started at http://127.0.0.1:8090
├─ REST API:  http://127.0.0.1:8090/v1/
└─ Dashboard: http://127.0.0.1:8090/

From a second terminal, create a record and list the collection:

curl -s -X POST http://127.0.0.1:8090/v1/collections/notes/records \
  -H 'Content-Type: application/json' -d '{"text":"hello"}'
{"collectionId":"hbc_3395098727","collectionName":"notes","id":"kbx358lmic2a4bw","text":"hello"}

curl -s http://127.0.0.1:8090/v1/collections/notes/records
{"items":[{"collectionId":"hbc_3395098727","collectionName":"notes","id":"kbx358lmic2a4bw","text":"hello"}],"page":1,"perPage":30,"totalItems":1,"totalPages":1}

The empty rules let anyone read and write notes; docs/rules.md shows how to close them. The data is in base_/data.

The startup output has two stale lines. The Dashboard address answers only when BASE_ENABLE_ADMIN_UI=1 is set, and the hint to run superuser upsert names a command that was removed. Superusers come from IAM.

Use it as a Go library

In an empty directory, save this as 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 {
		se.Router.GET("/hello", func(re *core.RequestEvent) error {
			return re.String(200, "Hello")
		})
		return se.Next()
	})

	if err := app.Start(); err != nil {
		log.Fatal(err)
	}
}
go mod init example.com/hello
go mod tidy
CGO_ENABLED=0 go build
./hello serve

GET http://127.0.0.1:8090/hello then answers Hello, next to the whole /v1 API.

Page For
docs/versions.md which tags serve what, and moving from /api and passwords to /v1 and IAM
docs/rules.md access rules, identity from IAM, orgs
docs/hooks.md JavaScript hooks and migrations
docs/config.md every command, flag and environment variable
docs/listeners.md every socket Base can open
docs/threat-model.md what Base defends, and what you configure
examples/hooks-hybrid-search full-text and vector search written as hooks

Clients

  • JavaScript and TypeScript: @hanzo/base. Give it the origin, as in new BaseClient('http://127.0.0.1:8090'); it adds /v1 itself.
  • Dart: hanzo-dart/base.

Contributing and security

CONTRIBUTING.md covers building and testing. Report vulnerabilities as SECURITY.md describes. Base is MIT licensed; see LICENSE.md.

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

	// DataDSN and AuxDSN name a server to open instead of the embedded file.
	// Empty is embedded SQLite, which is what `base serve` runs and what a
	// local Base is for.
	//
	// Whether an instance should live on a server, and which one, is a question
	// about a deployment rather than about Base, so it is asked here by whoever
	// is placing the instance — not read from this process's environment. A host
	// running many tenants answers it per tenant.
	DataDSN string
	AuxDSN  string
}

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 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.
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.
org
The wire base reaches Hanzo IAM on.
The wire base reaches Hanzo IAM on.
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-base SQLite storage model described in hanzo/ARCHITECTURE.md §5: a composable org / app / project / user isolation hierarchy (see the base-data-hierarchy HIP).
Package store implements the canonical per-base SQLite storage model described in hanzo/ARCHITECTURE.md §5: a composable org / app / project / user isolation hierarchy (see the base-data-hierarchy HIP).
encreplica
Package encreplica is a replicate.ReplicaClient that PQ-encrypts every LTX segment with a per-base 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.OrgKey).
Package encreplica is a replicate.ReplicaClient that PQ-encrypts every LTX segment with a per-base 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.OrgKey).
kmskeyring
Package kmskeyring binds store.RootSource to Hanzo KMS.
Package kmskeyring binds store.RootSource to Hanzo KMS.
replicator
Package replicator gives Base's per-base 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 base DB from its replica (bounded RPO, no data loss).
Package replicator gives Base's per-base 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 base 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
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