Skip to content
 
 

Latest commit

 

History

977 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Self-hosting Accounted

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.

Prerequisites

  • 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)

Step 0: Install Docker

If you don't have Docker installed:

macOS:

brew install --cask docker

Or 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 effect

Windows: Download Docker Desktop from docker.com/products/docker-desktop.

Verify Docker is running:

docker --version
docker compose version

Step 1: Get an OpenCode Zen API Key

Self 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:

  1. Go to opencode.ai
  2. Sign up or log in
  3. Create an API key in the dashboard
  4. Copy the key (you'll need it in Step 3)

Step 2: Clone and Start Supabase

# Clone the repo
git clone https://github.com/erp-mafia/accounted.git
cd accounted

# Initialize and start Supabase
supabase init
supabase start

supabase 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 status

Copy both keys -- you need them in Step 3.

Step 3: Apply Database Migrations

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 -l

If 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
done

After 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');"

Step 4: Configure Environment

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=Accounted

How 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.

Step 5: Start the App

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 app

Or pull the pre-built image:

docker compose up -d

The app is available at http://localhost:3000.

Step 6: First Login

Open http://localhost:3000 in your browser.

  1. Click "Skapa konto" (Create account) and register with email + password
  2. You'll be logged in immediately (email confirmation is disabled for self-hosted)
  3. 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.

How the Docker Build Works

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.

Further Reading

  • 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

Version Control with Forgejo

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 main

Forgejo 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/.


Accounted

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.

License: AGPL-3.0-or-later Core Build pg-real tests Docker

Website · Hosted app · Documentation

Why Accounted?

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.

Features

  • 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

Self-Hosting

git clone https://github.com/erp-mafia/accounted.git
cd accounted
./setup.sh              # Prompts for Supabase credentials, generates .env
docker compose up -d

You 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.

Development Setup

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      # ESLint

See CONTRIBUTING.md for the full development workflow.

Tech Stack

  • 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

Documentation

Community

Contributing

Contributions are welcome. See CONTRIBUTING.md for the full guide.

All commits require a DCO sign-off (git commit -s).

License

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.

About

The Open Source Swedish ERP System (previously Gnubok)

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages