DEV Community

Cover image for I Built a Secret Financial Vault Inside SQLite — Here's the Architecture
DEVANSHU PATIL
DEVANSHU PATIL

Posted on

I Built a Secret Financial Vault Inside SQLite — Here's the Architecture

I Built a Secret Financial Vault Inside SQLite — Here's the Architecture

When people think about personal finance apps, they assume every account belongs on the main dashboard: your checking account, your cash wallet, your credit cards, and your stock portfolio.

However, real life is more nuanced.

There are situations where certain financial reserves must remain completely private:

  • Impulse-Prevention Reserves: If you see Rs. 1,00,000 sitting in your primary checking balance every day, your brain subconsciously treats that money as available for discretionary splurges. Hiding it out of daily sight builds psychological discipline.
  • Social Privacy: When you hand your phone to a colleague to show them a shared lunch split or verify an expense receipt, you shouldn't have to expose your total life savings or emergency buffer.
  • Personal Safety: For users in delicate domestic or financial situations, having an autonomous, discreet financial buffer is a matter of personal security.

When I designed the Secret Fund Vault in FinLedger (VaultRepository.kt, commit 61f5434), I faced a critical architectural decision:

How do you build a secret vault inside an application without risking data leaks across the rest of the codebase?

Here is why adding an is_hidden boolean column to existing tables is an architectural disaster, and how FinLedger implemented Complete Schema Isolation inside SQLite.

The Flawed Approach: The "is_hidden" Boolean Flag

Most applications attempt to hide accounts using a simple flag:

-- The Fragile "is_hidden" Schema
CREATE TABLE accounts (
    id TEXT PRIMARY KEY,
    name TEXT NOT NULL,
    balance REAL NOT NULL,
    is_hidden INTEGER DEFAULT 0 -- The Dangerous Flag!
);
Enter fullscreen mode Exit fullscreen mode

This pattern is a ticking privacy time bomb:

flowchart TD
    subgraph BooleanFlagLeak["The Leaky 'is_hidden' Anti-Pattern"]
        DB["Single Monolithic 'accounts' Table"] --> Query1["Dashboard Developer writes:
        SELECT SUM(balance) FROM accounts;
        FORGOT 'WHERE is_hidden = 0'!"]

        DB --> Query2["Global Search Developer writes:
        SELECT * FROM transactions WHERE note LIKE '%rent%';
        Matches hidden vault transactions!"]

        DB --> Query3["Room Flow Invalidation:
        Updating hidden vault balance triggers
        recomposition on main dashboard screen!"]

        Query1 --> Leak["LEAK: Secret funds exposed in Net Worth!"]
        Query2 --> Leak
        Query3 --> Leak
    end

In a codebase with 100,000 lines of Kotlin, dozens of ViewModels, and continuous feature updates:

  • A developer writing a quick net worth query forgets to append WHERE is_hidden = 0. Suddenly, your hidden emergency fund appears in your monthly net worth graph!
  • A global transaction search matches a memo written inside a hidden transaction.
  • When Room invalidates table observers, a background update to a hidden account triggers recomposition on the public dashboard, causing UI flicker or revealing that secret records exist.

Relying on developers to remember to filter out a boolean flag on every single query is an invitation to catastrophic data leaks.

The FinLedger Architecture: Complete Schema Isolation

In FinLedger, secret vault data does not live in the same tables as regular accounts.

We established Physical Schema Compartmentalization:

flowchart TD
    subgraph SQLiteDatabase["Encrypted SQLite Database (SQLCipher)"]
        direction TB

        subgraph PublicSpace["Master Ledger Subsystem (Public Space)"]
            T1["accounts Table"]
            T2["transactions Table"]
            T3["categories Table"]
            T4["lending_records Table"]
        end

        subgraph VaultSpace["Secret Vault Subsystem (Isolated Sandbox)"]
            V1["vault_accounts Table"]
            V2["vault_transactions Table"]
            V3["vault_transfers Table"]
        end

        PublicSpace -.->|STRICT ZERO-CROSSING BOUNDARY
        NO Foreign Keys! NO SQL Joins!| VaultSpace
    end

1. Isolated Table Architecture

The Secret Fund operates on completely independent SQLite entities:

  • VaultAccountEntity $\rightarrow$ vault_accounts
  • VaultTransactionEntity $\rightarrow$ vault_transactions
  • VaultTransferEntity $\rightarrow$ vault_transfers

There are zero foreign keys linking master accounts to vault accounts, and zero database triggers connecting them.

2. Zero-Leak Net Worth Mathematics

Because the master ledger queries execute against accounts and transactions:

  • SELECT SUM(currentBalance) FROM accounts cannot physically see vault balances. Even if a bug were introduced into the dashboard ViewModel, the SQL compiler itself guarantees that vault balances cannot be returned.
  • Global search queries in the main ledger have zero access to vault_transactions.
  • Room database invalidation trackers for public screens do not observe vault tables, ensuring zero background recomposition or memory leaks.

3. Ephemeral UI Mounting

In the presentation layer, the Secret Vault does not exist as a visible tab in the bottom navigation bar.

It is accessed exclusively through a discreet gesture (such as long-pressing an inconspicuous icon or entering a secret shortcut) followed by secondary authentication. When the vault is locked, its UI composables are completely unmounted from the Jetpack Compose navigation graph.

Key Takeaway

True privacy cannot rely on developer discipline or fragile SQL WHERE clauses.

If data is intended to be secret, it must be architecturally isolated from the ground up. By creating completely decoupled SQLite tables, independent DAOs, and isolated in-memory domain engines, FinLedger guarantees that your emergency reserves remain 100% invisible to the rest of the application.


FinLedger is a privacy-first, offline-first personal finance application for Android that models bank accounts, credit cards, and cash without double-counting.

Explore FinLedger on Google Play: https://play.google.com/store/apps/details?id=com.devanshufinance.app

Top comments (0)