# Comprehensive E-Commerce Platform A full-featured e-commerce API built with FastAPI and SQLite, designed to provide all the backend functionality needed for a modern online store. ## Features - **User Management** - User registration and authentication with JWT - Role-based access control (Customer, Seller, Admin) - User profiles with address information - Password reset functionality - **Product Management** - CRUD operations for products - Multiple product images - SKU and barcode support - Inventory tracking - Digital and physical product support - **Category & Tag Management** - Hierarchical category structure - Product tagging system - SEO-friendly slugs - **Shopping Cart** - Add, update, remove items - Custom product attributes/options - Persistent cart for registered users - **Order Processing** - Order creation from cart - Order status tracking - Order history - Address management for shipping/billing - **Payment Integration** - Multiple payment method support - Payment status tracking - Refund handling - Mock implementations for Stripe and PayPal - **Inventory Management** - Stock level tracking - Low stock alerts - Stock update APIs - **Search & Filtering** - Advanced product search - Sorting and filtering options - Relevance-based results - **Reviews & Ratings** - User product reviews - Rating system - Verified purchase badges - **Admin Dashboard** - Sales analytics - Customer insights - Product performance metrics - Order management - **Security** - Rate limiting - Security headers - Input validation - Error handling ## Tech Stack - **Framework**: FastAPI - **Database**: SQLite with SQLAlchemy ORM - **Migration**: Alembic - **Authentication**: JWT with Python-JOSE - **Validation**: Pydantic - **Linting**: Ruff - **Logging**: Python's built-in logging with rotation ## Installation ### Prerequisites - Python 3.10 or higher - pip (Python package manager) ### Setup 1. Clone the repository: ```bash git clone https://github.com/yourusername/comprehensiveecommerceplatform.git cd comprehensiveecommerceplatform ``` 2. Create a virtual environment: ```bash python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate ``` 3. Install dependencies: ```bash pip install -r requirements.txt ``` 4. Initialize the database: ```bash python -m app.utils.db_init ``` ## Running the Application Start the application with: ```bash uvicorn main:app --reload ``` The API will be available at http://localhost:8000. - Interactive API documentation: http://localhost:8000/docs - Alternative API documentation: http://localhost:8000/redoc - Health check endpoint: http://localhost:8000/health ## API Documentation The API is fully documented with OpenAPI. You can explore the documentation using the interactive Swagger UI at `/docs` or ReDoc at `/redoc`. ### Authentication Most endpoints require authentication using JSON Web Tokens (JWT). To authenticate: 1. Register a user using the `/api/auth/register` endpoint 2. Login using the `/api/auth/login` endpoint 3. Use the returned access token in the Authorization header: `Authorization: Bearer {your_access_token}` ### Default Admin Account A default admin account is created when you initialize the database: - Email: admin@example.com - Password: admin ## Development ### Project Structure ``` / ├── app/ # Application package │ ├── core/ # Core functionality │ │ ├── config.py # Application settings │ │ ├── database.py # Database connection │ │ └── security.py # Security utilities │ ├── dependencies/ # FastAPI dependencies │ ├── middlewares/ # Custom middlewares │ ├── models/ # SQLAlchemy models │ ├── routers/ # API routes │ ├── schemas/ # Pydantic schemas │ ├── services/ # Business logic services │ └── utils/ # Utility functions ├── migrations/ # Alembic migrations ├── scripts/ # Utility scripts ├── main.py # Application entry point ├── requirements.txt # Dependencies ├── alembic.ini # Alembic configuration └── pyproject.toml # Project configuration ``` ### Database Migrations The project uses Alembic for database migrations. The initial migration is already set up. To create a new migration after making changes to the models: ```bash alembic revision --autogenerate -m "Description of changes" ``` To apply migrations: ```bash alembic upgrade head ``` ### Adding New Features When adding new features: 1. Define models in `app/models/` 2. Create Pydantic schemas in `app/schemas/` 3. Implement business logic in `app/services/` 4. Create API endpoints in `app/routers/` 5. Register new routers in `main.py` 6. Generate and apply database migrations ### Code Quality Run linting and formatting with: ```bash ./scripts/lint.sh ``` ## Deployment ### Production Configuration For production deployment: 1. Set up a proper database (e.g., PostgreSQL) by updating the connection settings in `app/core/config.py` 2. Configure proper authentication for production in `app/core/config.py` 3. Update CORS settings in `main.py` to restrict allowed origins 4. Set up a reverse proxy (e.g., Nginx) in front of the application 5. Configure HTTPS ### Docker Deployment A Dockerfile is included for containerized deployment: ```bash docker build -t ecommerce-api . docker run -p 8000:8000 ecommerce-api ``` ## License This project is licensed under the MIT License - see the LICENSE file for details. ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add some amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request