Skip to main content
PocketBase can be used as a Go framework, giving you complete control over the application lifecycle, custom commands, and direct access to all PocketBase internals.

Installation

First, create a new Go module and install PocketBase:

Basic example

Here’s a minimal example from examples/base/main.go:
main.go
This creates a PocketBase instance with default settings and starts the server.

Configuration

You can customize PocketBase’s configuration using NewWithConfig:
The application is bootstrapped automatically when you call app.Start(). Database connections, migrations, and settings are initialized at this point.

Application lifecycle

The PocketBase app follows this lifecycle:
1

Creation

Create a new PocketBase instance with New() or NewWithConfig().
2

Configuration

Register plugins, hooks, and custom commands before starting.
3

Bootstrap

The app bootstraps when Start() or Execute() is called. This initializes:
  • Database connections
  • Migrations
  • Application settings
  • Event hooks
4

Execution

The app executes the command (default is serve) and runs until terminated.
5

Termination

Graceful shutdown with cleanup via OnTerminate() hooks.

Custom commands

You can add custom CLI commands to your PocketBase app:
Run it with:

Working with the database

Accessing app settings

You can read and modify application settings:

Register plugins

PocketBase supports a plugin system for modular extensions:

Build and deployment

1

Build the binary

2

Run the application

3

Optional: Cross-compile

Always use CGO_ENABLED=0 when building PocketBase to ensure the binary is statically linked and portable.

Complete example

Here’s a complete example with multiple features:
main.go

Next steps

Event hooks

Learn about all available event hooks

Custom routes

Add custom API endpoints