Full‑stack shopping cart application built with:
- Django 6 backend exposing JSON APIs
- PostgreSQL (via Docker) for persistence
- React + Vite + TypeScript + Tailwind CSS frontend
- Automated tests, linting and formatting on both ends
- Continuous integration via GitHub Actions
django-shopper/
├─ cart/ # Django app (models, API views, tests)
├─ shopper/ # Project settings and URLs
├─ frontend/ # React/Vite frontend UI
├─ Dockerfile
├─ docker-compose.yml
├─ requirements.txt
└─ .github/workflows/ci.yml
-
Copy configuration
cp .env.example .env # edit .env if needed (secrets, ports) -
Start services (Docker must be running)
docker-compose up --build -d
-
Migrate database
docker-compose run web python manage.py migrate
-
(Optional) Load sample data
docker-compose run web python manage.py loaddata products
-
Create admin user
docker-compose run web python manage.py createsuperuser
-
Run frontend
cd frontend npm install # first time only npm run dev # http://localhost:5173/
The React app proxies /api/* to the Django server on port 8000, so you can hit APIs without CORS.
All endpoints return/accept JSON. No authentication is required.
| Method | Path | Description | Payload example |
|---|---|---|---|
| GET | /api/products/ |
List all products | — |
| POST | /api/products/ |
Create a new product | { "name": "Foo", "price": "9.99" } |
| GET | /api/products/{id}/ |
Retrieve single product | — |
| PUT | /api/products/{id}/ |
Update a product | same as POST |
| DELETE | /api/products/{id}/ |
Delete a product | — |
| POST | /api/cart/add/{product_id}/ |
Add product to current cart | — |
| POST | /api/cart/update/{product_id}/ |
Change quantity in cart | { "quantity": 3 } |
| POST | /api/cart/remove/{product_id}/ |
Remove item from cart | — |
Use curl or the React UI (located at /frontend/src/App.tsx) to exercise these.
- Tests:
docker-compose run web python manage.py test(also executed in CI) - Lint/format:
python -m black .,python -m flake8(see .flake8 config)
npm run lint(ESLint)npm run format:check/npm run format(Prettier)npm run buildproduces static assets for production
These checks are automatically run by the GitHub Actions workflow on every push/PR.
.envcontains database settings and should not be committed.- Use the
USE_SQLITE=Trueenv var when running management commands locally to avoid needing the DB container. - The Django backend no longer serves any HTML; the React frontend handles all user-facing screens.
Happy coding! 🚀