@@ -84,69 +84,44 @@ You should see NOTICE logs confirming that the engine successfully blocked unbal
8484## Ledger Architecture Diagram
8585
8686``` mermaid
87- erDiagram
88- %% Entities
89- ACCOUNTS ||--o{ ENTRIES : "tracked in"
90- TRANSACTIONS ||--|{ ENTRIES : "composed of"
91- ACCOUNTS ||--|| ACCOUNT_BALANCES : "cached as"
92- ACCOUNTS ||--|| ACCOUNT_MILESTONES : "checkpointed at"
93-
94- %% Table Structures
95- ACCOUNTS {
96- uuid id PK
97- varchar code
98- text type
99- }
100-
101- TRANSACTIONS {
102- uuid id PK
103- text description
104- timestamptz posted_at
105- }
106-
107- ENTRIES {
108- uuid id PK
109- uuid transaction_id FK
110- uuid account_id FK
111- numeric amount
112- text direction
113- }
114-
115- ACCOUNT_BALANCES {
116- uuid account_id PK, FK
117- numeric total_debit
118- numeric total_credit
119- numeric current_balance "GENERATED"
120- }
121-
122- ACCOUNT_MILESTONES {
123- uuid account_id PK, FK
124- uuid milestone_entry_id
125- numeric verified_balance
126- }
127-
128- %% Logic and Guarding Flow
129- subgraph Integrity_Layer [Data Guarding]
130- fn_enforce_double_entry {{Trigger: Double Entry Check}}
131- fn_block_modifications {{Trigger: Immutability Guard}}
132- fn_sync_account_balance {{Trigger: Balance Sentinel}}
87+ graph TD
88+ %% Entities/Tables
89+ subgraph Tables [Database Schema]
90+ ACCOUNTS[(accounts)]
91+ TRANSACTIONS[(transactions)]
92+ ENTRIES[(entries)]
93+ BALANCES[(account_balances)]
94+ MILESTONES[(account_milestones)]
13395 end
13496
97+ %% Logic/Triggers
98+ subgraph Integrity [Data Guarding]
99+ fn_double[fn_enforce_double_entry]
100+ fn_immutable[fn_block_modifications]
101+ fn_sync[fn_sync_account_balance]
102+ end
103+
104+ %% Maintenance
135105 subgraph Automation [Maintenance]
136- pg_cron [[ pg_cron Scheduler] ]
137- pr_create_account_milestones [[Milestone Procedure] ]
106+ cron[ pg_cron Scheduler]
107+ pr_milestone[pr_create_account_milestones ]
138108 end
139109
140- %% Flow Connections
141- ENTRIES -.-> fn_enforce_double_entry : "Validates Sums"
142- ENTRIES -.-> fn_block_modifications : "Prevents Update/Delete"
143- ENTRIES -.-> fn_sync_account_balance : "Updates Cache"
144-
145- fn_sync_account_balance -.-> ACCOUNT_BALANCES : "Increments"
146- fn_sync_account_balance -.-> ACCOUNT_MILESTONES : "Verifies against Delta"
110+ %% Relationships
111+ TRANSACTIONS -->|Header| ENTRIES
112+ ACCOUNTS -->|Reference| ENTRIES
147113
148- pg_cron --> pr_create_account_milestones : "Every 10 Mins"
149- pr_create_account_milestones --> ACCOUNT_MILESTONES : "Advances Checkpoint"
114+ %% Trigger Flow
115+ ENTRIES ==>|INSERT| fn_double
116+ ENTRIES ==>|INSERT| fn_immutable
117+ ENTRIES ==>|INSERT| fn_sync
118+
119+ fn_sync -->|Update| BALANCES
120+ fn_sync -.->|Verify| MILESTONES
121+
122+ %% Cron Flow
123+ cron -->|Every 10m| pr_milestone
124+ pr_milestone -->|Advance| MILESTONES
150125```
151126
152127
0 commit comments