A comprehensive platform for car auctions where dealers can register, list cars, create auctions, and place bids.
- System Overview
- Features
- System Flow
- Prerequisites
- Environment Setup
- Local Setup
- API Documentation
- Branching & PR Flow
- Development Guidelines
- Testing
The Car Auction System is a platform that enables car dealers to list their vehicles for auction and participate in bidding on other dealers' vehicles. The system follows a microservice-like architecture with clear separation of concerns between different components.
- User: Represents dealers and administrators in the system
- Car: Represents vehicles that can be listed for auction
- Auction: Represents an auction event for a specific car
- Bid: Represents a bid placed by a user on an auction
User (Dealer) --owns--> Car --listed in--> Auction <--places bid on-- User (Bidder)
|
v
Bid
The system follows a layered architecture:
- Routes Layer: Handles HTTP requests and routes them to appropriate controllers
- Controller Layer: Processes requests, validates input, and coordinates with services
- Service Layer: Contains business logic and interacts with models
- Model Layer: Represents data structures and interacts with the database
- User Registration: Dealers can register with name, email, and password
- User Authentication: JWT-based authentication system
- Role-Based Access Control: Different permissions for dealers and administrators
- Car Registration: Dealers can register their cars with details like make, model, year, price
- Car Listing: View all available cars or filter by various criteria
- Car Ownership: Only the owner can update or delete their cars
- Auction Creation: Create auctions for cars with starting price and time period
- Auction Lifecycle: Auctions progress through draft, upcoming, active, and completed states
- Auction Updates: Modify auction details while in draft state
- Bid Placement: Place bids on active auctions
- Bid History: View all bids placed on an auction
- Winning Determination: Highest bid at auction end wins
- Registration: User registers with name, email, and password
- Authentication: User logs in with email and password to receive JWT token
- Authorization: Token is used for accessing protected resources
- Creation: Dealer creates a car with details (make, model, year, price, etc.)
- Management: Dealer can update or delete their cars (if not in auction)
- Listing: Cars can be listed and filtered by various criteria
- Creation: Dealer creates an auction for a car (status: draft)
- Configuration: Dealer sets starting price, start time, and end time
- Activation: Auction is started, changing status to upcoming or active
- Progression: Auction automatically transitions from upcoming to active based on time
- Completion: Auction ends at the specified end time
- Placement: Users place bids on active auctions (must be higher than current highest bid)
- Tracking: System tracks all bids and updates highest bid
- Winning: At auction end, highest bidder wins the auction
- Settlement: Car ownership is transferred to the winning bidder
- Node.js version v18+ and
npm install - MongoDB Atlas connection string in
.env - GitHub repo access
- VS Code with ESLint and Prettier extensions
Refer to the .env.sample file for local setup:
PORT=5000
MONGO_URI=mongodb+srv://<username>:<password>@cluster0.az8oejc.mongodb.net/
JWT_SECRET=your_jwt_secret
JWT_EXPIRY=1h
Replace <username> and <password> with your credentials.
-
Clone the repository:
git clone https://github.com/vaibhav123-dev/Car-Auction-System.git
-
Navigate to the project directory:
cd Car-auction-system -
Install dependencies:
npm install
- If you encounter
ERESOLVEerrors, use:npm install --legacy-peer-deps
- If you encounter
-
Install Husky hooks:
npm run prepare
-
Copy
.env.sampleto.envand fill in the required values:MONGO_URI,JWT_SECRET, etc.
-
Start the development server:
npm run dev
This will start the server with
nodemon(seepackage.jsonfor details).
All API endpoints are prefixed with: /api/v1
Most endpoints require authentication via JWT token:
Authorization: Bearer <your-token>
POST /user/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "Password123!"
}
POST /user/login
Content-Type: application/json
{
"email": "john.doe@example.com",
"password": "Password123!"
}
POST /user/logout
Authorization: Bearer <your-token>
POST /car
Content-Type: application/json
Authorization: Bearer <your-token>
{
"make": "Toyota",
"model": "Camry",
"year": 2020,
"price": 25000,
"description": "Well maintained sedan",
"images": ["image1.jpg", "image2.jpg"]
}
GET /car/<car-id>
Authorization: Bearer <your-token>
GET /car
Authorization: Bearer <your-token>
GET /car/my-cars
Authorization: Bearer <your-token>
PUT /car/<car-id>
Content-Type: application/json
Authorization: Bearer <your-token>
{
"price": 28000
}
DELETE /car/<car-id>
Authorization: Bearer <your-token>
POST /auction
Content-Type: application/json
Authorization: Bearer <your-token>
{
"carId": "<valid-car-id>",
"startingPrice": 20000,
"startTime": "2025-10-10T10:00:00Z",
"endTime": "2025-10-15T10:00:00Z"
}
POST /auction/<auction-id>/start
Authorization: Bearer <your-token>
GET /auction/<auction-id>
Authorization: Bearer <your-token>
GET /auction
Authorization: Bearer <your-token>
PUT /auction/<auction-id>
Content-Type: application/json
Authorization: Bearer <your-token>
{
"startingPrice": 22000,
"startTime": "2025-10-11T10:00:00Z"
}
POST /bid
Content-Type: application/json
Authorization: Bearer <your-token>
{
"auctionId": "<auction-id>",
"amount": 25000
}
GET /bid/auction/<auction-id>
Authorization: Bearer <your-token>
GET /bid/my-bids
Authorization: Bearer <your-token>
- Main Branch: Protected (no direct pushes allowed).
- Feature Branches: Each developer creates a branch from
main:Example:git checkout main git pull origin main git checkout -b feature/<entity>/<short-description>
feature/car/create-model feature/car/create-controller
- After completing the work:
git push origin feature/<entity>/<short-description>
- Open a Pull Request (PR) to
mainand request one reviewer.
- Lint:
npm run lint
- Auto-fix Lint Errors:
npm run lint-fix
- Format Code:
npm run format
- Run Tests:
npm run test
Note: Husky pre-push hooks will run
npm run lint && npm run test.
If your push is blocked, fix linter errors/tests locally, then re-commit and push.
import mongoose from 'mongoose';
const UserSchema = new mongoose.Schema(
{
name: { type: String, required: true },
email: { type: String, required: true },
password: { type: Number, required: true },
},
{ timestamps: true },
);
export default mongoose.model('User', UserSchema);In routes/index.js:
router.use('user', userRoutes);In user.routes.js:
routes.route.post('/register', registerUser);const registerUser = asyncHandler(async (req, res, next) => {
// Validation
// Business logic in service.js file
// You don't need to handle exceptional errors; asyncHandler and errorMiddleware will handle them automatically.
// For validation or logic errors, follow the structure below:
throw new ApiError(HTTP_STATUS.BAD_REQUEST, 'User already exists');
// For responses, follow the structure below:
res.status(HTTP_STATUS.CREATED).json(new ApiResponse(HTTP_STATUS.CREATED, { data }, 'message'));
});const registerService = asyncHandler(async (userData) => {
// Get input for query from controller
// All business and DB query logic, then return the response to the controller
});- Create a JOI validation file in the
validationfolder. - Use this file to validate incoming request payloads in the controller.
The system includes comprehensive unit tests for all components:
- Model Tests: Test schema validation and methods
- Service Tests: Test business logic in isolation
- Controller Tests: Test HTTP request/response handling
- Middleware Tests: Test authentication and error handling
Run unit tests with:
npm testDetailed testing guides are available for each flow:
- User Flow: Registration, login, logout
- Car Flow: Creation, update, retrieval, deletion
- Auction Flow: Creation, start, update, retrieval
- Bid Flow: Placement, retrieval
For detailed testing procedures, refer to:
tests/user-flow-test-guide.mdtests/car-flow-test-guide.mdtests/auction-flow-test-guide.md
- Vaibhav: Project setup, User management
- Shrikant: Car management
- Musadhiek: Auction management
- Kiran: Bid management