A robust and scalable RESTful API built with FastAPI for managing an e-commerce platform. This backend handles product catalogs, user authentication, shopping carts, order processing, and more.
- User Management: Secure user registration, login, and profile management using JWT authentication and Argon2 hashing.
- Product Catalog: Manage products and categories with support for hierarchical structures.
- Shopping Cart: Full-featured shopping cart functionality (add, remove, update items).
- Order Processing: comprehensive order lifecycle management from creation to completion.
- Payments: Integration ready for payment processing (Data models included).
- Reviews: Product review and rating system.
- Address Management: Manage user shipping and billing addresses.
- Database: SQL-based persistence using SQLAlchemy ORM with Alembic for migrations.
- Monitoring: Integrated Sentry for error tracking and performance monitoring.
- Documentation: Interactive API documentation via Swagger UI and ReDoc.
- Framework: FastAPI
- Language: Python 3.10+
- Database ORM: SQLAlchemy
- Migrations: Alembic
- Validation: Pydantic
- Authentication: PyJWT, Argon2-cffi
- Server: Uvicorn
- Logging: Loguru
- Python 3.10 or higher
- Git
-
Clone the repository
git clone https://github.com/yourusername/fastapi-ecommerce.git cd fastapi-ecommerce -
Create a 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. You can use the following template:DATABASE_URL=sqlite:///./ecommerce.db SECRET_KEY=your_super_secret_key ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 # Add other necessary variables
Initialize the database and apply migrations:
# Apply existing migrations
alembic upgrade headStart the development server using Uvicorn:
uvicorn app.main:app --reloadThe API will be available at http://127.0.0.1:8000/api/v1.
If you prefer using Poetry for dependency management:
-
Install dependencies
poetry install
-
Environment Configuration
Ensure you have created the
.envfile as described in the Installation section. -
Run the application
poetry run uvicorn app.main:app --reload
You can also run the application using Docker.
-
Build the image
docker build -t fastapi-ecommerce . -
Run the container
docker run -d -p 8000:8000 fastapi-ecommerce
Once the application is running, you can access the interactive documentation:
- Swagger UI: http://127.0.0.1:8000/api/v1/docs
- ReDoc: http://127.0.0.1:8000/api/v1/redoc
fastapi-ecommerce/
├── alembic/ # Database migrations
├── app/
│ ├── api/ # API route handlers
│ ├── core/ # Core configuration (config, security)
│ ├── crud/ # CRUD operations
│ ├── db/ # Database connection and session
│ ├── middleware/ # Custom middlewares
│ ├── models/ # SQLAlchemy database models
│ ├── schema/ # Pydantic schemas (request/response)
│ ├── services/ # Business logic
│ ├── utils/ # Utility functions
│ └── main.py # Application entry point
├── tests/ # Test suite
├── .env # Environment variables
├── .gitignore
├── alembic.ini # Alembic configuration
├── docker-compose.yml # Docker composition (if applicable)
├── Dockerfile
├── requirements.txt # Python dependencies
└── README.md
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Yonas Mekonnen - Portfolio - myonas886@gmail.com