Prerequisites
1
Install Go
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
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
5
Install pb-cli Toolchain
pb-cli toolchain automates building, running, and deploying pb-ext applications.6
Run Your Server
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
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
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
pb-cli: command not found
pb-cli: command not found
Make sure Add this to your
$GOPATH/bin is in your PATH:.bashrc or .zshrc to make it permanent.Port 8090 already in use
Port 8090 already in use
Change the port by passing flags to the server:Or set it programmatically in
main.go:Module not found errors
Module not found errors
Run
go mod tidy to ensure all dependencies are downloaded:Dashboard shows no data
Dashboard shows no data
The dashboard requires admin authentication. Make sure you:
- Created an admin account at
/_/ - Logged in before accessing
/_/_
Example Project
Want to see a complete working example? The pb-ext repository includes a full example server incmd/server/ with:
- Multiple API versions (v1, v2)
- CRUD routes with OpenAPI docs
- Cron jobs with logging
- Collection definitions
- Request middleware