Skip to content
KaandroidsPublic

About

Invoice analysis for German businesses and their tax advisors: AI reads the documents, rules check them, people decide. Spring Boot · Angular · PostgreSQL · Gemini

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

255 Commits

Folders and files

Repository files navigation

rechnum

Invoice analysis for German businesses and their tax advisors:
AI reads the documents, rules check them, people decide.

CI Coverage gate of 90 % Java 25 Spring Boot 4.1 Angular 22 PostgreSQL 18 Gemini on Google Cloud, EU GoBD and GDPR by design MIT license

An invoice beside its document: the positions with their accounts and booking keys, one asking for a look, its line highlighted on the page

The inbox: uploaded documents, each with the invoice the analysis made of it The invoices: sender, number, tax case, due date, amount and status
The inbox The invoices

rechnum turns the documents a business receives into invoices its tax advisor can trust. A document is uploaded, the analysis reads it with Gemini, deterministic checks test every value, and the invoice is recorded with how certain each value is, why a value is doubtful and where it stands on the page. Each position gets an account of the organization's chart of accounts (SKR03 for now) and a booking key. Organizations own their data; tax advisors work on it within a mandate. Data stays in the EU, and GoBD and GDPR shape the design.

Status: in active development, not deployed yet (target: Google Cloud Run, set up with Terraform in #86). The application runs locally with Docker. The screenshots show generated sample documents.

What it does

  • Accounts and organizations: sign-up, sign-in, password reset; organizations with members, roles and invitations.
  • Documents: upload, warnings about possible duplicates, a trash; originals kept in Cloud Storage.
  • Invoices from documents: each document is analysed and becomes an invoice that is ready or asks for action. People correct what was read, enter an invoice by hand when the analysis cannot read a document, and mark invoices as checked.
  • Account assignment: each position gets an account of the organization's chart of accounts and a DATEV booking key, with the reason and the accounts considered; accounts people chose for similar positions of a supplier are offered again. How: docs/flows/account-assignment.md (ADR 0053, 0054, 0056, 0057).
  • Audit log: every change, by a person or the analysis, can be read, checked and exported.

Next: a readable audit log for the bookkeeping entries, conditions for the check that each organization sets (#492), and further checks of recorded invoices in the second pipeline.

Highlights

  • AI that explains itself. Every value the model read carries its confidence, its doubts and its place on the page, which the invoice screen highlights. The organization's thresholds mark what is doubtful; only certain findings (a value the law requires that is missing, a value that cannot be read, amounts that do not add up) ask a person to act, and nothing is decided silently (ADR 0039, 0041, 0062).
  • Rules around the model, not instead of it. Three model calls read a document, wrapped by deterministic steps: opening the PDF safely, normalising dates, amounts and IBANs, finding each value in the page's text, checking that net, tax and gross add up and that the positions make them, spotting the same invoice uploaded twice and deriving the tax case with its reasons (ADR 0047, 0050, 0052).
  • A second pipeline for the bookkeeping. A recorded invoice's positions are described in a model call, embedded, and matched against the organization's chart of accounts and the accounts people chose before for that supplier; a last model call chooses among those candidates with a reason, and the booking key follows by rule. A position without an account it can be booked to asks a person, and the invoice cannot be marked as checked before (ADR 0053, 0054, 0056).
  • Reproducible AI. Every model call is recorded with its prompt version. Tests and local runs answer from recorded answers for generated sample documents, so CI never calls Google and a prompt change shows its effect as a diff (ADR 0038, 0039).
  • Tenant isolation in two layers. One schema, tenant_id on every row, enforced by Hibernate and by PostgreSQL row-level security under a role that cannot bypass it; a test fails for any table that is not covered (ADR 0003, 0020).
  • An audit log that proves itself. Every change to an organization's data writes a hash-chained entry in the same transaction, and the chain can be checked and exported from the app. Invoice values appear only as salted hashes, so the log proves what was recorded without keeping personal data longer than the document (ADR 0004, 0016, 0027, 0028, 0042).
  • Decisions on record. Architecture decision records explain what was decided and why; new screens are agreed as clickable prototypes before they are built (ADR 0033).
  • Security in CI. Secret scanning, dependency advisories, static analysis and a check against breaking API changes run on every pull request, next to the tests and a 90 % coverage gate.

How a document becomes an invoice

flowchart TD
    upload([PDF uploaded]) --> inspect[Open the file<br/>pages, text, limits]
    inspect --> callA[Call A<br/>kind, sender, recipient, number, dates]
    callA --> gate{An invoice?}
    gate -- "no, or several documents" --> person([A person decides,<br/>and may take it as an invoice])
    gate -- yes --> normalise[Normalise call A's values]
    normalise --> repeat{Seen before?}
    repeat -- yes --> person
    repeat -- no --> callB[Call B<br/>amounts, payment terms, tax notes, supply]
    callB --> normaliseB[Normalise call B's values<br/>compute what follows, derive the tax case]
    normaliseB --> callC[Call C<br/>positions, item line by item line]
    callC --> normaliseC[Normalise the positions<br/>compute missing line amounts]
    normaliseC --> locate[Locate each value on the page]
    locate --> assess[Check sums, rates, dates and required values,<br/>mark values below the thresholds]
    assess --> invoice([Invoice recorded: analysed, or action needed<br/>for a missing, unreadable or not adding up value])
    classDef model fill:#fff4e5,stroke:#b45309,color:#3b2100
    class callA,callB,callC model
Loading

Model calls are orange; every other step is code. Each step is versioned and records its output, so a run can be traced and continued where it stopped. The full, generated flow: docs/flows/analysis.md.

Architecture

flowchart LR
    browser["Angular SPA"]
    subgraph gcp["Google Cloud (planned)"]
        api["Spring Boot<br/>modular monolith, Cloud Run"]
        db[("PostgreSQL<br/>data, audit log, analysis queue")]
        redis[("Redis<br/>rate limits, revoked sessions")]
        gcs[("Cloud Storage<br/>document originals")]
        model["Gemini<br/>EU location"]
    end
    mail["Mail server (SMTP)"]
    browser -- "/api, JSON" --> api
    api -- "row-level security per tenant" --> db
    api --> redis
    api --> gcs
    api -- "PDF or text, prompt, schema; texts to embed" --> model
    api -- "links and notices" --> mail
Loading
  • Modular monolith (ADR 0001): one Spring Boot application split into feature modules (identity, organization, document, analysis, invoice, audit, ...) that use each other only through their public API, checked by Spring Modulith.
  • Authentication (ADR 0006, 0008–0012): own JWTs; a short-lived access token in memory, a rotating refresh token in an HttpOnly cookie, sessions revocable through Redis.
  • API contract (ADR 0002): the backend generates the OpenAPI spec, the frontend client is generated from it, and CI rejects breaking changes.
  • Frontend (ADR 0014): Angular with its own UI components on Tailwind design tokens, English source texts with a German translation.

More: architecture · all diagrams · decisions · product definition

Tech stack

Area Technology
Backend Java 25, Spring Boot 4.1, Spring Modulith, Hibernate, Flyway, PDFBox, Maven
Frontend Angular 22 (signals, no SSR), Tailwind CSS, PDF.js, generated OpenAPI client
Data PostgreSQL 18 with row-level security, Redis 8, Google Cloud Storage
AI Gemini on Google Cloud (EU), recorded answers in tests
Quality JUnit, Testcontainers, Vitest, ESLint, Prettier, Spotless, JaCoCo
Security gitleaks, OSV-Scanner, Semgrep, oasdiff

Getting started

Prerequisites: Docker, JDK 25 (JAVA_HOME pointing to it), Node.js 24, and Python 3.9 or later for the sample documents.

# Backend: starts PostgreSQL, Redis, Mailpit and fake-gcs-server through Docker Compose, then the API on :8080
cd backend
SPRING_PROFILES_ACTIVE=local ./mvnw spring-boot:run

# Frontend: on :4200, proxies /api to the backend
cd frontend
npm ci
npm start          # English (source texts)
npm run start:de   # German

Then open http://localhost:4200/sign-up. Emails (registration and reset links) arrive in Mailpit at http://localhost:8025. The UI components are shown at http://localhost:4200/ui-preview (development builds only).

To see an analysis, generate the sample documents and upload some of them: invoices with cash discounts, reverse charge, wrong sums, a mistyped IBAN, and files that are no invoice at all. Locally the model answers from recordings, so any other file fails its analysis at once.

python3 tools/sample-documents/generate.py   # writes them to tools/sample-documents/out/

What each sample is for: tools/sample-documents. The recordings are found by the files' bytes; python3 tools/sample-documents/check-recordings.py says whether yours match. If they do not (another zlib may pack them differently), the few samples the tests use are committed as they were recorded, in backend/src/test/resources/analysis/samples/.

Repository

Path Contents
backend/ Spring Boot 4.1, Java 25, Maven wrapper. Conventions: backend/CLAUDE.md
frontend/ Angular 22, Tailwind CSS. Conventions: frontend/CLAUDE.md
compose.yaml Local PostgreSQL 18 with pgvector, Redis 8, Mailpit and fake-gcs-server (Cloud Storage)
infra/ Database roles for local development and tests
docs/ Architecture and flow diagrams, decisions (adr/), product definition (product/)
tools/ Sample documents for the analysis, and ask-model.sh to record the model's answers to them
.github/ CI workflow and Dependabot

Repository-wide rules (language, comments, Git workflow): CLAUDE.md.

Checks

The same checks run in CI on every pull request; CI OK must pass.

Command
Backend build, tests (Testcontainers, needs Docker), formatting, coverage cd backend && ./mvnw verify
Backend formatting fix cd backend && ./mvnw spotless:apply
Frontend tests, lint, formatting, build cd frontend && npm test -- --watch=false --coverage && npm run lint && npm run format:check && npm run build
Translations cd frontend && npm run i18n:extract && npm run i18n:check
API spec after API changes cd backend && ./mvnw test -Dtest=OpenApiSpecTest -Dopenapi.update=true
Analysis flow after changing a step cd backend && ./mvnw test -Dtest=AnalysisDiagramTest -Danalysis.diagram.update=true

Troubleshooting

Common problems when running locally
  • Backend does not start, "Unable to connect to Docker": start Docker first; the local profile starts the Compose services itself.
  • Backend does not start, "password authentication failed for user rechnum_owner": the local database was created before the database roles existed. Recreate it, which deletes the local data: docker compose down -v.
  • Backend does not start, Flyway "checksum mismatch": a migration changed on a branch after your local database applied it. Recreate the database: docker compose down -v.
  • An analysis fails at once: the recorded model only knows the sample documents as generate.py writes them; see Getting started.
  • ./mvnw fails with an unsupported class version: JAVA_HOME does not point to JDK 25.
  • Frontend build fails in generate:api: the API client generator needs Java on the PATH.
  • Signed out after every reload: the refresh cookie is Secure. Chrome and Firefox accept it on http://localhost, other browsers may not; use one of these two locally.

License

MIT

About

Invoice analysis for German businesses and their tax advisors: AI reads the documents, rules check them, people decide. Spring Boot · Angular · PostgreSQL · Gemini

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages