Full-stack ecommerce project with a Django REST backend and a React + Vite frontend.
This project now runs with:
- Django 6 + Django REST Framework
- JWT authentication with
djangorestframework-simplejwt - React 19 + React Router + Vite
- Tailwind CSS + Framer Motion
- SQLite by default, with PostgreSQL-ready settings support
ecommerce/
├─ backend/
│ ├─ core/ # Django settings and root URLs
│ ├─ users/ # auth, profile, admin user APIs
│ ├─ products/ # product models, product APIs, product seeding
│ ├─ cart/ # cart APIs
│ ├─ orders/ # order APIs
│ ├─ db.sqlite3 # default local database
│ └─ manage.py
├─ frontend/
│ ├─ src/
│ │ ├─ api/ # axios client and API service layer
│ │ ├─ app/ # router setup
│ │ ├─ components/ # reusable UI sections
│ │ ├─ contexts/ # auth context
│ │ ├─ hooks/ # API hooks
│ │ ├─ pages/ # user/admin route pages
│ │ └─ data/db.json # legacy product source used for backend seeding
│ └─ package.json
└─ README.md
backend/core/settings.py- Django app setup
- CORS configuration
- JWT auth config
- SQLite default database
backend/users/- register, login, profile, admin user management
backend/products/- product catalog
- image handling
- legacy product import command
backend/cart/- add/update/remove cart items for logged-in users
backend/orders/- create orders from the live cart
- reduce stock on order creation
- cancel orders and restore stock
frontend/src/api/apiService.js- central axios client
- JWT attach/refresh flow
- all API helpers
frontend/src/contexts/AuthContext.jsx- frontend auth state
frontend/src/app/router.jsx- route tree
- lazy-loaded pages
frontend/src/pages/user/- storefront, product page, cart, profile, auth pages
frontend/src/pages/admin/- admin dashboard, products, users, orders
frontend/src/components/OrderPage/Checkout.jsx- checkout form using live cart/order APIs
frontend/src/components/OrderPage/OrderConfirmation.jsx- fetches and shows the real created order
Base URL:
http://127.0.0.1:8000/api/
POST /register/POST /login/POST /token/refresh/GET /profile/PATCH /profile/GET /admin/users/PATCH /admin/users/:id/DELETE /admin/users/:id/
GET /products/POST /products/GET /products/:slug/PUT /products/:slug/PATCH /products/:slug/DELETE /products/:slug/POST /products/bulk/
GET /cart/POST /cart/PATCH /cart/:id/DELETE /cart/:id/DELETE /cart/clear/
GET /orders/POST /orders/GET /orders/:id/PATCH /orders/:id/cancel/GET /admin/orders/PATCH /admin/orders/:id/
- User registers or logs in from the frontend.
- Backend returns
user+ JWT tokens. - Frontend stores
access_token,refresh_token, andcurrentUser. - Axios attaches the access token automatically.
- On
401, the frontend refreshes the token and retries once.
- Store and search UI call
getProducts(). - Django returns products with nested images.
- Admin product forms send product updates back through the same API layer.
- Product page sends
product_id,quantity,storage, andram. - Backend validates stock and creates or updates the cart item.
- Cart and checkout read from
/api/cart/.
- Checkout submits shipping and payment info.
- Backend reads the authenticated user’s cart.
- Backend creates the order and order items.
- Backend reduces stock and clears the cart.
- Frontend redirects to the confirmation page and loads the real order.
cd backend
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python manage.py migrate
python manage.py seed_products --replace
python manage.py runservercd frontend
npm install
npm run devFrontend default dev URL:
http://127.0.0.1:5173
Backend default dev URL:
http://127.0.0.1:8000
The old frontend product catalog can be imported into Django with:
cd backend
python manage.py seed_products --replaceThis reads:
frontend/src/data/db.json
A repeatable test command now exists:
cd backend
python manage.py load_test_users --users 50What it does:
- registers 50 temporary users
- logs each one in
- fetches products
- adds an item to cart
- places an order
- fetches the user’s orders
- cleans up created users and temporary test product after the run
Keep generated data if needed:
python manage.py load_test_users --users 50 --keep-dataLatest successful run:
50/50users passed- total run time: about
113s - average per user: about
2.26s - product, cart, and order endpoints stayed fast
- register/login were the slowest steps at about
1.1seach on local machine
Important note:
- this is a sequential smoke/load test, not a true distributed concurrency benchmark
- it is useful for breakage detection and rough local performance validation
Backend:
cd backend
python manage.py check
python manage.py migrate
python manage.py load_test_users --users 50Frontend:
cd frontend
npm run buildbackend/core/settings.pynow includestestserverinALLOWED_HOSTSso Django APIClient and automated smoke tests work correctly.- If products look empty, seed them again with
python manage.py seed_products --replace. - The frontend build currently passes, but there is still a large vendor chunk warning from Vite.
- Tailwind config still has a noisy content-pattern warning that can be cleaned up in a later optimization pass.
- JWT emitted a warning during the load test because the current development
SECRET_KEYis shorter than the recommended 32 bytes for SHA-256 signing. For production, replace it with a longer secure secret.
- move secrets and DB settings to real environment loading for production
- trim unused legacy files under
frontend/backend/andfrontend/src/data/ - add proper backend unit tests per app in addition to the smoke/load command
- add route-level or component-level error boundaries in the frontend
- reduce frontend vendor bundle size further