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 incore/ and example applications live in cmd/.
Directory Structure
The framework follows a modular, feature-based architecture:Package Organization
The Facade Pattern
Thecore/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
Thecore/server/ package contains the main Server struct that wraps PocketBase:
core/server/server.go
OpenAPI Documentation System
Thecore/server/api/ package implements automatic API documentation generation using Go AST parsing:
ast.go- Entry points for AST parsingast_func.go- Handler and function analysisast_struct.go- Struct and schema extractionast_metadata.go- Type and value resolutionregistry.go- Core registration logicregistry_routes.go- Route registrationregistry_spec.go- OpenAPI spec generationversion_manager.go- Multi-version API support
Feature Packages
Each feature package is self-contained:core/logging/- Structured logging with trace IDs and request middlewarecore/analytics/- Privacy-focused page view tracking with session managementcore/jobs/- Cron job management with structured logging and auto-cleanupcore/monitoring/- Real-time system metrics (CPU, memory, disk, network)
How pb-ext Wraps PocketBase
pb-ext enhances PocketBase without modifying its core. TheServer struct contains a PocketBase instance and extends its lifecycle:
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:Next Steps
Server Lifecycle
Learn about bootstrap, serve, and shutdown phases
Configuration
Explore server options and configuration patterns