Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

E-commerce API Project

A comprehensive RESTful API for e-commerce product management built with FastAPI, React, and MongoDB.

πŸš€ Overview

This project demonstrates a complete e-commerce API with full CRUD operations for product management. It includes both a robust backend API and a beautiful frontend interface for managing products.

Key Features

  • βœ… Complete CRUD Operations for products
  • βœ… RESTful API Design with proper HTTP methods and status codes
  • βœ… Input Validation with comprehensive error handling
  • βœ… Interactive Documentation with Swagger/OpenAPI
  • βœ… Modern Frontend Interface with React and Tailwind CSS
  • βœ… Real-time Updates and responsive design
  • βœ… Production-ready with proper logging and monitoring

πŸ› οΈ Tech Stack

Backend

  • FastAPI - Modern, fast web framework for building APIs
  • MongoDB - NoSQL database for flexible data storage
  • Pydantic - Data validation and settings management
  • Python 3.9+ - Programming language

Frontend

  • React - JavaScript library for building user interfaces
  • Tailwind CSS - Utility-first CSS framework
  • JavaScript ES6+ - Modern JavaScript features

Infrastructure

  • Docker - Containerization
  • Supervisor - Process management
  • Kubernetes - Container orchestration (production)

πŸ“š API Documentation

Base URL

https://api.example.com/api

Core Endpoints

Method Endpoint Description Status Code
GET /api/health Health check 200
POST /api/products Create product 201
GET /api/products List all products 200
GET /api/products/{id} Get specific product 200
PUT /api/products/{id} Update product 200
DELETE /api/products/{id} Delete product 204
GET /api/products/category/{category} Get products by category 200

Product Model

{
  "id": "uuid-string",
  "name": "string (required, 1-200 chars)",
  "description": "string (required, 1-1000 chars)",
  "price": "float (required, > 0)",
  "category": "string (required, 1-100 chars)",
  "stock_quantity": "integer (required, >= 0)",
  "image_url": "string (optional)",
  "created_at": "datetime",
  "updated_at": "datetime"
}

πŸ”§ API Usage Examples

Create a Product

curl -X POST "https://api.example.com/api/products" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Wireless Bluetooth Headphones",
    "description": "Premium quality wireless headphones with noise cancellation",
    "price": 129.99,
    "category": "Electronics",
    "stock_quantity": 50,
    "image_url": "https://example.com/headphones.jpg"
  }'

Get All Products

curl -X GET "https://api.example.com/api/products"

Get Products with Pagination

curl -X GET "https://api.example.com/api/products?skip=0&limit=10"

Get Product by ID

curl -X GET "https://api.example.com/api/products/{product-id}"

Update a Product

curl -X PUT "https://api.example.com/api/products/{product-id}" \
  -H "Content-Type: application/json" \
  -d '{
    "price": 119.99,
    "stock_quantity": 45
  }'

Delete a Product

curl -X DELETE "https://api.example.com/api/products/{product-id}"

Filter by Category

curl -X GET "https://api.example.com/api/products/category/Electronics"

πŸ–₯️ Frontend Interface

Access the product management interface at:

https://yourapp.example.com

Features

  • Product Listing - View all products with images, prices, and stock status
  • Create Products - Add new products with full form validation
  • Edit Products - Update existing product information
  • Delete Products - Remove products with confirmation dialogs
  • Responsive Design - Works on desktop, tablet, and mobile devices
  • Real-time Updates - UI updates immediately after operations

πŸ—οΈ Project Structure

/app/
β”œβ”€β”€ backend/                    # FastAPI backend
β”‚   β”œβ”€β”€ server.py              # Main FastAPI application
β”‚   β”œβ”€β”€ requirements.txt       # Python dependencies
β”‚   └── .env                   # Environment variables
β”œβ”€β”€ frontend/                  # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.js            # Main React component
β”‚   β”‚   β”œβ”€β”€ App.css           # Component styles
β”‚   β”‚   β”œβ”€β”€ index.js          # Entry point
β”‚   β”‚   └── index.css         # Global styles
β”‚   β”œβ”€β”€ public/               # Static assets
β”‚   β”œβ”€β”€ package.json          # Node.js dependencies
β”‚   β”œβ”€β”€ tailwind.config.js    # Tailwind CSS configuration
β”‚   └── .env                  # Environment variables
β”œβ”€β”€ tests/                    # Test files
β”œβ”€β”€ scripts/                  # Utility scripts
└── README.md                # This file

πŸ” Interactive Documentation

Swagger UI

Access the interactive API documentation at:

https://yourapp.example.com/docs

OpenAPI Schema

Get the OpenAPI JSON schema at:

https://yourapp.example.com/openapi.json

πŸ§ͺ Testing

The project includes comprehensive test coverage:

Backend API Tests

  • βœ… All CRUD operations
  • βœ… Input validation and error handling
  • βœ… Edge cases and concurrent operations
  • βœ… Database integration
  • βœ… Health checks

Frontend Tests

  • βœ… Component rendering
  • βœ… Form interactions
  • βœ… API integration
  • βœ… Error handling
  • βœ… Responsive design

Test Results

All tests pass successfully, confirming:

  • API endpoints work correctly
  • Frontend integrates seamlessly with backend
  • Data persistence across operations
  • Proper error handling and validation

🚦 Status Codes

Code Description
200 Success (GET, PUT)
201 Created (POST)
204 No Content (DELETE)
400 Bad Request (validation errors)
404 Not Found (invalid ID)
422 Unprocessable Entity (validation errors)
500 Internal Server Error

πŸ”§ Development Setup

Prerequisites

  • Python 3.9+
  • Node.js 16+
  • MongoDB
  • Docker (optional)

Local Development

  1. Backend Setup

    cd backend
    pip install -r requirements.txt
    python server.py
  2. Frontend Setup

    cd frontend
    yarn install
    yarn start
  3. Database Setup

    • MongoDB running on mongodb://localhost:27017
    • Database name: ecommerce_db

Environment Variables

Backend (.env)

MONGO_URL=mongodb://localhost:27017
DB_NAME=ecommerce_db

Frontend (.env)

REACT_APP_BACKEND_URL=https://yourapi.example.com

πŸ›‘οΈ Security Features

  • Input validation with Pydantic models
  • SQL injection prevention (NoSQL MongoDB)
  • CORS configuration for cross-origin requests
  • Proper error handling without sensitive data exposure
  • UUID-based IDs (non-sequential, secure)

πŸ“ˆ Performance Features

  • Efficient MongoDB queries with indexing
  • Pagination for large datasets
  • Async/await for non-blocking operations
  • Optimized frontend rendering with React
  • CDN-ready static assets

πŸš€ Production Deployment

The application is containerized and ready for production deployment:

  • Docker containers for both frontend and backend
  • Kubernetes configuration for scalability
  • Supervisor process management for reliability
  • Load balancer ready with proper health checks

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

πŸ“„ License

This project is open source and available under the MIT License.

πŸ†˜ Support

For support and questions:

  • Check the interactive API documentation at /docs
  • Review the test cases for usage examples
  • Examine the frontend implementation for integration patterns

🎯 Next Steps

Potential enhancements for this API:

  • Authentication & Authorization (JWT tokens, user roles)
  • Order Management (shopping cart, checkout process)
  • Payment Integration (Stripe, PayPal)
  • Inventory Management (low stock alerts, batch updates)
  • Search & Filtering (full-text search, advanced filters)
  • Image Upload (file handling, image optimization)
  • Caching (Redis for improved performance)
  • Rate Limiting (API usage controls)
  • Monitoring (logging, metrics, alerting)

Built with ❀️ using FastAPI, React, and MongoDB

About

This project demonstrates a complete e-commerce API with full CRUD operations for product management. It includes both a robust backend API and a beautiful frontend interface for managing products.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages