Skip to content

ionutale/pocketbase

 
 

Repository files navigation

PocketBase - open source backend in 1 file

build Latest releases Go package documentation

PocketBase is an open source Go backend that includes:

  • embedded database (SQLite) with realtime subscriptions
  • built-in files and users management
  • convenient Admin dashboard UI
  • and simple REST-ish API

For documentation and examples, please visit https://pocketbase.io/docs.

Warning

Please keep in mind that PocketBase is still under active development and therefore full backward compatibility is not guaranteed before reaching v1.0.0.

Developers: looking for repo-specific build/run details? See the local guide: agents.md.

API SDK clients

The easiest way to interact with the PocketBase Web APIs is to use one of the official SDK clients:

You could also check the recommendations in https://pocketbase.io/docs/how-to-use/.

Overview

Use as standalone app

You could download the prebuilt executable for your platform from the Releases page. Once downloaded, extract the archive and run ./pocketbase serve in the extracted directory.

The prebuilt executables are based on the examples/base/main.go file and comes with the JS VM plugin enabled by default which allows to extend PocketBase with JavaScript (for more details please refer to Extend with JavaScript).

Expand all relations (default)

By default the server will automatically expand all relation fields (recursively) in API responses.

To explicitly disable this behavior when running the serve command, pass --no-expand-all:

./pocketbase serve --no-expand-all

Notes:

  • This expands declared direct relation fields iteratively without a fixed depth limit; cycles are guarded.
  • Access rules and field visibility still apply; unauthorized relations won't be expanded.
  • Use with caution on large graphs, as responses can become heavy.

OpenAPI (Swagger)

PocketBase exposes a basic OpenAPI 3.0 spec generated from the registered routes:

  • JSON: GET /openapi/json
  • YAML: GET /openapi/yaml
  • HTML viewer (Swagger UI): GET /openapi/html

Notes:

  • Purpose: discover available endpoints programmatically or load into tools (Swagger UI, Redoc, etc.).
  • Scope: the spec lists paths and methods. Schemas/parameters are minimal, intended as a starting point.

Examples:

curl http://localhost:8090/openapi/json | jq
curl http://localhost:8090/openapi/yaml
open http://localhost:8090/openapi/html

Use as a Go framework/toolkit

PocketBase is distributed as a regular Go library package which allows you to build your own custom app specific business logic and still have a single portable executable at the end.

Here is a minimal example:

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

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

    package main
    
    import (
        "log"
    
        "github.com/pocketbase/pocketbase"
        "github.com/pocketbase/pocketbase/core"
    )
    
    func main() {
        app := pocketbase.New()
    
        app.OnServe().BindFunc(func(se *core.ServeEvent) error {
            // registers 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. To init the dependencies, run go mod init myapp && go mod tidy.

  4. To start the application, run go run main.go serve.

  5. To build a statically linked executable, you can run CGO_ENABLED=0 go build and then start the created executable with ./myapp serve.

For more details please refer to Extend with Go.

Building and running the repo main.go example

To build the minimal standalone executable, like the prebuilt ones in the releases page, you can simply run go build inside the examples/base directory:

  1. Install Go 1.23+ (if you haven't already)
  2. Clone/download the repo
  3. Navigate to examples/base
  4. Run GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build (https://go.dev/doc/install/source#environment)
  5. Start the created executable by running ./base serve.

Note that the supported build targets by the pure Go SQLite driver at the moment are:

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

Testing

PocketBase comes with mixed bag of unit and integration tests. To run them, use the standard go test command:

go test ./...

Check also the Testing guide to learn how to write your own custom application tests.

Security

Releasing

To create a new GitHub release that produces the prebuilt executables, tag the repository with a SemVer tag prefixed with v (for example v0.1.0). The repository contains a GitHub Action that runs GoReleaser and will use the tag value as the injected Version (see .goreleaser.yaml).

Recommended steps:

  1. Run the test suite and any checks locally first:
go test ./...
  1. Create an annotated tag and push it to your GitHub fork/remote:
# create an annotated tag
git tag -a v0.1.0 -m "v0.1.0"

# push the tag to the origin (or your fork remote)
git push origin v0.1.0
  1. After the tag is pushed, the release workflow (.github/workflows/release.yaml) will run and trigger GoReleaser. By default .goreleaser.yaml uses release.draft: true, so GoReleaser will create a draft release for you. You can publish it manually from the Releases page, or change release.draft to false in .goreleaser.yaml to auto-publish.

Notes & tips:

  • The GoReleaser action observes tags beginning with v. The tag value is injected into the binary via the -ldflags "-X github.com/pocketbase/pocketbase.Version={{ .Version }}" setting in .goreleaser.yaml.
  • If you want a pre-release, use a tag like v1.2.3-rc.1 and GoReleaser will preserve the pre-release semantics.
  • The action builds the admin UI (ui folder) to ensure deterministic artifacts; make sure any generated frontend assets are committed or that the action can build them.

Local alternative (no tag):

If you want to build locally with a specific version without creating a tag, set the Version via -ldflags:

go build -ldflags "-s -w -X github.com/pocketbase/pocketbase.Version=v0.1.0" -o pocketbase ./examples/base

After building, verify the version:

./pocketbase --version

If you discover a security vulnerability within PocketBase, please send an e-mail to support at pocketbase.io.

All reports will be promptly addressed and you'll be credited in the fix release notes.

Contributing

PocketBase is free and open source project licensed under the MIT License. You are free to do whatever you want with it, even offering it as a paid service.

You could help continuing its development by:

PRs for new OAuth2 providers, bug fixes, code optimizations and documentation improvements are more than welcome.

But please refrain creating PRs for new features without previously discussing the implementation details. PocketBase has a roadmap and I try to work on issues in specific order and such PRs often come in out of nowhere and skew all initial planning with tedious back-and-forth communication.

Don't get upset if I close your PR, even if it is well executed and tested. This doesn't mean that it will never be merged. Later we can always refer to it and/or take pieces of your implementation when the time comes to work on the issue (don't worry you'll be credited in the release notes).

About

Open Source realtime backend in 1 file

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 71.5%
  • Svelte 16.8%
  • SCSS 6.2%
  • CSS 3.1%
  • JavaScript 2.3%
  • HTML 0.1%