RESTful API for managing users, brands, products, and sales in a grocery store context.
This is an API built for a selling and inventory management system that allows you to manage users, brands, products and sales in a simple way. It's designed to help my mom's grocery store track inventory and record sales efficiently.
- Users: Create and list users in the system.
- Brands: Create brands associated with a user. Brands are shared across all users (any user can see and use any brand).
- Products: Create products linked to any brand, list them, get one, or update stock.
- Sales: Register sales with multiple products. Stock is automatically decremented when a sale is created.
- Node.js: v22.20.0 or higher
- MongoDB: v6.0 or higher (local or cloud instance)
- NPM: Comes with Node.js
- Clone the repository:
$ git clone <repository-url>- Install dependencies:
$ npm installDefine the following environment variables in a .env file:
| Variable | Description | Default |
|---|---|---|
| PORT | Server port number | 3000 |
| API_PREFIX | API URL prefix | api |
| MONGODB_URI | MongoDB connection string | mongodb://localhost:27017 |
Example .env file:
PORT=3000
API_PREFIX=api
MONGODB_URI=mongodb://localhost:27017Start the development server:
$ npm run start:devThe API will be available at http://localhost:3000/api.
For production:
$ npm start- Docker: v24.0 or higher
- Docker Compose: v2.0 or higher (included with Docker Desktop)
- Clone the repository:
$ git clone <repository-url>- Create a
.envfile (optional — defaults will be used):
PORT=3000
API_PREFIX=api
MONGODB_URI=mongodb://mongo:27017- Start the API and MongoDB:
$ docker compose up -dThe API will be available at http://localhost:3000/api and MongoDB at localhost:27017.
| Command | Description |
|---|---|
docker compose up -d |
Start all services in detached mode |
docker compose up |
Start and show logs |
docker compose down |
Stop all services |
docker compose down -v |
Stop and remove volumes (data loss!) |
docker compose build |
Rebuild the API image |
docker compose logs -f |
Follow logs |
docker compose logs -f api |
Follow API logs only |
docker compose restart |
Restart all services |
When using Docker Compose, the following environment variables are used:
| Variable | Default | Description |
|---|---|---|
| PORT | 3000 | Server port |
| API_PREFIX | api | API URL prefix |
| MONGODB_URI | mongodb://mongo:27017 | MongoDB connection (use mongo hostname) |
If you need to run the container manually:
Build the image:
$ docker build -t sells-inventory-api .Run the container:
$ docker run -p 3000:3000 -e MONGODB_URI=mongodb://host.docker.internal:27017 sells-inventory-apiNote: On Windows, use
host.docker.internalto connect to MongoDB running locally.
Full API documentation is available in api.md, which includes:
- All available endpoints
- Request/response formats
- Request examples
- Error responses
Contributions are welcome! To get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to run tests before submitting (npm run test).
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Developed with ❤️ by Enmanuel Ferrer