Backend — Target Architecture

Bilko API — Express Backend

BookStack — Provjeri PRVO

Prije traženja bilo čega — provjeri BookStack (http://localhost:6875). Centralna baza znanja za tools, skills, hooks, agents, rules, projekte, klijente, dokumentaciju. Ako odgovor postoji tamo — NE TRAŽI dalje.

Status: NOT BUILT YET

This directory is EMPTY. The CLAUDE.md describes the target architecture. When building, follow docs/backend/API-REFERENCE.md as the implementation contract.

Target Tech Stack

Route Structure

All routes under /api/v1/{resource}:

Middleware Stack (Order Matters)

  1. helmet — Security headers
  2. cors — CORS with whitelist
  3. express.json() — Body parser
  4. rate-limit — 100 req/15min per IP
  5. auth-guard — JWT validation (protected routes)
  6. zod-validation — Request validation
  7. route-handler — Business logic
  8. error-handler — Centralized error responses

Error Response Format

{
  "error": "Error message",
  "code": "ERROR_CODE",
  "details": {} // optional
}

HTTP Status Codes:

Database Access

Authentication

Validation Rules

All requests validated with Zod schemas:

Double-Entry Rules (CRITICAL)

Every financial transaction MUST:

  1. Have both debit and credit accounts
  2. Equal amounts (debit = credit)
  3. Reference the source (invoice ID, expense ID)
  4. Lock exchange rate at transaction date
  5. Create audit log entry (LoggedAction)

Development Rules

  1. NEVER hold money — This is an accounting tool, not a payment processor
  2. Immutable transactions — Once locked, NEVER modify
  3. Audit everything — All mutations logged to LoggedAction
  4. Multi-currency always — Even single-currency orgs need exchange rate support
  5. Test with real accounting scenarios — Invoice → payment → reconciliation

API Reference

Full endpoint documentation in docs/backend/API-REFERENCE.md (to be created). This file will be the contract for implementation.


Revision #4
Created 2026-02-23 10:24:30 UTC by John
Updated 2026-07-05 20:02:16 UTC by John