13 KiB
🔍 Comprehensive Financial Module Audit
Date: 2026-07-25 Auditor: Rendszer-Architect (🏗️ Architect Mode) Scope: Full-stack financial system audit — Models, API, Services, Workers, Frontend Executive Summary:
The financial backend is well-architected and modular. The model layer follows DDD schema separation, the service layer splits into distinct managers, the API provides complete user-facing endpoints, and all system workers properly write to the audit ledger. The critical gap is the frontend — zero financial UI exists for end users despite the backend being fully ready.
1. MODELS — Schema & Architecture
✅ STATUS: WELL-ARCHITECTED — No Monolith
| Schema | Table | Purpose | File |
|---|---|---|---|
identity |
wallets |
Quadruple wallet: earned, purchased, service_coins + ActiveVouchers (FIFO) | models/identity/identity.py:263 |
identity |
active_vouchers |
FIFO voucher tracking with expiration | models/identity/identity.py:316 |
audit |
financial_ledger |
Immutable double-entry ledger (DEBIT/CREDIT) | models/system/audit.py:78 |
fleet_finance |
cost_categories |
Hierarchical cost category tree | models/fleet_finance/models.py:37 |
fleet_finance |
asset_costs |
Operational expense log (TCO) | models/fleet_finance/models.py:109 |
fleet_finance |
asset_financials |
Acquisition & depreciation | models/fleet_finance/models.py:180 |
fleet_finance |
insurance_providers |
Insurance company catalog | models/fleet_finance/models.py:219 |
fleet_finance |
vehicle_insurance_policies |
Vehicle insurance policies | models/fleet_finance/models.py:248 |
fleet_finance |
vehicle_tax_obligations |
Tax obligations per vehicle | models/fleet_finance/models.py:298 |
finance |
issuers |
Billing entities (KFT/EV/BT/ZRT) | models/marketplace/finance.py:27 |
marketplace |
payment_intents |
Payment intent lifecycle (Double Lock) | models/marketplace/payment.py |
core_logic |
subscription_tiers |
Subscription tier definitions | models/core_logic.py |
core_logic |
user_subscriptions / org_subscriptions |
Subscription state tracking | models/core_logic.py |
Key Enums (Defined in audit.py:58)
LedgerEntryType:DEBIT,CREDITWalletType:EARNED,PURCHASED,SERVICE_COINS,VOUCHERLedgerStatus:PENDING,SUCCESS,FAILED,REFUNDED,REFUND
2. API ENDPOINTS — Routing & User Access
✅ STATUS: WELL-COVERED
| Method | Endpoint | Purpose | User-Facing? | RBAC |
|---|---|---|---|---|
POST |
/billing/upgrade |
Package upgrade | ✅ Yes | Auth required |
POST |
/billing/payment-intent/create |
Create PaymentIntent | ✅ Yes | Auth required |
POST |
/billing/payment-intent/{id}/stripe-checkout |
Initiate Stripe checkout | ✅ Yes | Auth required |
POST |
/billing/payment-intent/{id}/process-internal |
Internal gifting deduction | ✅ Yes | Auth required |
POST |
/billing/stripe-webhook |
Stripe callback | N/A (webhook) | Signature |
GET |
/billing/payment-intent/{id}/status |
PaymentIntent status | ✅ Yes | Auth required |
GET |
/billing/wallet/balance |
User wallet balances | ✅ Yes | Auth required |
GET |
/billing/wallet/transactions |
User transaction History | ✅ Yes | Auth required |
POST |
/financial-manager/purchase-package |
Full purchase lifecycle | ✅ Yes | Auth required |
GET |
/financial-manager/status |
Service health check | ✅ Yes | Auth required |
GET |
/finance/issuers/ |
List billing issuers | ❌ Admin | finance:view |
PATCH |
/finance/issuers/{id} |
Update issuer | ❌ Admin | finance:edit |
GET |
/admin/finance/ledger |
Admin ledger view | ❌ Admin | finance:view |
POST |
/expenses/ |
Create expense (TCO) | ✅ Yes | Auth + Capability |
PUT |
/expenses/{id} |
Update expense | ✅ Yes | Auth |
GET |
/expenses/ |
List all expenses | ❌ Admin | Auth |
GET |
/expenses/{asset_id} |
Asset-specific expenses | ✅ Yes | Auth |
GET |
/subscriptions/public |
Public package catalog | ✅ Public | None |
GET |
/subscriptions/my |
Current subscription | ✅ Yes | Auth |
GET |
/subscriptions/feature-flags |
Resolved feature flags | ✅ Yes | Auth |
Router Registration (in api/v1/api.py:1)
billing.router→/billing✅financial_manager.router→/financial-manager✅finance_admin.router→/finance/issuers+/admin/finance✅
3. SERVICES — Monolith vs. Modular Managers
✅ STATUS: MODULAR & SEPARATED — Minor Overlap Risk
| Service File | Responsibility | Lines |
|---|---|---|
billing_engine.py |
Core: PricingCalculator, SmartDeduction (FIFO), AtomicTransactionManager (double-entry) | ~1070 |
financial_manager.py |
Orchestrator: full purchase lifecycle (validate→price→intent→pay→activate→commission) | ~520 |
financial_interfaces.py |
ABCs: BasePaymentGateway, BaseInvoicingService + exceptions |
~186 |
financial_orchestrator.py |
Unit of Work: payment processing with issuer selection (vetésforgó) | ~449 |
payment_router.py |
Router: PaymentIntent creation, Stripe Double Lock, internal gifting | ~495 |
cost_service.py |
Fleet operational cost tracking with telemetry | ~140 |
subscription_activator.py |
Subscription activation (user/org with stacking) | ~unknown |
commission_service.py |
MLM commission distribution | ~unknown |
stripe_adapter.py |
Stripe API adapter | ~unknown |
mock_payment_gateway.py |
Test gateway (auto-approve mode) | ~unknown |
Architecture Decision: Strategy Pattern
The financial_interfaces.py defines BasePaymentGateway and BaseInvoicingService ABCs. FinancialManager accepts any gateway implementation via constructor injection.
⚠️ Concern: Overlap Between financial_orchestrator and billing_engine
- Both create
FinancialLedgerentries financial_orchestrator.process_payment()writes ledger entries with rawupdate()SQL instead of usingAtomicTransactionManagerfinancial_orchestratoraccessesWalletfields directly via raw SQL updates- This is a code duplication risk — two different ledger-writing paths exist
Recommendation
- Either retire
FinancialOrchestrator.process_payment()in favor ofAtomicTransactionManager+PaymentRouter, or refactorFinancialOrchestratorto delegate toBillingEngineclasses.
4. WORKERS — Ledger Integration
✅ STATUS: FULLY CONNECTED — All workers write to audit ledger
| Worker | Ledger Entry? | Transaction Type | Amount | WalletType |
|---|---|---|---|---|
inactivity_monitor_worker.py |
✅ | ACCOUNT_SUSPENDED_INACTIVITY |
0.0 | EARNED |
subscription_worker.py |
✅ | SUBSCRIPTION_EXPIRED |
0.0 | SYSTEM |
subscription_monitor_worker.py |
✅ | SUBSCRIPTION_EXPIRED |
0.0 | EARNED |
⚠️ Minor Inconsistency
subscription_worker.pyline 75 usesWalletType.SYSTEM— this value does NOT exist in theWalletTypeenum (which only hasEARNED,PURCHASED,SERVICE_COINS,VOUCHER). This would raise anAttributeErrorat runtime.subscription_monitor_worker.pycorrectly usesWalletType.EARNED.
5. FRONTEND — Wallet & Transaction Views
❌ STATUS: COMPLETELY MISSING
A search across the entire frontend/src/ directory for Vue files containing wallet, transaction, balance, purchase, subscription, or billing returned zero results.
The backend already provides:
GET /billing/wallet/balance→ Returns quadruple wallet balancesGET /billing/wallet/transactions→ Returns paginated transaction history with filteringGET /subscriptions/my→ Returns current subscription detailsGET /subscriptions/feature-flags→ Returns feature flags
But no frontend component calls any of these endpoints.
What Needs Building
- WalletBalanceCard.vue — Display earned/purchased/service_coins/voucher balances
- TransactionHistory.vue — Paginated transaction list with type/wallet filters
- SubscriptionStatusBanner.vue — Current tier, expiry, upgrade CTA
- CheckoutView.vue — Package selection → PaymentIntent → Stripe/internal redirect
- PaymentStatusView.vue — Success/cancel pages after Stripe redirect
- Admin Ledger View (already spec'd in
docs/sf/epic_10_admin_frontend_spec.md) — Paginated financial ledger with user join data
6. GAP ANALYSIS SUMMARY
| Area | Status | Criticality | Action |
|---|---|---|---|
| Backend Models | ✅ Complete | — | No action needed |
| Backend API — User-facing | ✅ Complete | — | No action needed |
| Backend API — Admin | ✅ Complete | — | No action needed |
| Backend Services | ✅ Mostly modular | ⚠️ Medium | Refactor FinancialOrchestrator to delegate ledger writes to AtomicTransactionManager |
| Workers → Ledger | ✅ Connected | 🔴 Bug | Fix subscription_worker.py:75 — WalletType.SYSTEM does not exist |
| Frontend — Wallet | ❌ Missing | 🔴 Critical | Build WalletBalanceCard.vue + TransactionHistory.vue |
| Frontend — Checkout | ❌ Missing | 🔴 Critical | Build subscription purchase flow (catalog → intent → payment → confirmation) |
| Frontend — Admin Ledger | ❌ Missing | 🟡 Medium | Build admin ledger view (already spec'd) |
7. RECOMMENDED ACTIONS (Priority Order)
🔴 P0 — Critical Bugs
- Fix
subscription_worker.py:75: ChangeWalletType.SYSTEMtoWalletType.EARNED(or addSYSTEMto the enum) - Fix
FinancialOrchestrator.refund_payment()line 399/403: Code referencesWallet.wallet_typefield which doesn't exist on the Wallet model; also referenceswallet.balancewhich doesn't exist. This code would crash at runtime.
🔴 P0 — Missing Frontend
- Build
WalletBalanceCard.vue— user wallet summary display - Build
TransactionHistory.vue— paginated transaction list - Build subscription checkout flow (catalog → Intent → payment → confirmation)
🟡 P1 — Code Quality
- Refactor
FinancialOrchestrator.process_payment()to delegate toAtomicTransactionManagerfor ledger creation (eliminate dual ledger-writing paths) - Audit
FinancialOrchestrator.refund_payment()— it references non-existent fields (Wallet.wallet_type,Wallet.balance)
🟢 P2 — Documentation
- Update
epic_3_financial_motor_architecture.mdwith current service file structure - Create
logic_spec_financial_manager.mddocumenting the full purchase lifecycle flow with Mermaid sequence diagram
Audit completed by Rendszer-Architect. Ready for Gitea ticket creation.