A comprehensive backend system for a betting oracle platform with MongoDB user profiles and real-time football data integration.
- Real-time match data from API-Football
- Team search and match finding
- Head-to-head analysis
- Live match updates
- Match predictions and statistics
- Intelligent caching system
- MongoDB-powered user profiles
- Wallet-based authentication
- Social login support (Google, Facebook, Twitter, Discord)
- Contract integration for blockchain users
- Profile search and discovery
- Three-party game resolution (2 players + 1 arbitrator)
- Dynamic evidence system
- UUID-based tracking
- Mock data for development
- Node.js 16+
- MongoDB (local or Atlas)
- API-Football account (free tier available)
# 1. Clone and install
npm install
# 2. Configure environment
cp env.template .env
# 3. Edit .env with your credentials
# - MongoDB connection string
# - Football API key
# 4. Generate Prisma client
npm run prisma:generate
# 5. Push database schema
npm run prisma:push
# 6. Start server
npm run devServer will start on http://localhost:3000
# Find match between teams
GET /api/football/matches/find?team1=Bayern Munich&team2=Liverpool
# Search team
GET /api/football/teams/search?name=Barcelona
# Head-to-head
GET /api/football/matches/h2h?team1=Real Madrid&team2=Barcelona
# Live matches
GET /api/football/fixtures/live
# Team fixtures
GET /api/football/fixtures/team?name=Liverpool&next=5# Get profile
GET /api/user/profile?address=0x1234...
# Create/update profile
POST /api/user/profile
# Check exists
GET /api/user/exists?address=0x1234...
# Social login
POST /api/user/social-login# Get all results
GET /api/results
# Get specific result
GET /api/results/:id
# Create result
POST /api/results# API info and all endpoints
GET /
# Health check
GET /health- 📖 Integration Guide:
FOOTBALL_API_INTEGRATION.md - ⚡ Quick Start:
FOOTBALL_QUICK_START.md - 📋 API Reference:
FOOTBALL_API_REFERENCE.md - 💻 Code Examples:
examples/football-usage-examples.ts - 🧪 Test Script:
test-football-api.js
- 🗄️ MongoDB Setup:
MONGODB_SETUP.md - 🔄 Migration Guide:
MIGRATION_GUIDE.md - 📖 API Reference:
USER_API_QUICK_REFERENCE.md
- ✅ Summary:
IMPLEMENTATION_COMPLETE.md - 📝 Implementation Details:
IMPLEMENTATION_SUMMARY.md
node test-football-api.js# Test team search
curl "http://localhost:3000/api/football/teams/search?name=Liverpool"
# Test match finding
curl "http://localhost:3000/api/football/matches/find?team1=Real Madrid&team2=Barcelona"
# Test user profile
curl "http://localhost:3000/api/user/exists?address=0x1234567890abcdef"
# Test health
curl "http://localhost:3000/health"┌─────────────┐
│ Frontend │
└──────┬──────┘
│
│ HTTP/REST
│
┌──────▼──────────────────────────────┐
│ Express.js Server │
│ ┌──────────────────────────────┐ │
│ │ Routes │ │
│ │ - /api/football │ │
│ │ - /api/user │ │
│ │ - /api/results │ │
│ └──────────┬───────────────────┘ │
│ │ │
│ ┌──────────▼───────────────────┐ │
│ │ Controllers │ │
│ └──────────┬───────────────────┘ │
│ │ │
│ ┌──────────▼───────────────────┐ │
│ │ Services │ │
│ │ - FootballService │ │
│ │ - UserService │ │
│ │ - ContractService │ │
│ └──────────┬───────────────────┘ │
│ │ │
└─────────────┼───────────────────────┘
│
┌──────┴──────┐
│ │
┌──────▼─────┐ ┌────▼────────┐
│ MongoDB │ │ API-Football│
│ (Profiles) │ │ (Matches) │
└────────────┘ └─────────────┘
- Runtime: Node.js + TypeScript
- Framework: Express.js
- Database: MongoDB (via Prisma ORM)
- External API: API-Football
- Caching: In-memory cache with TTL
- Validation: Input validation
- Error Handling: Centralized error middleware
// Works with just team names!
GET /api/football/matches/find?team1=Bayern Munich&team2=Liverpool
// Or with specific date
GET /api/football/matches/find?team1=Bayern Munich&team2=Liverpool&date=2024-03-15const match = await footballService.findMatch({
team1: 'Real Madrid',
team2: 'Barcelona'
});
const winner = match.teams.home.winner
? match.teams.home.name
: match.teams.away.winner
? match.teams.away.name
: 'Draw';- Reduces API costs by 70-90%
- Automatic cache invalidation
- Optimized TTL for each data type
- Graceful error handling
- Helpful error messages
- Fallback mechanisms
# Server
PORT=3000
NODE_ENV=development
# MongoDB
DATABASE_URL=mongodb://localhost:27017/oracle_db
# Football API (get from dashboard.api-football.com)
FOOTBALL_API_KEY=your_api_key_here
FOOTBALL_API_URL=https://v3.football.api-sports.io
FOOTBALL_API_HOST=v3.football.api-sports.ionpm run build
npm startdocker build -t oracle-backend .
docker run -p 3000:3000 oracle-backend- Set production environment variables
- Use MongoDB Atlas for database
- Configure CORS for your frontend domain
- Enable HTTPS
- Set up monitoring
- Free: 100 requests/day
- Basic: 3,000 requests/day
- Pro: 15,000 requests/day
With caching enabled:
- 1,000 team searches → ~50 API calls
- 500 match finds → ~100 API calls
- Saves 80-90% of API requests
npm run dev # Start development server
npm run build # Build for production
npm start # Start production server
npm run lint # Run linter
npm run prisma:generate # Generate Prisma client
npm run prisma:push # Push schema to database
npm run prisma:studio # Open Prisma Studio GUIsrc/
├── app.ts # Express app setup
├── server.ts # Server entry point
├── config/
│ ├── config.ts # Configuration
│ └── db.ts # Database connection
├── controllers/
│ ├── football.controllers.ts
│ ├── user.controllers.ts
│ └── gameResults.controllers.ts
├── services/
│ ├── footballService.ts
│ ├── userService.ts
│ └── contractService.ts
├── routes/
│ ├── football.routes.ts
│ ├── user.routes.ts
│ └── gameResults.routes.ts
├── utils/
│ ├── footballApiClient.ts
│ ├── cache.ts
│ └── routeRegistry.ts
└── middlewares/
└── errorHandler.ts
- ✅ Input validation
- ✅ Error handling
- ✅ CORS enabled
- ✅ Environment variables
- JWT authentication
- Rate limiting middleware
- Request sanitization
- HTTPS in production
- API key rotation
Update CORS for production in src/app.ts:
app.use(cors({
origin: ['https://yourdomain.com'],
credentials: true
}));- Football API: https://dashboard.api-football.com
- Prisma Docs: https://www.prisma.io/docs
- MongoDB Atlas: https://docs.atlas.mongodb.com
ISC
- Test the APIs - Run
node test-football-api.js - Integrate Frontend - Connect your betting UI
- Add More Sports - Basketball, Hockey, etc.
- Implement Betting Logic - Odds calculation, bet settlement
- Add Analytics - Track popular matches and bets
- Deploy - Launch to production
Built for betting oracles with real-time sports data ⚽🎲
Version 1.0.0