-
Notifications
You must be signed in to change notification settings - Fork 9
08 Financial System
Vicky Patel edited this page Sep 14, 2026
·
1 revision
Architectural specification for the pure integer-cents financial discipline engine in
src/lib/money.ts.
PACT OS strictly forbids floating-point arithmetic for currency calculations:
// ❌ FORBIDDEN IN PACT OS: Floating-point precision error
0.1 + 0.2 // 0.30000000000000004
// ✅ MANDATORY IN PACT OS: Integer-cents calculations
10 + 20 // 30 cents ($0.30)Floating-point numbers in JavaScript suffer from binary representation inaccuracies (IEEE 754 standard). In PACT OS, all monetary amounts are converted to and stored as integer cents (amount_cents of type bigint in PostgreSQL / number in TypeScript).
Parses user-entered currency strings or numbers safely into integer cents:
- Handles inputs like
"45","45.50","1,250.00","₹1200". - Strips non-numeric characters while preserving valid decimal points.
- Enforces positive amount validation and threshold bounds.
import { parseAmountToCents } from '@/lib/money';
const res = parseAmountToCents("45.99");
// Returns: { cents: 4599, error: null }Formats integer cents into a localized currency string using Intl.NumberFormat:
import { formatCentsToCurrency } from '@/lib/money';
formatCentsToCurrency(4999, 'USD'); // "$49.99"
formatCentsToCurrency(150000, 'INR', { showFractional: false }); // "₹1,500"-
calculateFinanceSummary(transactions): Computes total income cents, total expense cents, net savings cents, savings rate percentage, and total transaction count. -
calculateCategoryBreakdown(transactions, categories): Aggregates expense totals per category with percentage rollups. -
calculateMonthlyTrends(transactions, timeZone): Computes historical month-over-month cashflow metrics.
graph TD
Trans[New Expense Transaction] --> Parse[parseAmountToCents]
Parse --> DB[(Store amount_cents in PostgreSQL)]
DB --> Agg[calculateCategoryBreakdown]
Agg --> BudgetCheck{Compare totalCents vs limitCents}
BudgetCheck -->|Below Limit| Normal[Normal Category Status]
BudgetCheck -->|Exceeds Limit| Alert[Budget Exceeded Warning]
- Each category budget specifies a
limit_centsthreshold. - Budget utilization percentages are calculated dynamically from integer cents without rounding drift.
| 🏛️ Project Hub | 🛠️ Developer Docs | 💬 Community & Support |
|---|---|---|
| GitHub Repository | System Architecture | GitHub Discussions |
| Beginner Issue Catalog | Design System | Open Issues |
| Production Deployment | API Reference | Pull Requests |
| Project Roadmap | Testing & QA Matrix | Maintainer Governance |
- Codebase Tour
- Domain Model
- Database Architecture
- Security Model
- Financial System
- Consequence System
- External Integrations
- Discipline Intelligence
- Data Portability & Sync