A clean and test-driven REST API for an online store built with Django, Django REST Framework, and Docker Compose.
This project follows the TDD (Test-Driven Development) approach and supports full CRUD operations for Product resources.
- Django 5.x + DRF
- RESTful CRUD for Products
- Fully containerized with Docker Compose
- TDD setup with
pytest - Simple Makefile-based workflow
- MySQL-backed data persistence
.
├── src/
│ ├── backend/ # Django project
│ └── store/ # App for managing products
├── docker-compose.yml
├── Makefile # Developer commands
├── requirements.txt
└── .env
Create a .env file:
DB_NAME=store_db
DB_USER=store_user
DB_PASSWORD=store_pass
DB_ROOT_PASSWORD=rootpass
DJANGO_SETTINGS_MODULE=backend.settingsmake composeThis will:
- Stop and remove any old containers
- Rebuild everything
- Start the application on http://localhost:8000
make testRuns the test suite using pytest inside the container.
All endpoints are prefixed with /api/.
| Method | Endpoint | Description |
|---|---|---|
| GET | /products/ |
List all products |
| POST | /products/ |
Create a product |
| GET | /products/<id>/ |
Get single product |
| PUT | /products/<id>/ |
Update a product |
| DELETE | /products/<id>/ |
Delete a product |
{
"name": "Laptop",
"price": "999.99"
}All features are written starting from tests first using pytest + Django DB fixtures.
Example:
def test_create_product():
response = client.post('/api/products/', {"name": "Phone", "price": "499.99"})
assert response.status_code == 201- Edit code →
make compose - Write a failing test →
make test - Make it pass → commit!
- Repeat 💡
- Python 3.10
- Django 5.x
- Django REST Framework
- MySQL 8
- Pytest
- Docker Compose
- Makefile
MIT — Use it freely, improve it responsibly.