Skip to content

Latest commit

 

History

History
169 lines (119 loc) · 4.42 KB

File metadata and controls

169 lines (119 loc) · 4.42 KB

🛒 E-commerce Backend (FastAPI)

A modern, scalable backend API for an E-commerce platform built with Python & FastAPI. This project demonstrates real-world backend architecture — covering authentication, database relationships, payment integration, and RESTful API design.


🚀 Features

User Management

  • User registration & login with JWT authentication
  • Role-based access (Admin, Customer)

Product Management

  • CRUD operations for products
  • Category-based product listing
  • Search & filtering

Order Management

  • Create & manage customer orders
  • Track order status (Pending → Shipped → Delivered)
  • Admin order control

Payment Integration

  • Simulated/real payment handling (e.g., Stripe/Paystack ready)
  • Secure transaction flow

Database Relationships

  • One-to-Many: User → Orders
  • Many-to-Many: Orders ↔ Products

API Design

  • RESTful endpoints
  • Pagination, validation, and error handling

🧠 Tech Stack

Layer Technology
Framework FastAPI
Database ORM SQLAlchemy
Database Migration Alembic
Authentication JWT (via python-jose, passlib[bcrypt])
Environment Management python-dotenv
Server Uvicorn
Testing Pytest
Docs Built-in Swagger UI (/docs) & Redoc (/redoc)

📁 Project Structure

ecommerce-backend/
├── app/
│   ├── main.py                # Entry point
│   ├── config.py              # Environment & DB settings
│   ├── database.py            # DB connection setup
│   ├── models/                # SQLAlchemy models
│   ├── schemas/               # Pydantic schemas
│   ├── routers/
│   │   ├── users.py
│   │   ├── products.py
│   │   ├── orders.py
│   │   └── payments.py
│   ├── services/              # Business logic layer
│   └── utils/                 # Helpers (auth, hashing, etc.)
├── tests/                     # Unit & integration tests
├── requirements.txt
└── README.md

⚙️ Installation & Setup

1️⃣ Clone the Repository

git clone https://github.com/<your-username>/ecommerce-backend.git
cd ecommerce-backend

2️⃣ Create a Virtual Environment

python -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Setup Environment Variables

Create a .env file in the root directory:

DATABASE_URL=postgresql://user:password@localhost:5432/ecommerce_db
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

5️⃣ Run Database Migrations

alembic upgrade head

6️⃣ Start the Application

uvicorn app.main:app --reload

Now open your browser and navigate to: 👉 Swagger Docs: http://127.0.0.1:8000/docs


🧪 Example Endpoints

Method Endpoint Description
POST /users/signup Register new user
POST /users/login Login & get JWT token
GET /products/ List all products
POST /orders/ Create an order
POST /payments/checkout Process a payment

🛠️ Future Improvements

  • Integrate Paystack or Stripe API
  • Implement Redis caching for performance
  • Add Celery background tasks (e.g., email notifications)
  • Build an admin dashboard frontend

👨‍💻 Author

Olabowale Babatunde Ipaye 📧 b.tunde.ipaye@gmail.com 🌍 Lagos, Nigeria 🔗 LinkedIn | GitHub


🧾 License

This project is licensed under the MIT License. Feel free to use, modify, and distribute.