Skip to content

Backend (Pocketbase)

We use pb_hooks to implement several backend features. These features have been (mostly) broken up into their own files.

Important features and their related files:

Geofencing

./pb/pb/pb_hooks/coords.pb.js Recieves GPS positions and geofencing logic

Database Hooks

./pb/pb_hooks/model-hooks.pb.ts Contains hooks for database operations and model interactions.

Custom API Routes

./pb/pb_hooks/routes.pb.ts Defines custom API routes for specific backend functionalities.

Custom CLI Commands

./pb/pb_hooks/metrics.pb.js Implements custom CLI commands for backend operations.

Public Pre-made Queries

./pb/pb_hooks/query.pb.js Provides pre-made queries for public use cases.

You can add a custom template that is served directly by pocketbase and used pocketbases built-in template renderer with some variables fed in by default.

You can add templates in the ./pb/view folder and add variables for populating the templates in ./pb/pb_hooks/view.pb.ts

We use LiteStream to replicate the production database into our dev environments.

Populate the LiteStream Environment variables listed in .env.example (Prefaced with LS_ ) in your .env file.

To trigger the replication (assuming you are at the root of the project):

  1. Run docker compose down
  2. Delete pb_data/*.db (ex. rm -rf pb/pb_data/data.*)
  3. Run docker compose up -d

When the container starts up it will detect the lack of a database and use LiteStream to replicate it from the env variables specified.