A comprehensive backend API for the SOKOGO classifieds platform, supporting user authentication and item listings.
- User Authentication: Register, login, and JWT-based authentication
- Item Management: Create, read, update, delete classifieds listings
- Search & Filtering: Advanced search and filtering capabilities
- Category Support: Motors, Property, and Electronics categories
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM for MongoDB
- JWT - Authentication
- bcrypt - Password hashing
- CORS - Cross-origin resource sharing
- Clone the repository:
git clone <repository-url>
cd sokogo_backend- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
mongoUrl=mongodb://localhost:27017/sokogo_backend
key=sokogo_secret_key_2024
port=8080- Start the server:
# Development mode
npm run server
# Production mode
npm startPOST /api/auth/register- Register a new userPOST /api/auth/login- Login userGET /api/auth/users- Get all users (with pagination and filtering)GET /api/auth/users/:userId- Get user by ID
GET /api/items- Get all items with filteringGET /api/items/:itemId- Get item by IDGET /api/items/popular/:category- Get popular items by categoryPOST /api/items- Create new item (authenticated)POST /api/items/bulk- Create multiple items (authenticated)PUT /api/items/:itemId- Update item (authenticated)DELETE /api/items/:itemId- Delete item (authenticated)GET /api/items/seller/my-items- Get user's items (authenticated)
{
firstName: String,
lastName: String,
email: String (unique),
phoneNumber: String,
password: String (hashed),
role: String (buyer|seller|admin, default: buyer),
createdAt: Date
}{
title: String,
description: String,
category: String (MOTORS|PROPERTY|ELECTRONICS),
subcategory: String,
price: Number,
currency: String,
location: {
district: String,
city: String,
address: String
},
images: [String],
seller: ObjectId (ref: User),
status: String (ACTIVE|SOLD|EXPIRED|SUSPENDED),
features: Object,
contactInfo: {
phone: String,
email: String
}
}The API uses User ID authentication. Include the user ID in the request headers:
userid: <your_user_id>
or
user-id: <your_user_id>
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"phoneNumber": "+250123456789",
"password": "password123",
"role": "seller"
}'curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123"
}'curl -X POST http://localhost:8080/api/items \
-H "Content-Type: application/json" \
-H "userid: <your_user_id>" \
-d '{
"title": "Kia Sorento DLX AWD",
"description": "Excellent condition SUV",
"category": "MOTORS",
"subcategory": "CARS",
"price": 12000000,
"location": {
"district": "Kigali",
"city": "Kigali",
"address": "Kabeza"
},
"features": {
"brand": "Kia",
"model": "Sorento",
"year": 2016,
"mileage": 82100,
"fuelType": "Petrol",
"transmission": "Automatic"
}
}'mongoUrl: MongoDB connection URLkey: Secret key for JWT token generationport: Port number for the server
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the ISC License.