Skip to main content←Back to docsArchitecture overview
TL;DR
- NEAR is source of truth for vault state.
- Firestore mirrors vault state for fast UI reads.
- Next.js API routes handle RPC proxying, reads, and indexing writes.
Main pieces
- Frontend (Next.js app): landing, dashboard, discover, vault, docs.
- Wallet layer: NEAR Wallet Selector for sign-in and transaction approval.
- Data mirror: Firestore documents keyed by factory ID and vault ID.
- API layer:
/api/rpc, list/read routes, and indexing routes.
Runtime flow
- User opens app and optionally connects wallet.
- By default, UI subscribes to Firestore for vaults, pending requests, and lender positions.
- User approves a transaction in wallet.
- App triggers indexing via
/api/index_vault (and best-effort enqueue). - Firestore subscribers update Discover, dashboard, and vault views.
Why this model
- Fast list/detail rendering from indexed documents.
- Clear wallet approval boundary for state-changing actions.
- Deterministic recovery path through retry indexing.
Data source notes
- Pending requests and lender positions can use REST polling.
- Enable polling with
NEXT_PUBLIC_PENDING_USE_API=true and NEXT_PUBLIC_LENDING_USE_API=true. - Vault detail views always subscribe directly to Firestore.
Related docs
SudoStake | Stake-Backed Liquidity