W14: An App with No Server at All

A restaurant needs a kitchen, staff, and someone to open the doors every morning. A cookbook needs none of that: you buy it once and cook at home, even when the shops are shut. Many apps are cookbooks. An app with no server runs entirely in the visitor's browser, and there is nothing for you to keep running.

The One Question

Before building, ask one question:

Does more than one person need the same data when they are not online together, or does the app need a secret (a paid API key, a password check, payments)?

Some examples:

App Answer Why
A personal habit tracker No server Only you, on your phone
A game for two friends playing together No server They are online at the same time (see below)
A shop inventory for three staff Server Different people, different times, same data
A chat with an AI using your paid key Server The key is a secret

The question decides, not taste.

What You Gain

What You Lose

Be honest about it before you choose:

Where the Data Lives: IndexedDB

Without a server, data goes into the browser's own small database, IndexedDB, which keeps it on the device between visits. T14: Persistence shows its simpler cousin, localStorage.

Sharing Live, with No Server of Yours

People can share live without your server, as long as they are online at the same time. The kit includes p2p-core, the library the AI course's game uses (A12: Other People). Browsers connect straight to each other: two tabs, the same Wi-Fi, anyone online through public relays, or a pairing code with no internet. It starts like this:

import { joinRoom } from './vendor/p2p-core/p2p-core.js';
const room = joinRoom({ app: 'my-game', profile: { name } });
room.onMessage('move', (data, from) => { /* check data, then use it */ });

A12 explains the catch: browsers still need a public noticeboard to find each other, and some networks block direct connections. It fits games and classroom activities, not an inventory that must survive while everyone is away.

The No-Server Stack

One way again, as plain as possible:

// @ts-check

/**
 * @param {string} title
 * @returns {string}
 */
export function cleanTitle(title) {
  return title.split(/\s+/).filter(Boolean).join(" ");
}

With // @ts-check at the top, the checker warns when you pass a number by mistake, like pyright does.

Building One Today

There is a second starter for this, the same notes app with no server. From the pi-local-harness folder, as in W04:

python3 kit/new_project.py --static ~/Projects/habits

Its README lists the commands: one checks the types, one runs the tests, one builds the CSS, and this one serves the folder as plain files:

python3 -m http.server 8000

Open http://127.0.0.1:8000. Then, as in W04: Add Existing Folder…, Create Roadmap, and a first git commit (W11). The rules live in js/logic/, the IndexedDB code in js/store.mjs, the page in index.html and js/app.mjs. Ask Pi to turn it into your app:

"Turn these notes into a habit tracker: a habit has a name and the days I did it. Keep the rules in js/logic/ with tests, and keep the export button for backups."

When it works, put it on GitHub (W12) as a public repository and switch on Pages.

Pi Workbench will do this step for you soon: it will ask the one question when a project starts, and offer this starter when the answer is "no".

This Week's Exercise

  1. List five apps you would like to build. Answer the one question for each.
  2. Read A12's "There is no server, and that is a half-truth".
  3. Build the habit tracker with the request above, and test it offline.
  4. Publish it on GitHub Pages and open it on your phone.

Key Takeaways

  • One question decides: shared data between people who are not online together, or a secret? Then a server. Otherwise, none
  • No server means free GitHub Pages hosting, full offline, nothing to keep running
  • It also means data on one device (backups are exports), no secrets in the page, no sharing with people who are offline
  • p2p-core lets people share live with no server of yours, when they are online together
  • The no-server stack: plain JavaScript modules with JSDoc types checked by TypeScript, Basecoat, pure tested logic, a service worker