Architecture
Locale Lending's and Data Flow & Technical Architecture

The Locale Lending's data flow and API architecture involve the following steps:
Data Collection:
Bank Account to Plaid API: Financial data is collected from bank accounts using the Plaid API.
Plaid API to HTTPs API Gateway: This data is sent to a Next.js server acting as an HTTPs API Gateway that will transform, encrypt and report to a standard webpage.
Data Processing:
Reclaim Protocol Integration: The financial data is converted into a JSON file, which is then processed through the Reclaim Protocol to produce a zk-proof on Arbitrum. This ensures the data's integrity and validity.
Storage in SQLite Database: The encrypted data, is sent to the backend inside of the CVM via a JSON file, further processed, and stored in an SQLite database via an input payload
Smart Contract Interaction:
Loan Health Monitoring: Drastic changes in loan health trigger recalculations of interest rates and limits. These calculations are performed consistently on Cartesi, using financial and smart contract data.
Smart Contract Updates: The results from these calculations are used as parameters to call smart contract functions, updating the loan terms accordingly.
Front-End Reporting:
Investor Dashboard: Important loan health metrics and zk-proof links are reported on the front-end in an investor dashboard.
Compliance and Reporting: Potential compliance and reporting to the SBA are triggered by changes in the smart contracts, ensuring regulatory adherence.
Architecture
System Overview
Locale is built on a multi-layer architecture combining traditional web services with blockchain infrastructure and off-chain computation.
Technology Stack
Frontend
Next.js 15
React framework with App Router
React 19
UI components
TypeScript 5
Type safety
Tailwind CSS
Styling
shadcn/ui
Component library
TanStack Query
Data fetching & caching
wagmi + viem
Web3 hooks & client
Backend
Next.js API Routes
REST API endpoints
Prisma
ORM for PostgreSQL
NextAuth.js
Session management
Alchemy Account Kit
Wallet abstraction
Blockchain
Solidity 0.8.22
Smart contract language
Foundry
Development & testing
OpenZeppelin
Contract standards
Arbitrum
L2 network
Off-Chain
Cartesi
Verifiable computation
Circom
ZK circuit language
snarkjs
Groth16 proof generation
Plaid
Bank account integration
Component Details
1. Web Application
The frontend is a Next.js application using the App Router pattern:
Key Features:
Server-side rendering for SEO
Role-based page access
Real-time portfolio updates
Responsive design
2. API Layer
33+ REST endpoints organized by domain:
/api/pools/*
Pool CRUD, deployment
Mixed
/api/portfolio/*
User stakes, transactions
Yes
/api/loan/*
DSCR status, applications
Yes
/api/admin/*
Dashboard, management
Admin
/api/plaid/*
Webhooks
Webhook signature
3. Smart Contracts
Six core contracts deployed on Arbitrum:
Contract Patterns:
UUPS Upgradeable Proxy
Role-Based Access Control
Reentrancy Guards
Pausable
4. Cartesi Integration
Off-chain computation via Cartesi rollups:
Cartesi DApp Handlers:
register_borrower- Initialize borrower recordcreate_loan- Create loan entrysync_transactions- Process bank transactionscalculate_dscr- Compute debt service ratioupdate_rate- Propose interest rate change
5. ZK Circuits
Circom circuits for privacy-preserving proofs:
kyc_verification.circom
Prove KYC without revealing data
dscr_threshold.circom
Prove DSCR meets threshold
plaid_commitment.circom
Commit to bank data
Proof Flow:
Generate witness from private inputs
Create Groth16 proof
Submit proof to verifier contract
Contract validates without seeing inputs
Data Flow
Loan Application Flow
Staking Flow
Database Schema
Key tables in PostgreSQL:
Security Architecture
Authentication Flow
Authorization Layers
API Routes
NextAuth session + role check
Smart Contracts
AccessControl roles
Webhooks
Signature verification
Cron Jobs
Secret token validation
Deployment Architecture
Production Environment
Environment Configuration
DATABASE_URL
PostgreSQL connection
NEXT_PUBLIC_ALCHEMY_API_KEY
Blockchain RPC
PLAID_CLIENT_ID
Bank integration
CARTESI_GRAPHQL_URL
Off-chain compute
POOL_ADMIN_PRIVATE_KEY
Contract deployment
Performance Considerations
Caching Strategy
API Responses - Redis/Vercel KV for frequent queries
Blockchain Data - TanStack Query with stale-while-revalidate
Static Assets - Vercel CDN
Rate Limiting
Public APIs
100 req/min
Authenticated
200 req/min
Webhooks
1000 req/min
Admin
50 req/min
Last updated