The OnChain Sage backend serves as the central nervous system for the decentralized trading intelligence platform, providing:
- AI-Driven Market Analysis: Real-time processing of market data and social sentiment
- Multi-Chain Trading Intelligence: Comprehensive analysis across multiple blockchain networks
- Community Features: Forum management and reputation system backend
- External Data Integration: Twitter/X, DEX Screener, Raydium, and other market data sources
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β API Gateway Layer β
β βββββββββββββββββββββββββββββββ β
β β NestJS Backend API β β
β β (Authentication, Logic, β β
β β Data Processing) β β
β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Core Modules β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
β β Trading β β AI/ML β β Data Ingestion β β
β β Signals β β Processing β β (External APIs) β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
β β Community β β Auth β β Notifications β β
β β Forum β β & Users β β & Alerts β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Layer β
β ββββββββββββββββββββββββββββββββ β
β β PostgreSQL + Redis Cache β β
β β Message Queue (Bull) β β
β ββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Node.js 18+ and npm/yarn
- PostgreSQL 15+
- Redis 7+
- Git
-
Clone the repository
git clone https://github.com/your-org/onchainsage-offchain.git cd onchainsage-offchain -
Install dependencies
npm install
-
Environment Configuration
cp .env.example .env
Configure your
.envfile with:# Database DATABASE_URL=postgresql://username:password@localhost:5432/onchainsage_db REDIS_URL=redis://localhost:6379 # API Keys TWITTER_API_KEY=your_twitter_api_key TWITTER_API_SECRET=your_twitter_api_secret DEX_SCREENER_API_KEY=your_dex_screener_api_key # StarkNet STARKNET_RPC_URL=https://starknet-mainnet.public.blastapi.io STARKNET_PRIVATE_KEY=your_private_key # JWT JWT_SECRET=your_jwt_secret JWT_EXPIRES_IN=24h # Application PORT=3000 NODE_ENV=development
-
Database Setup
# Run migrations npm run migration:run # Seed data (optional) npm run seed
-
Start Development Server
npm run start:dev
The API will be available at http://localhost:3000
src/
βββ modules/
β βββ auth/ # Authentication & wallet verification
β β βββ auth.controller.ts
β β βββ auth.service.ts
β β βββ auth.module.ts
β β βββ guards/
β β βββ strategies/
β βββ trading/ # Trading signals & bot logic
β β βββ trading.controller.ts
β β βββ trading.service.ts
β β βββ signals/
β β βββ bots/
β βββ data-ingestion/ # External API integrations
β β βββ twitter/
β β βββ dex-screener/
β β βββ raydium/
β β βββ processors/
β βββ ai-processing/ # ML/AI analysis engines
β β βββ sentiment/
β β βββ pattern-recognition/
β β βββ risk-assessment/
β β βββ signal-generation/
β βββ community/ # Forum & social features
β β βββ forum/
β β βββ reputation/
β β βββ badges/
β βββ notifications/ # Alert & notification system
β βββ notifications.controller.ts
β βββ notifications.service.ts
β βββ channels/
βββ shared/
β βββ dto/ # Data transfer objects
β βββ interfaces/ # Shared interfaces
β βββ utils/ # Utility functions
β βββ constants/ # Application constants
β βββ decorators/ # Custom decorators
βββ database/
β βββ migrations/ # Database migrations
β βββ seeds/ # Seed data
β βββ entities/ # Database entities
βββ config/ # Configuration files
β βββ database.config.ts
β βββ redis.config.ts
β βββ app.config.ts
βββ main.ts # Application entry point
- Wallet Integration: StarkNet wallet signature verification
- JWT Tokens: Secure session management
- Role-based Access: User hierarchy and permissions
- Signal Generation: AI-powered buy/sell recommendations
- Bot Configurations: Conservative, Moderate, Aggressive, Degen modes
- Risk Assessment: Multi-factor risk scoring system
- Performance Tracking: Signal accuracy and profitability metrics
- Twitter/X Integration: Real-time narrative and sentiment analysis
- DEX Screener API: Price, volume, and market data
- Raydium Integration: Liquidity pools and trading metrics
- On-chain Analytics: Whale movements and holder analysis
- Sentiment Analysis: NLP processing of social media content
- Pattern Recognition: Technical analysis algorithms
- Risk Scoring: Multi-dimensional risk assessment
- Signal Generation: Automated trading recommendations
- Forum Management: Discussion threads and moderation
- Reputation System: Performance-based user rankings
- Badge System: Achievement and milestone tracking
- Voting Mechanisms: Community-driven decision making
- Real-time Alerts: WebSocket-based notifications
- Email Notifications: Critical updates and reports
- Push Notifications: Mobile and browser notifications
- Custom Channels: User-defined notification preferences
# Development
npm run start:dev # Start development server with hot reload
npm run start:debug # Start with debug mode
npm run start:prod # Start production server
# Building
npm run build # Build the application
npm run build:webpack # Build with webpack
# Testing
npm run test # Run unit tests
npm run test:watch # Run tests in watch mode
npm run test:e2e # Run end-to-end tests
npm run test:cov # Run tests with coverage
# Database
npm run migration:generate # Generate new migration
npm run migration:run # Run pending migrations
npm run migration:revert # Revert last migration
npm run seed # Seed database with initial data
# Code Quality
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issues
npm run format # Format code with Prettier
# Documentation
npm run docs:generate # Generate API documentation
npm run docs:serve # Serve documentation locallyPOST /auth/wallet-login # Wallet signature authentication
POST /auth/refresh # Refresh JWT token
GET /auth/profile # Get user profile
GET /trading/signals # Get trading signals
POST /trading/signals # Submit trading signal
GET /trading/bots # Get bot configurations
POST /trading/bots # Create/update bot config
GET /trading/performance # Get performance metrics
GET /community/forum # Get forum threads
POST /community/forum # Create new thread
GET /community/reputation # Get user rankings
POST /community/vote # Vote on content
GET /data/market # Get market data
GET /data/sentiment # Get sentiment analysis
GET /data/narratives # Get trending narratives
For detailed API documentation, visit /api/docs when running the server.
# Start all services
docker-compose up -d
# Start specific services
docker-compose up -d postgres redis
# View logs
docker-compose logs -f api
# Stop services
docker-compose down# Build production image
docker build -t onchainsage-backend .
# Run container
docker run -p 3000:3000 --env-file .env onchainsage-backend# Unit tests
npm run test
# Integration tests
npm run test:e2e
# Test coverage
npm run test:cov- Unit Tests: Individual module testing
- Integration Tests: API endpoint testing
- E2E Tests: Full application flow testing
Ensure the following environment variables are set in production:
NODE_ENV=production
DATABASE_URL=your_production_database_url
REDIS_URL=your_production_redis_url
JWT_SECRET=your_secure_jwt_secret
TWITTER_API_KEY=your_twitter_api_key
# ... other API keys- Docker: Use provided Dockerfile and docker-compose
- PM2: Process manager for Node.js applications
- Cloud Platforms: AWS, GCP, Azure with container services
- Serverless: AWS Lambda, Vercel Functions
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Add tests for new functionality
- Run the test suite
npm run test npm run lint - Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- TypeScript: Strict mode enabled
- ESLint: Airbnb configuration
- Prettier: Code formatting
- Conventional Commits: Commit message format
- Test Coverage: Minimum 80% coverage required
- Performance: Response times and throughput
- Health Checks: Database and external service status
- Error Tracking: Comprehensive error logging
- Custom Metrics: Trading signal accuracy, user activity
- Structured Logging: JSON format for easy parsing
- Log Levels: Error, Warn, Info, Debug
- Request Tracing: Unique request IDs
- Security Logging: Authentication and authorization events
- Input Validation: All inputs validated and sanitized
- Rate Limiting: API rate limiting to prevent abuse
- CORS: Properly configured CORS policies
- Helmet: Security headers middleware
- JWT Security: Secure token handling and rotation
- Regular dependency updates
- Security audits and penetration testing
- Secure API key management
- Database security and encryption
- Architecture Documentation: Detailed system architecture
- API Documentation: Interactive API docs
- Contributing Guidelines: How to contribute
- Deployment Guide: Production deployment
- Frontend Repository: React/Next.js frontend
- Smart Contracts: Cairo smart contracts
This project is licensed under the MIT License - see the LICENSE file for details.
- Discord: Join our community
- GitHub Issues: Report bugs or request features
- Documentation: Read the docs
- Email: support@onchainsage.com