A backend REST API using MongoDB Atlas, Neo4j, and Redis Cloud running in Docker.
- Docker Desktop installed and running
- MongoDB Atlas account
- Neo4j AuraDB account
- Redis Cloud account
1. Clone the repo
git clone https://github.com/yourteam/ecommerce-api.git
cd ecommerce-api2. Configure environment
cp .env.example .envOpen .env and fill in your credentials:
PORT=3000
MONGO_URI=mongodb+srv://<user>:<password>@cluster.mongodb.net/ecommerce?retryWrites=true&w=majority
NEO4J_URI=neo4j+s://<your-instance>.databases.neo4j.io
NEO4J_USER=<your-username>
NEO4J_PASSWORD=<your-password>
REDIS_URL=redis://:<password>@<host>:<port>3. Seed MongoDB
Open MongoDB Compass → connect to your Atlas cluster → open the MongoShell tab at the bottom and paste the contents of scripts/seed.mongo.js, then press Enter.
4. Generate product embeddings
npm install
node ./scripts/generateEmbeddings.js5. Seed Neo4j and Redis
node ./scripts/seed.js6. Start the API
docker compose up --buildAPI runs at http://localhost:3000
| Method | Endpoint | Description |
|---|---|---|
| GET | /products/:id | Get product (Redis cache then MongoDB) |
| GET | /products/top-selling | Top 5 products by units sold |
| GET | /products/revenue-by-category | Revenue grouped by category |
| GET | /home | Home page data, cached 5 mins in Redis |
| POST | /orders | Place an order |
| GET | /recommendations/:userId | Neo4j graph recommendations |
| GET | /similar/:productId | Similar products by vector search |
| POST | /similar/by-image | Similar products from a text description |
| GET | /cart/:userId | Get cart |
| POST | /cart/:userId/add | Add item to cart |
| DELETE | /cart/:userId | Clear cart |
Place an order
POST /orders
{
"userId": "user1",
"items": [
{ "productId": "<productId>", "quantity": 1, "price": 79.99 }
]
}Add to cart
POST /cart/user1/add
{
"productId": "<productId>",
"quantity": 2,
"price": 39.99
}Search by image description
POST /similar/by-image
{
"description": "wireless audio device for music"
}docker compose down