3.9 KiB
3.9 KiB
Frontend-Backend Connection Guide
This guide explains how to run both the frontend and backend together for the Immortal AI Trading Bot.
Quick Start
1. Install Dependencies
First, install the main backend dependencies:
bun install
Then install frontend dependencies:
cd frontend && bun install && cd ..
2. Set Up Environment Variables
Copy the environment files and configure them:
Backend (.env):
cp .env.example .env
# Edit .env with your API keys and configuration
Frontend (.env):
cp frontend/.env.example frontend/.env
# The frontend .env is already configured to connect to localhost:3001
3. Run Both Frontend and Backend
Option A: Run both together (recommended):
bun run dev:full
Option B: Run separately in different terminals:
Terminal 1 (Backend):
bun run dev:backend
Terminal 2 (Frontend):
bun run dev:frontend
Access Points
- Frontend Dashboard: http://localhost:5173
- Backend API: http://localhost:3001
- Health Check: http://localhost:3001/api/health
- Connection Test: http://localhost:3001/api/ping
API Endpoints
The backend exposes these REST endpoints for the frontend:
Core Endpoints
GET /api/health- Server health checkGET /api/ping- Connection testGET /api/status- Bot status and summary
Trading Data
GET /api/trades?limit=50- Get recent tradesGET /api/trades/:memoryId- Get specific tradeGET /api/stats- Trading statistics
Wallet & Tokens
GET /api/wallet/balance- Get wallet balanceGET /api/token/:address- Get token dataGET /api/token/:address/balance- Get token balance
Troubleshooting
Connection Issues
-
"Network error: Cannot connect to backend"
- Make sure the backend is running on port 3001
- Check if another process is using port 3001:
lsof -i :3001 - Verify environment variables are set correctly
-
CORS Errors
- The backend is configured to allow frontend origins
- Make sure you're accessing frontend from http://localhost:5173
-
Port Conflicts
- Backend runs on port 3001 (configurable via API_PORT in .env)
- Frontend runs on port 5173 (Vite default)
- Change ports if they conflict with other services
Backend Issues
-
Missing Environment Variables
- Copy
.env.exampleto.env - Set required variables like
OPENROUTER_API_KEY - Set
WALLET_PRIVATE_KEYfor testnet
- Copy
-
Database Issues
- The bot uses BNB Greenfield for memory storage
- Configure Greenfield credentials in .env if needed
Frontend Issues
-
Build Errors
- Make sure all dependencies are installed:
cd frontend && bun install - Check TypeScript errors:
cd frontend && bun run build
- Make sure all dependencies are installed:
-
API Connection
- Verify VITE_API_URL in frontend/.env points to the correct backend URL
- Default:
VITE_API_URL=http://localhost:3001
Development Scripts
Main Project
bun run dev:full- Run both frontend and backendbun run dev:backend- Run only backend with auto-reloadbun run dev:frontend- Run only frontend dev serverbun run build:all- Build both frontend and backendbun start- Run the trading bot (production)
Frontend Only
cd frontend && bun dev- Start development servercd frontend && bun build- Build for productioncd frontend && bun preview- Preview production build
Production Deployment
For production deployment:
- Build both applications:
bun run build:all
- Set production environment variables
- Run the backend:
bun start
- Serve the frontend build (frontend/dist) with a web server like nginx
API Rate Limiting
The backend includes basic CORS protection and connects to:
- OpenRouter API for AI decisions
- DexScreener API for token data
- BNB Chain RPC for blockchain operations
- PancakeSwap for trading
Monitor API usage to avoid rate limits.