PitchHut logo
A streamlined boilerplate for PocketBase with monitoring and logging features.
Pitch

pb-ext provides an enhanced PocketBase server experience by integrating crucial features like API schema auto-generation, cron job tracking, and real-time system monitoring. Effortlessly manage your applications with structured logging and visitor analytics, all while utilizing PocketBase's powerful authentication. Perfect for developers looking to streamline their workflow.

Description

pb-ext - Enhanced PocketBase Server

The pb-ext project offers an advanced PocketBase server solution with enhanced features including monitoring, logging, and auto-generated API documentation. This tool is designed for developers looking to streamline their development processes while ensuring robust performance and security.

Core Features

  • Automatic API Documentation: Quickly generates OpenAPI documentation UI for all endpoints, enabling efficient interaction and integration with APIs.
  • Cron Job Monitoring: Logs and monitors scheduled tasks, providing insights into execution times and outcomes.
  • Real-time System Metrics: Track vital statistics such as CPU usage, memory consumption, disk space, network activity, and runtime metrics to ensure optimal server performance.
  • Structured Logging: Advanced logging capabilities include detailed error tracking and request tracing for enhanced troubleshooting.
  • Visitor Analytics: GDPR-compliant analytics to monitor visitor interactions, including page views, device types, and browser data.
  • Seamless PocketBase Integration: Utilizes PocketBase's user authentication and styling for a cohesive application experience.

Access Endpoints

  • Admin Panel: Accessible at 127.0.0.1:8090/_
  • pb-ext Dashboard: Accessible at 127.0.0.1:8090/_/_

Quick Start Example

Getting started with pb-ext is straightforward. Below is a simple example of how to initialize the application:

package main

import (
	"flag"
	"log"
	app "github.com/magooney-loon/pb-ext/core"
	"github.com/pocketbase/pocketbase/core"
)

func main() {
	devMode := flag.Bool("dev", false, "Run in developer mode")
	flag.Parse()

	initApp(*devMode)
}

func initApp(devMode bool) {
	var opts []app.Option

	if devMode {
		opts = append(opts, app.InDeveloperMode())
	} else {
		opts = append(opts, app.InNormalMode())
	}

	srv := app.New(opts...)

	app.SetupLogging(srv)

	registerCollections(srv.App())
	registerRoutes(srv.App())
	registerJobs(srv.App())

	srv.App().OnServe().BindFunc(func(e *core.ServeEvent) error {
		app.SetupRecovery(srv.App(), e)
		return e.Next()
	})

	if err := srv.Start(); err != nil {
		srv.App().Logger().Error("Fatal application error",
			"error", err,
			"uptime", srv.Stats().StartTime,
			"total_requests", srv.Stats().TotalRequests.Load(),
			"active_connections", srv.Stats().ActiveConnections.Load(),
			"last_request_time", srv.Stats().LastRequestTime.Load(),
		)
		log.Fatal(err)
	}
}

Reserved Collections

During startup, pb-ext automatically creates system collections within PocketBase. These collections are integral for functionality and should not be manually created:

CollectionPurpose
_analyticsStores daily aggregated page view counts, retaining data for 90 days.
_analytics_sessionsMaintains a buffer for the most recent visits. No personal information is stored.
_job_logsContains logs for cron job executions for 72 hours.

Reserved Routes

pb-ext comes with predefined routes that facilitate smooth operation. Custom routes should not overlap with these:

  • Dashboard Route: Access health, analytics, and jobs dashboard via GET /_/_

  • Cron Job API Routes: Manage cron jobs and retrieve their statuses with dedicated endpoints for listing, running, and logging jobs.

For those looking to enhance their development experience with PocketBase, pb-ext stands as a comprehensive solution, providing the necessary tools for effective project management and monitoring.

0 comments

No comments yet.

Sign in to be the first to comment.