A comprehensive backend API service for managing cricket player forms, achievements, and statistics.
- Overview
- Features
- Tech Stack
- Project Structure
- API Endpoints
- Data Models
- Setup and Installation
- Environment Variables
- Running the Application
- Testing
- Deployment
- Security Features
- Error Handling
This project provides a robust backend service for tracking cricket players' performance metrics, managing their profiles, and analyzing their form over time. It offers comprehensive API endpoints for creating, reading, updating, and deleting player information along with authentication and authorization capabilities.
- Player Management: CRUD operations for player profiles
- Authentication & Authorization: Secure routes with JWT token-based authentication
- Form Statistics: Track and analyze player performance metrics
- Career Achievements: Record notable accomplishments and milestones
- Search & Filter: Advanced query capabilities for searching players
- Data Validation: Strong validation for all incoming data
- Error Handling: Comprehensive error responses with appropriate status codes
- Logging: Detailed logging for debugging and monitoring
- Node.js: JavaScript runtime
- Express.js: Web application framework
- MongoDB: NoSQL database for data storage
- Mongoose: ODM library for MongoDB
- JWT: JSON Web Tokens for authentication
- Bcrypt: Password hashing
- Joi: Data validation
- Morgan: HTTP request logger
- Winston: Application logger
- Jest: Testing framework
player-form-cc/
├── controllers/ # Route controllers
├── middlewares/ # Custom middleware functions
├── models/ # Mongoose models
├── routes/ # API routes
├── services/ # Business logic
├── utils/ # Utility functions
├── config/ # Configuration files
├── tests/ # Test files
├── logs/ # Application logs
├── .env # Environment variables
└── server.js # Entry point
POST /api/auth/register
- Register a new userPOST /api/auth/login
- Login and get access tokenGET /api/auth/profile
- Get user profilePUT /api/auth/profile
- Update user profile
GET /api/players
- Get all playersGET /api/players/:id
- Get player by IDPOST /api/players
- Create a new playerPUT /api/players/:id
- Update player by IDDELETE /api/players/:id
- Delete player by ID
GET /api/players/:id/stats
- Get player statisticsPOST /api/players/:id/stats
- Add player statisticsPUT /api/players/:id/stats/:statId
- Update player statisticsDELETE /api/players/:id/stats/:statId
- Delete player statistics
GET /api/players/:id/achievements
- Get player achievementsPOST /api/players/:id/achievements
- Add player achievementPUT /api/players/:id/achievements/:achievementId
- Update player achievementDELETE /api/players/:id/achievements/:achievementId
- Delete player achievement
{
username: String,
email: String,
password: String,
role: String,
createdAt: Date,
updatedAt: Date
}
{
name: String,
dateOfBirth: Date,
nationality: String,
playerType: String,
battingStyle: String,
bowlingStyle: String,
teams: [String],
stats: [StatisticsSchema],
achievements: [AchievementSchema],
createdAt: Date,
updatedAt: Date
}
{
format: String,
matches: Number,
runs: Number,
average: Number,
strikeRate: Number,
centuries: Number,
fifties: Number,
wickets: Number,
economyRate: Number,
year: Number
}
{
title: String,
description: String,
date: Date,
tournament: String
}
-
Clone the repository:
git clone https://github.com/yourusername/player-form-cc.git cd player-form-cc
-
Install dependencies:
npm install
-
Set up environment variables (see Environment Variables)
-
Start MongoDB:
mongod --dbpath /path/to/data/directory
Create a .env
file in the root directory with the following variables:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/player-form
JWT_SECRET=your_jwt_secret_key
NODE_ENV=development
LOG_LEVEL=info
npm run dev
npm start
npm test
docker build -t player-form-api .
docker run -p 3000:3000 player-form-api
The project uses GitHub Actions for CI/CD pipeline, automatically running tests and deploying to production when merging to the main branch.
- Password hashing with bcrypt
- JWT for secure authentication
- CORS protection
- Rate limiting to prevent brute force attacks
- Input validation and sanitization
- Environment variable protection
- Helmet.js for HTTP security headers
The API uses a standardized error response format:
{
"status": "error",
"code": 400,
"message": "Validation error",
"errors": ["Field 'name' is required"]
}
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.