6.0 KiB
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
-
Clone the repository:
git clone https://github.com/yourusername/comprehensiveecommerceplatform.git cd comprehensiveecommerceplatform
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Initialize the database:
python -m app.utils.db_init
Running the Application
Start the application with:
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:
- Register a user using the
/api/auth/register
endpoint - Login using the
/api/auth/login
endpoint - 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:
alembic revision --autogenerate -m "Description of changes"
To apply migrations:
alembic upgrade head
Adding New Features
When adding new features:
- Define models in
app/models/
- Create Pydantic schemas in
app/schemas/
- Implement business logic in
app/services/
- Create API endpoints in
app/routers/
- Register new routers in
main.py
- Generate and apply database migrations
Code Quality
Run linting and formatting with:
./scripts/lint.sh
Deployment
Production Configuration
For production deployment:
- Set up a proper database (e.g., PostgreSQL) by updating the connection settings in
app/core/config.py
- Configure proper authentication for production in
app/core/config.py
- Update CORS settings in
main.py
to restrict allowed origins - Set up a reverse proxy (e.g., Nginx) in front of the application
- Configure HTTPS
Docker Deployment
A Dockerfile is included for containerized deployment:
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request