Skip to main content
This guide will walk you through creating a minimal pb-ext application from scratch. By the end, you’ll have a running server with monitoring, logging, and API documentation.

Prerequisites

1

Install Go

pb-ext requires Go 1.25.7 or higher.
If you need to install or upgrade Go, visit golang.org/dl.
2

Verify Installation

Ensure Go is properly installed and in your PATH:

Create Your First pb-ext Project

1

Create Project Directory

2

Initialize Go Module

This creates a go.mod file that tracks your dependencies.
3

Create Main Application File

Create the directory structure and main file:
Create cmd/server/main.go with the following content:
cmd/server/main.go
This is the exact structure from cmd/server/main.go in the pb-ext repository. The file location matters: pb-cli expects your entry point at cmd/server/main.go.
4

Download Dependencies

This downloads pb-ext and all its dependencies (PocketBase, gopsutil, etc.).
5

Install pb-cli Toolchain

The pb-cli toolchain automates building, running, and deploying pb-ext applications.
Make sure your $GOPATH/bin or $HOME/go/bin is in your PATH. If pb-cli is not found, add this to your shell profile:
6

Run Your Server

You should see output similar to:
The --run-only flag skips frontend building (useful when you don’t have a frontend yet).

Access Your Application

PocketBase Admin Panel

Open http://127.0.0.1:8090/_Create your first admin account to access the PocketBase admin UI.

pb-ext Dashboard

Open http://127.0.0.1:8090//View system metrics, analytics, and cron job logs (requires admin auth).

Add Your First API Endpoint

Let’s add a simple API endpoint to see how pb-ext auto-generates documentation.
1

Create Routes File

Create cmd/server/routes.go:
cmd/server/routes.go
The // API_SOURCE comment at the top tells pb-ext to parse this file for OpenAPI metadata. The API_DESC and API_TAGS directives add documentation to your endpoint.
2

Restart the Server

Stop the server (Ctrl+C) and restart it:
3

Test Your Endpoint

Expected response:
4

View Auto-Generated Docs

Open http://127.0.0.1:8090/api/docs/v1/swaggerYou’ll see a Swagger UI with your /api/v1/time endpoint fully documented, including the response schema automatically inferred from your code.

Add a Cron Job

Let’s schedule a background task that runs every minute.
1

Create Jobs File

Create cmd/server/jobs.go:
cmd/server/jobs.go
2

Restart and View Job Logs

Restart the server:
After waiting 1 minute, check the dashboard at http://127.0.0.1:8090// to see your job execution logs.

Add a Database Collection

Let’s create a simple “todos” collection.
1

Create Collections File

Create cmd/server/collections.go:
cmd/server/collections.go
2

Restart Server

The “todos” collection will be automatically created on startup.
3

Test CRUD Operations

Create a todo:
List todos:

Project Structure

Your project should now look like this:
You can restructure your project however you like, but cmd/server/main.go is the conventional entry point expected by pb-cli.

Next Steps

Learn API Documentation

Master the AST-based OpenAPI system with versioning and parameter inference

Explore Cron Jobs

Deep dive into job scheduling, logging, and the management API

Setup Frontend

Build a SvelteKit frontend with the pb-cli toolchain

Deploy to Production

Use pb-deployer for automated VPS deployment

Troubleshooting

Make sure $GOPATH/bin is in your PATH:
Add this to your .bashrc or .zshrc to make it permanent.
Change the port by passing flags to the server:
Or set it programmatically in main.go:
Run go mod tidy to ensure all dependencies are downloaded:
The dashboard requires admin authentication. Make sure you:
  1. Created an admin account at /_/
  2. Logged in before accessing /_/_

Example Project

Want to see a complete working example? The pb-ext repository includes a full example server in cmd/server/ with:
  • Multiple API versions (v1, v2)
  • CRUD routes with OpenAPI docs
  • Cron jobs with logging
  • Collection definitions
  • Request middleware
Clone the repository to explore: