How to build a finance dashboard in Next.js

2026-11-28来源 dev.toEnglish

Building a finance dashboard from scratch is hard, but the result is a tool tailored to your exact needs. Here's how to approach it in Next.js, focusing on the technical parts that matter.

The Data Model

Start with these core entities:

accounts:

id, user_id, provider, external_account_id, institution_name, account_name, account_type, balance_current, balance_available, currency, last_synced_at 

transactions:

id, account_id, external_transaction_id, posted_date, amount, description, merchant_name, category_id, is_pending, is_excluded, notes 

categories:

id, user_id, parent_id, name, type, color, icon 

budgets:

id, user_id, category_id, month, amount, rollover 

goals:

id, user_id, name, target_amount, current_amount, target_date, linked_account_id, contribution_schedule 

Gotcha: Use signed amounts in transactions (negative for outflow). This simplifies net worth calculations.

Account Aggregation

Your options:

  • Plaid: Covers 12,000+ US institutions. $0.30-$0.60 per linked account/month.
  • Teller: Cheaper alternative with solid US bank coverage.
  • MX (Atrium): Enterprise-grade, better for B2B.

For crypto, you'll need to wire wallet APIs per chain or use Zapper/DeBank APIs. Always include manual account support.

Transaction Normalization

Raw transactions are messy. You'll need to build:

  • Merchant detection: Regex + lookup table
  • Category prediction: Rules-based initially, ML later
  • Transfer matching: Flag same-day transfers between accounts
  • Recurring detection: Identify subscriptions
  • User overrides: Store separately to avoid overwriting

Critical: Transfer matching prevents double-counting in net worth and budgets.

Net Worth Calculation

Sum account balances, handling credit/loan accounts as negative:

SELECT SUM(CASE WHEN account_type IN ('credit', 'loan') THEN -balance_current ELSE balance_current END) as net_worth FROM accounts WHERE user_id = $1 AND last_synced_at > NOW() - INTERVAL '24 hours' 

Snapshot net worth daily for the trend chart.

Budgets and Cash Flow

Query transactions by month, excluding transfers:

SELECT category_id, SUM(CASE WHEN amount < 0 THEN -amount ELSE 0 END) as spent, SUM(CASE WHEN amount > 0 THEN amount ELSE 0 END) as received FROM transactions WHERE user_id = $1 AND posted_date BETWEEN $2 AND $3 AND is_excluded = false GROUP BY category_id 

Optimization: Index on (user_id, posted_date, category_id). Materialize monthly summaries for large datasets.

Sync Strategy

Use Plaid webhooks for transaction updates:

  1. Plaid sends TRANSACTIONS_REFRESH
  2. Enqueue sync job
  3. Fetch latest transactions
  4. Upsert into transactions table
  5. Re-categorize new transactions
  6. Notify user of balance changes

For non-webhook accounts, use daily cron sync.

Performance Tips

At scale, optimize with:

  1. Indexing on (user_id, posted_date)
  2. Materialized monthly summaries
  3. Redis caching for dashboard summaries
  4. Archiving old transactions

Expect 11 weeks solo, 5-6 weeks with two engineers. The UI is the easier part, focus on integration and math.

This is a shorter version of a guide I wrote at Frontkit Studio. The full post has the complete walkthrough.

原文:https://www.a8q9.cn/en/article/how-to-build-a-finance-dashboard-in-next-js-35f3de.html

相关文章