Skip to main content

Overview

pb-ext is a Go library that wraps PocketBase with production-ready features. It follows a clean architectural pattern where the library code lives in core/ and example applications live in cmd/.

Directory Structure

The framework follows a modular, feature-based architecture:

Package Organization

The Facade Pattern

The core/core.go file acts as a public facade that re-exports components from internal packages. This provides a clean, stable API for users:
core/core.go
Users import github.com/magooney-loon/pb-ext/core and get access to all necessary components through this single import.

Core Server Package

The core/server/ package contains the main Server struct that wraps PocketBase:
core/server/server.go

OpenAPI Documentation System

The core/server/api/ package implements automatic API documentation generation using Go AST parsing:
  • ast.go - Entry points for AST parsing
  • ast_func.go - Handler and function analysis
  • ast_struct.go - Struct and schema extraction
  • ast_metadata.go - Type and value resolution
  • registry.go - Core registration logic
  • registry_routes.go - Route registration
  • registry_spec.go - OpenAPI spec generation
  • version_manager.go - Multi-version API support

Feature Packages

Each feature package is self-contained:
  • core/logging/ - Structured logging with trace IDs and request middleware
  • core/analytics/ - Privacy-focused page view tracking with session management
  • core/jobs/ - Cron job management with structured logging and auto-cleanup
  • core/monitoring/ - Real-time system metrics (CPU, memory, disk, network)

How pb-ext Wraps PocketBase

pb-ext enhances PocketBase without modifying its core. The Server struct contains a PocketBase instance and extends its lifecycle:
You can pass your own PocketBase instance using WithPocketbase() or customize the config with WithConfig().

Extension Points and Hooks

pb-ext integrates into PocketBase’s lifecycle using hooks:

OnBootstrap Hook

Initializes infrastructure before the server starts:
core/server/server.go

OnServe Hook

Registers routes and middleware when the server starts:
core/server/server.go

User Hooks

Users extend the server in their application code:
cmd/server/main.go

Design Principles

Separation of Concerns

Library code (core/) is completely separate from example apps (cmd/)

Functional Options

Configuration uses the functional options pattern for flexibility

Hook-Based

Extensions use PocketBase’s hook system rather than forking

Self-Contained

Each feature package manages its own collections, routes, and logic

Module Path

The Go module path is:
Import the framework with:

Next Steps

Server Lifecycle

Learn about bootstrap, serve, and shutdown phases

Configuration

Explore server options and configuration patterns