This guide walks you through setting up a fully self-hosted Accounted instance with self-hosted Supabase on your local machine using Docker where the Accounted AI assistant running Opencode Zen instead of AWS Bedrock.
- Docker Desktop (or Docker Engine + Compose v2)
- Supabase CLI installed (
brew install supabase) - About 2 GB of disk for the Docker images
- An OpenCode Zen API key (for AI features like invoice OCR, transaction categorization, and the chat assistant)
If you don't have Docker installed:
macOS:
brew install --cask dockerOr download from docker.com/products/docker-desktop.
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install docker.io docker-compose-plugin
sudo usermod -aG docker $USER
# Log out and back in for group changes to take effectWindows: Download Docker Desktop from docker.com/products/docker-desktop.
Verify Docker is running:
docker --version
docker compose versionSelf hosted Accounted uses OpenCode Zen for AI-powered features instead of relying on AWS Bedrock:
- Invoice OCR - automatically extract data from uploaded invoices
- Transaction categorization - suggest accounting categories for bank transactions
- Chat assistant - AI help with bookkeeping questions
To get an API key:
- Go to opencode.ai
- Sign up or log in
- Create an API key in the dashboard
- Copy the key (you'll need it in Step 3)
# Clone the repo
git clone https://github.com/erp-mafia/accounted.git
cd accounted
# Initialize and start Supabase
supabase init
supabase startsupabase start pulls the required Docker images (Postgres, Auth, REST, Realtime, Storage, Studio) and starts all services. When it finishes, it prints the local credentials including the anon key and service_role key.
Supabase Studio (the dashboard) is available at http://localhost:54323 - use it to browse data, run SQL queries, and manage authentication.
If you missed the output, run:
supabase statusCopy both keys -- you need them in Step 3.
Critical: supabase start may only apply a subset of migrations. You must verify and apply all of them, or the app will fail at onboarding.
# Check how many migrations are applied vs available
docker exec supabase_db_accounted psql -U postgres -c \
"SELECT COUNT(*) FROM supabase_migrations.schema_migrations;"
ls supabase/migrations/*.sql | wc -lIf the counts don't match, apply the missing migrations using the same approach as the official self-hosting guide:
# Apply each unapplied migration directly to the database
for f in supabase/migrations/*.sql; do
ver=$(basename "$f" .sql | cut -d_ -f1)
if ! docker exec supabase_db_accounted psql -U postgres -t -c \
"SELECT 1 FROM supabase_migrations.schema_migrations WHERE version='$ver'" | grep -q 1; then
echo "Applying $ver..."
docker exec -i supabase_db_accounted psql -v ON_ERROR_STOP=0 -U postgres < "$f"
docker exec supabase_db_accounted psql -U postgres -c \
"INSERT INTO supabase_migrations.schema_migrations (version) VALUES ('$ver') ON CONFLICT DO NOTHING;"
fi
doneAfter applying migrations, grant permissions to Supabase roles:
docker exec supabase_db_accounted psql -U postgres -c "
DO \$\$
DECLARE tbl RECORD;
BEGIN
FOR tbl IN SELECT tablename FROM pg_tables WHERE schemaname = 'public' LOOP
EXECUTE format('GRANT SELECT, INSERT, UPDATE, DELETE ON public.%I TO service_role', tbl.tablename);
EXECUTE format('GRANT SELECT, INSERT, UPDATE, DELETE ON public.%I TO authenticated', tbl.tablename);
EXECUTE format('GRANT SELECT ON public.%I TO anon', tbl.tablename);
END LOOP;
END
\$\$;"Then reload the PostgREST schema cache:
docker exec supabase_db_accounted psql -U postgres -c \
"SELECT pg_notify('pgrst', 'reload schema');"Create .env in the project root with the Supabase credentials from Step 3 and your OpenCode Zen key from Step 1:
# Supabase (from `supabase status` output)
NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321
NEXT_PUBLIC_SUPABASE_ANON_KEY=<paste anon key>
SUPABASE_SERVICE_ROLE_KEY=<paste service_role key>
# App config
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_SELF_HOSTED=true
SELF_HOSTED=true
CRON_SECRET=$(openssl rand -hex 32)
# AI features (from Step 1)
ZEN_API_KEY=<paste your OpenCode Zen API key>
NEXT_PUBLIC_BRANDING_APP_NAME=AccountedHow to generate each key:
| Key | How to get it |
|---|---|
NEXT_PUBLIC_SUPABASE_ANON_KEY |
Printed by supabase start, or run supabase status |
SUPABASE_SERVICE_ROLE_KEY |
Printed by supabase start, or run supabase status |
CRON_SECRET |
Run openssl rand -hex 32 in your terminal |
ZEN_API_KEY |
Get from opencode.ai (see Step 1) |
Never commit .env to version control. It contains your service role key and API secrets.
Build from source (takes a few minutes the first time):
docker compose -f docker-compose.yml -f docker-compose.build.yml --env-file .env up -d --build appOr pull the pre-built image:
docker compose up -dThe app is available at http://localhost:3000.
Open http://localhost:3000 in your browser.
- Click "Skapa konto" (Create account) and register with email + password
- You'll be logged in immediately (email confirmation is disabled for self-hosted)
- Complete the onboarding wizard:
- Step 1: Choose entity type (enskild firma or aktiebolag)
- Step 2: Company name and org number
- Step 3: Fiscal year, VAT registration, accounting method
- Step 4: Preliminary tax amount (optional, skip if unsure)
- Step 5: Bank details for invoices (optional)
There is no admin account or invite system: any email address can sign up.
The Dockerfile builds the Next.js app with placeholder sentinels (e.g. __NEXT_PUBLIC_SUPABASE_URL__) instead of real values. This produces a generic image that works across different deployments. At container startup, docker-entrypoint.sh copies the built files into writable tmpfs mounts, then sed-substitutes every __NEXT_PUBLIC_* sentinel with the runtime value from your .env. The mounts are then made read-only as defense in depth.
- SELF-HOSTING.md - Official self-hosting guide (includes cloud Supabase setup, Synology DSM notes, and the fully self-hosted Docker architecture)
- DOCKER.md - Docker deployment reference
- Supabase Self-Hosting Guide - Official Supabase Docker documentation
Accounted can be mirrored to a self-hosted Forgejo instance for private version control:
git remote add forgejo http://your-forgejo-host:3000/user/accounted.git
git push forgejo mainForgejo supports GitHub Actions-compatible workflows, but without an act-runner installed they won't execute. The workflow files in .github/workflows-disabled/ are kept for reference and can be re-enabled by renaming the directory back to .github/workflows/.
Open-source Swedish accounting software for sole traders (enskild firma) and limited companies (aktiebolag). Double-entry bookkeeping that complies with Swedish accounting law, built to be operated by you or by your AI agent.
Website · Hosted app · Documentation
Compliant by construction. Accounted implements double-entry bookkeeping under Swedish accounting law (Bokföringslagen). Voucher immutability, sequential voucher numbering, period locks, and 7-year document retention are enforced by database triggers, not by convention. Corrections are made the legal way, with reversal entries (storno), never by editing history. See ARCHITECTURE.md for how.
Agent-native. The full bookkeeping engine is exposed as 100+ MCP (Model Context Protocol) tools with scoped API keys, so an AI agent can do the books in Accounted: categorize transactions, draft vouchers, reconcile periods, and prepare declarations. Posting is staged for human approval, so the agent proposes and you decide.
Yours to run. AGPL-3.0 licensed and fully self-hostable with Docker and Supabase. Use the hosted version at app.gnubok.se or run your own.
- Double-entry bookkeeping -- BAS 2026 chart of accounts, draft/commit workflow, sequential voucher numbering
- Invoicing -- Create, send, and track invoices with mixed VAT rates and PDF generation
- Bank reconciliation -- PSD2 bank connection via Enable Banking, 4-pass automatic matching
- VAT declaration -- SKV 4700 form mapping, per-rate breakdown, EU/export handling
- Tax reports -- NE-bilaga, INK2, SRU export for Skatteverket
- Payroll -- Salary runs, payslips, and AGI (arbetsgivardeklaration) employer declarations
- Supplier invoices -- Registration, payment tracking, input VAT deduction
- Document archive -- SHA-256 integrity, 7-year retention enforcement, full archive ZIP export
- SIE import/export -- Standard Swedish accounting interchange format
- Agent access (MCP) -- 100+ bookkeeping tools over the Model Context Protocol, with scoped API keys and staged approvals
- Extension system -- Opt-in plugins for AI categorization, receipt OCR, email, calendar, and more
git clone https://github.com/erp-mafia/accounted.git
cd accounted
./setup.sh # Prompts for Supabase credentials, generates .env
docker compose up -dYou need a Supabase project and must apply the database migrations before first use. See docs/SELF-HOSTING.md for the full step-by-step guide, including Supabase setup, auth configuration, optional features (AI, email, push notifications), and troubleshooting.
Prerequisites: Node.js 20+, a Supabase project.
npm install
npm run dev # Start dev server (auto-generates extension registry)
npm test # Run tests
npm run build # Production build
npm run lint # ESLintSee CONTRIBUTING.md for the full development workflow.
- Framework: Next.js 16 (App Router), React 19, TypeScript (strict)
- Database: Supabase (PostgreSQL + Row Level Security + email/password auth + TOTP MFA)
- Styling: Tailwind CSS 4 + shadcn/ui
- Integrations: Enable Banking (PSD2), Anthropic SDK, LangChain, OpenAI, Resend, JSZip
- User and API documentation -- Guides for using the product and the public API
- ARCHITECTURE.md -- How the system is built: bookkeeping engine, legal enforcement, tenancy, extensions, agent surface
- docs/SELF-HOSTING.md -- Full self-hosting guide (Docker, Supabase setup, migrations, optional features)
- docs/EXTENSIONS.md -- Extension development guide
- docs/DOCKER.md -- Docker deployment reference
- CONTRIBUTING.md -- Development workflow, code style, pull request process
- SECURITY.md -- Vulnerability reporting policy
- Found a bug or have an idea? Open an issue
- Security vulnerabilities: see SECURITY.md, never a public issue
- Everyone interacting in the project is expected to follow the Code of Conduct
Contributions are welcome. See CONTRIBUTING.md for the full guide.
All commits require a DCO sign-off (git commit -s).
AGPL-3.0-or-later with an extension exception: third-party extensions that interact solely through the documented Extension API may be licensed under any terms, including proprietary. See LICENSE for details and NOTICE for third-party attributions.