This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Layerswap UI — a Next.js 15 web application (Pages Router) for cross-chain token swaps across 9+ blockchain networks (EVM, Solana, Starknet, TON, TRON, Fuel, Bitcoin, Cosmos, ZkSync).
pnpm install # Install dependencies
pnpm dev # Start dev server
pnpm build # Production build
pnpm lint # ESLint (next/core-web-vitals + custom JSX literal plugin)
pnpm storybook # Component docs on port 6006
ANALYZE=true pnpm build # Bundle analysisNo unit test framework is configured. Storybook is used for component documentation.
NEXT_PUBLIC_LS_API=https://api-dev.layerswap.cloud/ # API base URL
NEXT_PUBLIC_API_KEY=mainnet # "sandbox" for testnetsProduction uses https://api.layerswap.io with additional env vars for identity API, Immutable, WalletConnect, and PostHog (see .env).
- Server-side:
getServerSidePropsinhelpers/getSettings.tsfetches networks, exchanges, and routes viaLayerSwapApiClient, compresses them withsettingsCompression, and passes as page props - Client-side: Settings are inflated and pre-populated into SWR cache as fallback data. SWR handles subsequent client-side data fetching (5s dedup, no revalidation on focus)
- State: Zustand stores for wallet state, balances, slippage, routes, and transactions. React Context for swap flow, settings, form wizard, validation, and wallet providers
- Pages Router (not App Router) — routes are in
pages/, SSR viagetServerSideProps - Hybrid state: Zustand for persistent/global state (10 stores in
stores/), React Context for component-tree-scoped state (13 contexts incontext/) - Multi-chain wallet abstraction:
lib/wallets/contains adapters for each chain type, unified throughWalletProvidermodel andwalletStore - API client:
lib/apiClients/layerSwapApiClient.ts— Axios-based with auth interceptors, retry logic, and PostHog error tracking - SWR fallback pattern: Server-fetched data is injected into SWR cache at page level, enabling instant renders with background revalidation
- Settings compression: Large settings objects are compressed for SSR transfer (
helpers/settingsCompression.ts) - Path alias:
@/*maps to project root
Defined in Models/Network.ts as NetworkType enum: EVM, Starknet, Solana, Cosmos, StarkEx, ZkSyncLite, TON, Fuel, Bitcoin. Each has chain-specific wallet adapters, balance resolvers, and gas estimators in lib/.
pages/_app.js— Root: SWRConfig, PostHog, Intercom providerspages/index.tsx— Home: inflates settings, sets up SWR fallback, renders<Layout>+<Swap>components/layout.tsx— Layout wrapper with settings/query/wallet providerscomponents/swapComponent.tsx— Main swap interface orchestrator
- Custom ESLint plugin
no-conditional-literals-in-jsx: prevents conditional literals and unwrapped text in JSX (both set toerror) react-hooks/exhaustive-depsis disabledreact/display-nameis disabled
components/ # React components (~284 .tsx files)
context/ # React context providers (swap, settings, wallet, wizard, validation, etc.)
hooks/ # Custom React hooks (useWallet, useFee, useFormRoutes, etc.)
helpers/ # Utility functions (settings, balances, routes, tokens)
lib/ # API clients, wallet adapters, balance resolvers, gas estimators
├── apiClients/ # LayerSwap API, JSON-RPC, Hyperliquid clients
├── wallets/ # Per-chain wallet integrations
├── balances/ # Per-chain balance fetchers
└── gas/ # Per-chain gas estimation
Models/ # TypeScript interfaces (Network, Token, Route, Exchange, SwapStatus, etc.)
pages/ # Next.js pages (index, swap/[swapId], transactions, campaigns)
stores/ # Zustand stores (wallet, balance, slippage, routes, transactions)
styles/ # Global CSS
stories/ # Storybook stories
| Category | Libraries |
|---|---|
| Framework | Next.js 15, React 18, TypeScript 5 |
| Styling | Tailwind CSS v4, Framer Motion, Headless UI, Radix UI |
| State | Zustand, SWR, React Query, Formik |
| EVM | wagmi, viem, ethers v5 |
| Solana | @solana/web3.js, wallet-adapter-react |
| Starknet | starknet v8, @starknet-react/core, starknetkit |
| Other chains | @ton/ton, @tronweb3/, @fuel-ts/, @imtbl/sdk, @paradex/sdk |
| Analytics | PostHog |
This project includes specialized review tooling in .cursor/agents/. For comprehensive reviews, read .cursor/agents/pr-review-coordinator.md which orchestrates 6 parallel reviewers (architecture, bugs, performance, quality, react, security). For quick single-perspective reviews, use .cursor/agents/pr-reviewer.md.
Review workflow: read .cursor/commands/reviewchanges.md, output findings to pr-review-report.md.
.cursor/skills/vercel-react-best-practices/SKILL.md contains 45+ optimization rules. Key ones:
async-parallel.md— UsePromise.all()for independent operationsbundle-barrel-imports.md— Import directly, avoid barrel filesbundle-dynamic-imports.md— Usenext/dynamicfor heavy componentsrerender-memo.md— Extract expensive work into memoized components