A Node.js backend service for the L1Beat, providing API endpoints for Avalanche L1 data and metrics.
- Chain Data: Fetch and store information about Avalanche chains
- Validator Data: Track validators for each chain
- TVL Tracking: Historical and current TVL data for Avalanche
- TPS Metrics: Track transactions per second for each chain and the entire network
- Caching: In-memory caching for improved performance
- Structured Logging: Comprehensive logging system
- Security: Rate limiting, input validation, and security headers
- Node.js and Express: Backend framework
- MongoDB: Database for storing chain, validator, TVL, and TPS data
- Mongoose: MongoDB object modeling
- Winston: Structured logging
- Helmet: Security headers
- Express Validator: Input validation
- Express Rate Limit: API rate limiting
- Node-cron: Scheduled tasks
GET /api/chains
: Get all chainsGET /api/chains/:chainId
: Get a specific chain by IDGET /api/chains/:chainId/validators
: Get validators for a specific chain
GET /api/tvl/history
: Get historical TVL dataGET /api/tvl/health
: Check TVL data health
GET /api/chains/:chainId/tps/history
: Get TPS history for a specific chainGET /api/chains/:chainId/tps/latest
: Get latest TPS for a specific chainGET /api/tps/network/latest
: Get latest network-wide TPSGET /api/tps/network/history
: Get historical network-wide TPSGET /api/tps/health
: Check TPS data healthGET /api/tps/diagnostic
: Get diagnostic information about TPS dataGET /api/tps/status
: Get TPS status summary
- Node.js (v16.20.1 or higher)
- MongoDB
-
Clone the repository:
git clone https://github.com/yourusername/l1beat-backend.git cd l1beat-backend
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory with the following variables:# Development Database DEV_MONGODB_URI=mongodb://localhost:27017/glacier-chains PROD_MONGODB_URI=mongodb+srv://[username]:[password]@your-mongodb-cluster/glacier-chains NODE_ENV=development PORT=5001 ADMIN_API_KEY=your-admin-key UPDATE_API_KEY=your-update-key # Frontend URLs FRONTEND_URL=http://localhost:5173
-
Start the development server:
npm run dev
For production deployment, set NODE_ENV=production
and ensure all environment variables are properly configured.
This application is configured for deployment on Vercel. To deploy:
-
Install the Vercel CLI:
npm install -g vercel
-
Create a
.env.production
file with your production environment variables:NODE_ENV=production PROD_MONGODB_URI=your_production_mongodb_uri ADMIN_API_KEY=your_production_admin_key UPDATE_API_KEY=your_production_update_key
-
Run the deployment script:
./deploy.sh
Alternatively, you can deploy directly from the Vercel dashboard by connecting your GitHub repository.
The application runs several scheduled tasks:
- TVL updates: Every 30 minutes
- Chain and TPS updates: Every hour
- TPS verification: Every 15 minutes
The application implements in-memory caching for frequently accessed data:
- Chain data: 5 minutes
- TVL history: 15 minutes
- TPS data: 5 minutes
The application implements several security measures:
- Rate limiting for API endpoints
- Input validation for all parameters
- Security headers via Helmet
- CORS configuration
ISC