> For the complete documentation index, see [llms.txt](https://maplefun.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maplefun.gitbook.io/docs/overview-and-basics/architecture-overview.md).

# Architecture Overview

### System Components

Maple.fun combines on-chain smart contracts with an off-chain backend to run token pools and calculate rewards.

**Smart Contracts**

The core protocol is a Solana program built with Anchor. It handles pool creation, deposits, withdrawals, and fee calculations. Pools and user accounts use Program Derived Addresses (PDAs) for deterministic, verifiable addresses.

**Backend API**

A Node.js/Express server manages pool metadata, transaction history, and user profiles. It also connects to external services like CoinGecko for token pricing.

**Database**

PostgreSQL stores off-chain data including pool configurations, transaction logs, and user activity. This enables fast queries and historical tracking without bloating on-chain storage.

**External Integrations**

The backend pulls token prices from CoinGecko and Jupiter for USD conversions and TVL calculations.

***

### How It Works

**Pool Creation**

Users create pools through the vault\_factory program and set their configuration (fees, TVL thresholds, lockup periods, etc). The backend records metadata for display and tracking.

**Deposits and Withdrawals**

Users deposit or withdraw SOL or SPL tokens directly through the program. The backend monitors transactions via Solana RPC and updates TVL and portfolio data accordingly.

**Fee and Reward Calculations**

The program calculates dynamic fees based on TVL levels and applies time-based discounts. The backend estimates APR for display using its rewardCalculator module.

**Data Aggregation**

Periodic backend jobs aggregate portfolio snapshots and refresh TVL to keep pool statistics accurate.

***

### Supported Chains

Maple.fun runs exclusively on Solana.

***

### Technical Highlights

The program uses PDAs for deterministic addresses and rent-exempt accounts, keeping costs low.

Fees scale dynamically based on TVL and time since pool creation. Pool creators configure these curves when deploying.

The protocol is non-custodial. Users control their assets and all operations execute on-chain.

Security measures include overflow guards, pausable pools, and automatic loss cap protection. The backend uses parameterized queries and input validation to prevent injection attacks.
