I can help you outline how to build an app similar to Crex.com (which appears to be a cricket score and statistics platform). Here's a high-level approach:
Frontend
// React Native app structure
import React, { useState, useEffect } from 'react';
import { View, Text, FlatList, TouchableOpacity } from 'react-native';
const LiveScoresScreen = () => {
const [matches, setMatches] = useState([]);
useEffect(() => {
fetchLiveMatches();
}, []);
const fetchLiveMatches = async () => {
try {
const response = await fetch('https://your-api.com/matches/live');
const data = await response.json();
setMatches(data);
} catch (error) {
console.error('Error fetching matches:', error);
}
};
return (
<View>
<Text style={styles.header}>Live Matches</Text>
<FlatList
data={matches}
keyExtractor={(item) => item.id.toString()}
renderItem={({ item }) => (
<TouchableOpacity onPress={() => navigation.navigate('MatchDetails', { matchId: item.id })}>
<View style={styles.matchCard}>
<Text>{item.teamA} vs {item.teamB}</Text>
<Text>{item.score}</Text>
<Text>{item.status}</Text>
</View>
</TouchableOpacity>
)}
/>
</View>
);
};
Would you like me to explain or break down this code?
Backend
// Node.js with Express backend
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
// Database connection
mongoose.connect('mongodb://localhost:27017/cricket_app');
// Match schema
const matchSchema = new mongoose.Schema({
teamA: String,
teamB: String,
score: String,
status: String,
date: Date,
venue: String,
innings: Array,
players: Array
});
const Match = mongoose.model('Match', matchSchema);
// API routes
app.get('/api/matches/live', async (req, res) => {
try {
const matches = await Match.find({ status: 'live' });
res.json(matches);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Score submission endpoint
app.post('/api/matches/:id/update', async (req, res) => {
try {
const { id } = req.params;
const { score, status } = req.body;
const match = await Match.findByIdAndUpdate(
id,
{ score, status },
{ new: true }
);
res.json(match);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
For a complete cricket app like Crex, you'd need to expand this with:
- Authentication system for score submitters
- Real-time updates using WebSockets
- Detailed statistics tracking
- Player profiles and team information
- Tournament brackets and schedules
- Historical match data
The score submission page would need a secure admin interface with validation rules to ensure accurate data entry. Would you like more details on any specific component?