This repository contains the Next.js frontend for the Routstr Chat application.
- Chat UI with conversation history and model selection
- Cashu Lightning wallet integration (deposit, balance, invoice history)
- Nostr support and relay connectivity
- Configurable models and providers
- Persistent storage via localStorage and Zustand stores
- Next.js 15, React 19, TypeScript 5
- Tailwind CSS 4
- Zustand for state management
- TanStack Query for data fetching/caching
- Cashu TS, Nostr tools
- Install dependencies
npm install- Run the development server
npm run devThe app will be available at http://localhost:3000.
# Start dev server (Turbopack)
npm run dev
# Build production assets
npm run build
# Start production server
npm run start
# Lint
npm run lint
# Invoice-related tests (see Testing below)
npm run test:invoices
npm run test:invoices:integration
# Helper: set up local regtest Cashu mint
npm run test:setupThis project includes invoice persistence and Lightning integration tests.
- Overview and quick usage:
test/README.md - Full local regtest setup:
test/LIGHTNING_TESTING_SETUP.md
Quick start:
# Start Cashu regtest environment (see the guide for details)
cd ~ && git clone https://github.com/callebtc/cashu-regtest.git
cd ~/cashu-regtest && ./start.sh
# From the project root, start mint and run tests
npm run test:setup
npm run test:invoicesWhen running the app against local regtest:
npm run devThen in your browser console set the mint URL (first run):
localStorage.clear();
localStorage.setItem('mint_url', 'http://localhost:3338');
location.reload();See test/LIGHTNING_TESTING_SETUP.md for a full end-to-end walkthrough and troubleshooting.
Build and run a production server:
npm run build
npm run startYou can deploy using any platform that supports Next.js 15 (Node.js 18+). Ensure required environment variables are set in your hosting provider.
- Port conflicts: If
3000is in use, Next.js will prompt or choose another port. - Regtest not detected: Verify the mint is running:
curl http://localhost:3338/v1/info. - Invoices not updating:
- Check that
mint_urlis set inlocalStorage - Ensure the regtest containers and the mint are up (see test guide)
- Check that
- Node version: Use Node.js 18 or newer.
Key directories:
app/: Next.js App Router entry pointscomponents/: UI components (chat UI, settings, wallet, etc.)context/: React context providershooks/: Custom React hooksstores/: Zustand stores for wallet and transactionsutils/andlib/: Utilities and integrations (Cashu, Nostr)test/: Scripts and docs for Lightning/regtest testing
This project uses Mock Service Worker (MSW) for API mocking in development. This allows you to test error scenarios and edge cases without hitting the real backend.
To test the 413 error scenario:
-
Start the development server:
npm run dev
-
Open the app in your browser and wait for the service worker to initialize (check Network tab for
mockServiceWorker.js). -
Enable the 413 mock scenario in your browser console:
localStorage.setItem('msw:scenario', '413'); // Optional: add latency delay localStorage.setItem('msw:latency', '1500'); // milliseconds
-
Refresh the page and trigger a chat request. The API call to
v1/chat/completionswill return a 413 error with the payload:{ "error": { "message": "Payload Too Large", "code": "PAYLOAD_TOO_LARGE", "status": 413 } } -
Disable the mock when done:
localStorage.removeItem('msw:scenario'); localStorage.removeItem('msw:latency');
The mock handler is configured in mocks/handlers.ts and automatically starts in development mode via components/ClientProviders.tsx.
mocks/handlers.ts may be outdated. The mock responses for /v1/keysets and /v1/info endpoints should be updated periodically to match the current Minibits mint state.
To update the mock data:
- Fetch the latest data from the real mint:
curl https://mint.minibits.cash/Bitcoin/v1/keysets curl https://mint.minibits.cash/Bitcoin/v1/info
- Update the corresponding handlers in
mocks/handlers.tswith the fresh responses.
MIT