Hosting OsaBooks online yourself

OsaBooks runs happily on your own computer with no server at all. This guide is for the other way: books kept online, reachable from any browser, shared with your bookkeeper or accountant — on your own Supabase project and your own web hosting, so nobody else holds your books.

It is written to be worked through by a person, or by a person together with their own AI assistant (Claude, ChatGPT, Gemini, or similar). The steps say who does what: some things only you should do — creating accounts, typing passwords, pasting secret keys — and the AI should hand those back to you. There is a short section at the end for the AI itself.

Time: an hour or two the first time. Cost: Supabase's free tier and most web hosting are enough for one business's books.


1. What you end up with

PieceWhat it doesWhere it lives
The web appThe OsaBooks pages: plain files, no server of their ownYour web host (any static hosting)
Supabase: databaseYour books, members and roles, locked down by row-level securityYour Supabase project
Supabase: authSign-in with email and password, and the confirmation emailYour Supabase project
Supabase: VaultBank feed tokens, the Wise token, AI keys — encrypted, never readable by a browserYour Supabase project
Supabase: Edge Functionsakahu (bank feed), wise (Wise), gemini (AI suggestions), gemini-demo (an optional shared AI allowance)Your Supabase project
Email (optional)Sends sign-up confirmations from your own addressYour email provider's SMTP

The only keys that ever reach a browser are the Supabase project URL and publishable key. Both are public by design: they identify the project and carry no rights of their own. Everything else — the service role key, bank tokens, API keys — stays inside Supabase.


2. Before you start

You need:

Keep secrets out of chat and out of files you might share. If you work with an AI, keep secrets in environment variables on your computer and let the AI refer to them by name (section 10).


3. Create the Supabase project

You do this, in the Supabase dashboard.

  1. New project. Choose a region near you — Sydney (ap-southeast-2) for New Zealand — and a strong database password (keep it in your password manager; OsaBooks never needs it).
  2. From Project Settings → API, note: - the Project URL (https://<your-ref>.supabase.co) and project ref (<your-ref>); - the publishable key (sb_publishable_…) — public; - the service role / secret key — secret. You will not paste this anywhere in OsaBooks; the Edge Functions get it from Supabase automatically.
  3. From Account → Access Tokens, create a personal access token if you want to run the steps below from the command line (or let an AI run them). Store it as an environment variable, e.g. SUPABASE_ACCESS_TOKEN.

4. Set up the database

The database is built by the files in supabase/migrations/, run in the order of their names (they start with a date). Each one is plain SQL.

Option A — the dashboard (no tools needed). Open SQL Editor, and for each file in supabase/migrations/, oldest first, paste its contents and run it.

Option B — the Supabase CLI.

npx supabase link --project-ref <your-ref>
npx supabase db push

Check it worked. Run this in the SQL Editor. Every line should say what the comment beside it says:

select
  (select count(*) from information_schema.tables
     where table_schema = 'public'
       and table_name in ('books','book_members','book_parts','bank_feeds','wise_feeds','ai_secrets'))
    as tables_expected_6,
  (select bool_and(relrowsecurity) from pg_class
     where relname in ('books','book_parts','bank_feeds','wise_feeds'))
    as row_security_on_expected_true,
  has_function_privilege('authenticated', 'public.feed_secrets(uuid)', 'execute')
    as users_can_read_bank_tokens_expected_false,
  has_function_privilege('authenticated', 'public.wise_secret(uuid)', 'execute')
    as users_can_read_wise_token_expected_false;

If the last two say true, stop: something went wrong and tokens would be readable by signed-in users. Re-run the migrations in order.


5. Deploy the Edge Functions

Four functions, in supabase/functions/. With the CLI (Docker is not needed with --use-api):

npx supabase functions deploy akahu --use-api --project-ref <your-ref>
npx supabase functions deploy wise --use-api --project-ref <your-ref>
npx supabase functions deploy stripe --use-api --project-ref <your-ref>
npx supabase functions deploy gemini --use-api --project-ref <your-ref>
npx supabase functions deploy gemini-demo --use-api --project-ref <your-ref>

SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY are given to every function by Supabase itself — you set nothing for them.

Optional: payment reminders sent by themselves. Books with reminders turned on in Settings are sent them each morning at 21:00 UTC (the *_reminders.sql migration schedules it, with the morning run's key). Build the run, then deploy:

node tools/build-nightly-function.mjs
npx supabase functions deploy reminders --no-verify-jwt --use-api --project-ref <your-ref>

It sends through the same SMTP secrets as the invitations (SMTP_HOST, SMTP_USER, SMTP_PASSWORD), from SMTP_USER's address. To send through Resend instead, set RESEND_API_KEY and REMINDERS_FROM (an address on a domain verified with Resend). Each email comes in the business's name, with replies to the business's own email; at most 50 go from one set of books in a morning.

Optional: a shared AI allowance. If you want people using your copy to try AI suggestions before they add a key of their own, set a Gemini API key as a function secret (Edge Functions → Secrets, or the CLI):

npx supabase secrets set GEMINI_API_KEY=<your key> --project-ref <your-ref>

GEMINI_MODEL is optional (a current Flash model is the default). The allowance is one pool shared by everybody without a key, capped at 1,000 lines by default; change the cap in the ai_demo_pool table. Leave the key unset and there is simply no shared allowance — everybody uses their own key or copies prompts to an AI they already have.

Check it worked. A request with no sign-in should be refused, which proves the function is there and checking:

curl -s -X POST https://<your-ref>.supabase.co/functions/v1/wise -H "apikey: <publishable key>" -H "content-type: application/json" -d "{\"action\":\"status\",\"book\":\"x\"}"

It should answer not signed in (or a 401).


6. Sign-in settings

In the dashboard, Authentication.

  1. URL Configuration. Set Site URL to where the app will live, e.g. https://books.example.co.nz/, and add the same under Redirect URLs. The confirmation email links back here.
  2. Email. Keep Confirm email on. It is not only tidiness: an invitation to a set of books is matched on the email address in the person's sign-in, so with it off anybody could sign up as an address they do not own and accept that address's invitations. Check it is on before inviting anyone.
  3. SMTP (optional, recommended). Under SMTP Settings, enter your email provider's host, port (465 or 587), username and password, and the sender address. Two traps: the host name must match the server's certificate (your provider's own server name, which is not always mail.yourdomain), and if you set these through the Management API, send all the SMTP fields together and the port as text.

7. Point the web app at your project

Edit apps/web/src/cloud-config.ts and put in your two public values:

export const CLOUD: CloudProject = {
  url: "https://<your-ref>.supabase.co",
  publishableKey: "sb_publishable_<yours>",
};

Then build:

npm install
npm run build --workspace @nzosa/web

The finished app is in apps/web/dist/.

Leaving both values empty builds an app with no online option at all — books on the computer or in the browser only.


8. Put the app on your web host

Upload everything in apps/web/dist/, including the hidden .htaccess file, to the folder your site serves — for example public_html/books/.

Check it worked. Open the address. Books online should offer Sign in. Create your account, confirm it from the email, and sign in.


9. Your first books online

  1. Books → New set of books online. You are its owner.
  2. Start here walks you through the rest, the same as on the desktop: start date, entities, chart of accounts, opening balances.
  3. Invite your bookkeeper or accountant from the Books page. Roles: owner (everything, including who is a member), accountant (everything in the books, lock dates and year end included), bookkeeper (the daily work; cannot move lock dates) and read only (sees everything, changes nothing).
  4. Bank feed: connect with your own Akahu personal app tokens (my.akahu.nz → Developers). They go into your Vault.
  5. Wise: a read-only API token from Wise (Settings → API tokens), on the Bank import page. It goes into your Vault.
  6. AI: your own key on the AI suggestions page, or the shared allowance if you set one up. It goes into your Vault.

Each set of books has its own tokens. Deleting a set of books deletes its tokens from the Vault too.


10. Working through this with your AI assistant

Give the assistant this guide and the repository, and let it do the parts that are typing commands and checking results. Keep these for yourself:

A good way to start the conversation:

> I want to host OsaBooks online on my own Supabase project and web host, using > docs/self-hosting.md in the repository. My project ref is <ref>. My > Supabase personal access token is in the environment variable > SUPABASE_ACCESS_TOKEN; don't print it. Walk me through the guide one > section at a time, run the commands you can, run each "Check it worked" > step and show me the result, and stop and ask me whenever a step needs an > account, a password, or a secret.

Notes for the AI assistant


11. Keeping it up to date

When OsaBooks changes:

  1. Get the new code.
  2. Run any new files in supabase/migrations/ (by date, after the last one you ran).
  3. Re-deploy any Edge Function whose folder changed.
  4. Rebuild the app (section 7) and upload apps/web/dist/ again (section 8).

Your books are in your database and are not touched by an update.


12. Security, in short

OsaBooks — free accounting for New Zealand. Free software under the GNU AGPL v3 with the additional terms in NOTICE, provided as is and without warranty of any kind. Built from self-hosting.md.