phibac developer docs

One backend, many apps

phibac gives each user (the person whose data it is) one private database on the server, and lets the apps that user approves (web apps that developers build) share it. As a developer you write only the front end, the part of the app that runs in the user's browser. This page explains how the pieces fit together.

One private database per user

A user is the person whose data it is. Each user who signs up on this server (https://phibac.com) has their own database, kept in a file of its own on the server. Every record (one saved item, such as one note) that any app saves for that user goes into that database.

Users never share a database. An app that one user signs in to can reach only that user's data: it cannot see what other users have saved, even in the same app.

Apps share the user's database

An app is a web app a developer builds: static files (HTML, JavaScript, CSS) served from a web address the developer registers. One user can use many apps, and every app they approve saves into the same database, theirs.

For example, Ana uses a journal app and a habits app, and Ben uses a notes app:

In Ana's browser                       On the server
  Journal app --+
                +------------------>   Ana's database
  Habits app  --+                        collection: journal entries  (owned by Journal)
                                         collection: habit check-ins  (owned by Habits)

In Ben's browser
  Notes app   --------------------->   Ben's database
                                         collection: notes            (owned by Notes)

Each app owns the collections it defines. A collection is one kind of data, such as journal entries or habit check-ins, and holds that kind's records. The owning app may read and change its collections freely. Another app may only read them, and only after the user gives consent (says yes when asked): the Habits app could show journal entries next to check-ins, but it could never change or delete them. Users, sign-in and consent explains how the user is asked.

Because the data belongs to the user and not to an app, a user can see all of it, restore earlier versions and export it from their account page on the server, whatever app saved it.

What you write and what the server does

Part Who provides it What it does
Your web app You The pages users see. It reads and saves data with the SDK, described below.
pb.config.ts You Describes your app's collections and their fields. You publish it with phibac deploy, a command of the CLI (the command-line tool you run in a terminal).
The SDK (@phibac/sdk) phibac A JavaScript library your page uses. It signs the user in, keeps a copy of their data in the browser, holds writes while the device is offline and delivers live updates (it tells your page when data changes, including changes made on another device).
The server phibac Signs users in, with passkeys (keys kept on the user's device) or passwords, stores each user's database, checks every record against the fields you described (except in sandbox collections, which your app keeps for itself and the server does not check), asks the user for consent, keeps the history of every change and sends live updates.

You do not write server code, SQL or a sign-in system, and you never handle passwords. Collections and records explains how data is described and stored, and Offline writes and sync what the SDK does when the network is gone.

How an app reaches the data

  1. The user presses Sign in in your app. Your code calls connect(), which opens a sign-in popup on the server.
  2. In the popup the user signs in, with a passkey or a password, if they are not signed in to the server already, and approves your app the first time.
  3. The popup closes. The SDK now holds a sign-in that only works from this browser, tied to a key kept in the browser.
  4. Your app reads and saves records through the SDK. The server accepts the requests only from the origins registered for your app, and from http://localhost while you develop. An origin is the first part of a web address: https or http, the host name and the port, such as https://notes.example.com.

Developer tools work differently. The CLI, and the tools an AI coding assistant uses, work with a developer token: a secret key that creates and changes your apps and the descriptions of their data. A developer token can never read, write, export or delete any user's data: only an app running in the user's browser, after the user signs in and approves it, reaches user data.

Who pays

This server does not charge anyone. It has no plans or payments: every account can connect apps, save data and publish collections without paying.