Features β’ Tech Stack β’ Getting Started β’ API Documentation β’ Project Structure
A production-ready e-commerce backend system built with FastAPI that provides secure user authentication, comprehensive product management, shopping cart functionality, and order processing capabilities. Designed with scalability, security, and modularity at its core.
- Secure Authentication: JWT-based authentication with OAuth2 password flow and bcrypt password hashing
- Role-Based Access Control: Separate admin and user permissions for resource management
- Complete E-commerce Flow: From product browsing to order placement
- Database Migrations: Alembic integration for seamless schema versioning
- RESTful API Design: Clean, intuitive endpoints following REST conventions
- User registration and login with hashed password storage
- JWT access token generation and validation
- Protected routes with role-based access control
- Full CRUD operations for products (admin only)
- Public product catalog with search and filtering capabilities
- Detailed product information retrieval
- Add, update, and remove cart items
- Price tracking at time of addition
- Persistent cart across sessions
- Place orders directly from cart
- Order status tracking and history
- User-specific order management
| Component | Technology |
|---|---|
| Framework | FastAPI |
| Database | PostgreSQL |
| ORM | SQLAlchemy |
| Authentication | JWT + OAuth2 |
| Password Hashing | Passlib (bcrypt) |
| Migrations | Alembic |
| Configuration | Pydantic Settings |
| Environment | Python 3.9+ Virtual Environment |
Ensure you have the following installed on your system:
- Python 3.9 or higher
- PostgreSQL 12 or higher
- pip (Python package manager)
- virtualenv or venv
- Clone the repository
git clone https://github.com/Achal13jain/Ecommerce_backend.git
cd Ecommerce_backend
- Create and activate virtual environment
Windows
python -m venv venv
venv\Scripts\activate
Linux/MacOS
python3 -m venv venv
source venv/bin/activate
- Install dependencies
pip install -r requirements.txt
- Configure environment variables
Create a .env file in the root directory:
DATABASE_URL=postgresql://username:password@localhost:5432/ecommerce_db
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
- Initialize database
Create database
createdb ecommerce_db
Run migrations
alembic upgrade head
- Run the application
uvicorn app.main:app --reload
The API will be available at http://localhost:8000.
Once the server is running, access the interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
POST /auth/signup- Register new userPOST /auth/signin- User login (returns JWT token)
GET /products- List all products (public)GET /products/{id}- Get product details (public)POST /products- Create product (admin only)PUT /products/{id}- Update product (admin only)DELETE /products/{id}- Delete product (admin only)
GET /cart- View cart itemsPOST /cart- Add item to cartPUT /cart/{id}- Update cart item quantityDELETE /cart/{id}- Remove item from cart
POST /orders- Place order from cartGET /orders- View order historyGET /orders/{id}- Get order details
Ecommerce_backend/
βββ app/
β βββ init.py
β βββ main.py # Application entry point
β βββ config.py # Configuration settings
β βββ database.py # Database connection
β βββ models/ # SQLAlchemy models
β β βββ user.py
β β βββ product.py
β β βββ cart.py
β β βββ order.py
β βββ schemas/ # Pydantic schemas
β β βββ user.py
β β βββ product.py
β β βββ cart.py
β β βββ order.py
β βββ routers/ # API route handlers
β β βββ auth.py
β β βββ products.py
β β βββ cart.py
β β βββ orders.py
β βββ utils/ # Utility functions
β βββ auth.py # JWT & password hashing
β βββ dependencies.py # Dependency injection
βββ alembic/ # Database migrations
β βββ versions/
β βββ env.py
βββ tests/ # Unit and integration tests
βββ .env.example # Environment variables template
βββ .gitignore
βββ alembic.ini # Alembic configuration
βββ requirements.txt # Python dependencies
βββ README.md
- Password hashing using bcrypt algorithm
- JWT token-based authentication with expiration
- Protected routes with dependency injection
- SQL injection prevention via SQLAlchemy ORM
- Environment-based configuration management
- Payment gateway integration (Stripe/PayPal)
- Email notification system
- Product image upload and storage
- Advanced filtering and search
- Rate limiting and throttling
- Redis caching layer
- Docker containerization
- CI/CD pipeline setup
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a 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
Please ensure your code follows the existing style and includes appropriate tests.
Achal Jain
- GitHub: @Achal13jain
- Repository: Ecommerce_backend
- FastAPI documentation and community
- SQLAlchemy ORM framework
- JWT authentication best practices