Skip to main content
PocketBase is a Go framework that you can use as a standalone library in your Go application. You can leverage all of PocketBase’s features while maintaining full control over your application’s architecture.

Installation

Install PocketBase as a Go module:
go get github.com/pocketbase/pocketbase

Quick start

Create a basic PocketBase application:
main.go
package main

import (
    "log"
    "github.com/pocketbase/pocketbase"
)

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

    if err := app.Start(); err != nil {
        log.Fatal(err)
    }
}
Run your application:
go run main.go serve

Core concepts

App instance

The core.App interface is the backbone of PocketBase. It provides access to all core functionality including database operations, file storage, event hooks, and more.
app := pocketbase.New()

Event hooks

PocketBase uses an event-driven architecture. You can register hooks to execute custom logic at specific points:
app.OnRecordCreate().BindFunc(func(e *core.RecordEvent) error {
    // Your custom logic here
    return e.Next()
})

Collections and records

Collections define the schema for your data. Records are instances of collection data:
record := core.NewRecord(collection)
record.Set("name", "John Doe")
app.Save(record)

Configuration

Customize your PocketBase instance with configuration options:
app := pocketbase.NewWithConfig(pocketbase.Config{
    DefaultDataDir: "./pb_data",
    DefaultDev: true,
    HideStartBanner: false,
})

Configuration options

HideStartBanner
bool
Hide the default console server info on app startup.
DefaultDev
bool
Enable development mode (logs SQL statements to stderr).
DefaultDataDir
string
The data directory path (defaults to ./pb_data).
DefaultEncryptionEnv
string
Environment variable name for encryption key.
DefaultQueryTimeout
time.Duration
Default timeout for database queries.

Running the application

Start method

The Start() method registers default system commands and executes the root command:
if err := app.Start(); err != nil {
    log.Fatal(err)
}

Bootstrap

Manually initialize the application before starting:
if err := app.Bootstrap(); err != nil {
    log.Fatal(err)
}

// Your custom initialization code here

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

Custom commands

Add custom CLI commands to your application:
app.RootCmd.AddCommand(&cobra.Command{
    Use: "hello",
    Run: func(cmd *cobra.Command, args []string) {
        log.Println("Hello, PocketBase!")
    },
})

Next steps

App interface

Learn about the core App interface and its methods

Collections

Work with collections and schema definitions

Records

Create, read, update, and delete records

Events

Register event hooks for custom logic