A comprehensive e-commerce REST API built with Django REST Framework that provides complete functionality for managing products, categories, shopping carts, orders, and user ratings.
- User Management: Custom user model with email-based authentication
- Product Management: CRUD operations for products with categories
- Shopping Cart: Add, update, and manage cart items
- Order Processing: Complete order workflow with status tracking
- Rating System: Product rating and review functionality
- Authentication: JWT-based authentication with registration/login
- Admin Interface: Django admin for backend management
- API Documentation: Auto-generated OpenAPI/Swagger documentation
- Async Tasks: Celery integration for background tasks (email notifications)
- Filtering & Search: Advanced filtering and search capabilities
- Pagination: Built-in pagination for large datasets
- Backend: Django 5.2.1, Django REST Framework
- Database: SQLite (default), easily configurable for PostgreSQL/MySQL
- Authentication: JWT (Simple JWT), Django Allauth
- Task Queue: Celery with Redis
- Documentation: DRF Spectacular (OpenAPI/Swagger)
- Image Handling: Pillow for image uploads
- Email: SMTP email backend
- Monitoring: Django Silk for performance monitoring
- Python 3.8+
- Redis (for Celery)
- Virtual environment (recommended)
-
Clone the repository
git clone <repository-url> cd shopflow-api
-
Create and activate virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Environment Configuration Create a
.envfile in the root directory:SECRET_KEY=your-secret-key-here DEBUG=True EMAIL_HOST_USER=[email protected] EMAIL_HOST_PASSWORD=your-email-password
-
Database Setup
python manage.py makemigrations python manage.py migrate
-
Create Superuser
python manage.py createsuperuser
-
Load Sample Data (Optional)
python manage.py popluate_db
-
Start Redis Server (for Celery)
redis-server
-
Start Celery Worker (in separate terminal)
celery -A E_COM worker --loglevel=info
-
Run Development Server
python manage.py runserver
Once the server is running, access the API documentation at:
- Swagger UI:
http://localhost:8000/api/schema/swagger-ui/ - ReDoc:
http://localhost:8000/api/schema/redoc/ - OpenAPI Schema:
http://localhost:8000/api/schema/
The API uses JWT authentication. To access protected endpoints:
-
Register a new user:
POST /dj-rest-auth/registration/ -
Login:
POST /dj-rest-auth/login/ -
Get JWT Token:
POST /api/token/ -
Include token in requests:
Authorization: Bearer <your-jwt-token>
POST /dj-rest-auth/registration/- User registrationPOST /dj-rest-auth/login/- User loginPOST /dj-rest-auth/logout/- User logoutPOST /api/token/- Get JWT tokenPOST /api/token/refresh/- Refresh JWT token
GET /product/- List all products (with filtering, search, pagination)POST /product/- Create new product (Admin only)GET /product/{id}/- Get product detailsPUT /product/{id}/- Update product (Admin only)DELETE /product/{id}/- Delete product (Admin only)
GET /category/- List all categories (Admin only)POST /category/- Create new category (Admin only)GET /category/{id}/- Get category details (Admin only)PUT /category/{id}/- Update category (Admin only)DELETE /category/{id}/- Delete category (Admin only)
GET /cart/- List all cartsPOST /cart/- Create new cartGET /cart/{id}/- Get cart detailsPUT /cart/{id}/- Update cart (add/remove items)DELETE /cart/{id}/- Delete cart
GET /order/- List orders (filtered by user)GET /order/{id}/- Get order detailsPUT /order/{id}/- Update order status (Admin only)DELETE /order/{id}/- Cancel order (Admin only)
GET /rating/- List all ratingsPOST /rating/- Create new rating (Authenticated users)GET /rating/{id}/- Get rating detailsPUT /rating/{id}/- Update ratingDELETE /rating/{id}/- Delete rating
- Filter by price:
?price=100or?price__gte=50&price__lte=200 - Filter by category:
?category_slug=electronics - Filter by stock:
?stock__gt=0 - Search:
?search=laptop - Ordering:
?ordering=priceor?ordering=-price - In-stock only: Automatically filters in-stock products
- Filter by status:
?status=Confirmed - Filter by date:
?created_at__date=2024-01-01 - Filter by date range:
?created_at__gte=2024-01-01&created_at__lte=2024-12-31
- Create Cart: User creates a new cart with products
- Add Items: Add products to cart with quantities
- Update Cart: Modify quantities or remove items
- Checkout: Set
checked_out=trueto process the cart - Order Creation: System automatically creates order from cart
- Stock Update: Product stock is automatically reduced
- Email Notification: User receives order confirmation email
The system automatically sends email notifications for:
- Order confirmations
- Account registration (console backend in development)
Configure SMTP settings in .env for production email delivery.
- Public: Product listing, product details
- Authenticated: Cart operations, order creation, ratings
- Admin: Product/category management, order management
- Custom user model with email as username
- Fields: username, email, phone_number, first_name, last_name
- Fields: name, description, price, stock, image, category
- Relationships: belongs to category, has many ratings
- Fields: category_name, slug, description, image
- Auto-generates slug from category name
- Fields: user, date_added, checked_out
- Relationships: belongs to user, has many cart items
- Fields: order_id (UUID), user, status, created_at
- Status choices: Pending, Confirmed, Cancelled
- Relationships: belongs to user, has many order items
- Fields: user, product, rating (1-5), review, created_at
- Relationships: belongs to user and product
-
Environment Variables:
DEBUG=False SECRET_KEY=your-production-secret-key ALLOWED_HOSTS=your-domain.com DATABASE_URL=your-database-url REDIS_URL=your-redis-url
-
Database: Configure PostgreSQL or MySQL
-
Static Files: Configure static file serving
-
Media Files: Configure media file storage (AWS S3, etc.)
-
Celery: Deploy with proper process management
-
Security: Enable HTTPS, configure security headers
Access Django Silk profiler at /silk/ for:
- Request/response analysis
- Database query optimization
- Performance bottleneck identification
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Create an issue in the GitHub repository
- Check the API documentation for endpoint details
- Review the Django and DRF documentation
- Initial release with core e-commerce functionality
- JWT authentication
- Product and category management
- Shopping cart and order processing
- Rating system
- Email notifications
- API documentation