Automated Action 598b4eb68e Update README with SQLite configuration details
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: BackendIM <https://backend.im>
2025-05-11 18:57:44 +00:00

E-commerce API

A RESTful API for an e-commerce application built with FastAPI and SQLite.

Features

  • User authentication and authorization
  • Product management
  • Category management
  • Shopping cart and order processing
  • Admin dashboard

Tech Stack

  • Framework: FastAPI
  • Database: SQLite with SQLAlchemy ORM
  • Migration: Alembic
  • Authentication: JWT tokens
  • API Documentation: Swagger UI and ReDoc (auto-generated)

Project Structure

/
├── alembic/                  # Database migrations
├── app/                      # Main application directory
│   ├── api/                  # API endpoints
│   │   ├── endpoints/        # API route handlers
│   ├── core/                 # Core components
│   ├── crud/                 # CRUD operations
│   ├── db/                   # Database sessions and connections
│   ├── models/               # SQLAlchemy models
│   └── schemas/              # Pydantic models/schemas
├── main.py                   # FastAPI application instance
└── requirements.txt          # Project dependencies

Installation

  1. Clone the repository

  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Database Setup: The application uses SQLite as the database, which is stored in ../storage/db/db.sqlite (outside the project root directory). This directory will be created automatically when the application runs.

  4. Run database migrations:

    alembic upgrade head
    
  5. Start the API server:

    uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    

API Endpoints

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Login and get access token

Users

  • GET /api/v1/users/me - Get current user info
  • PUT /api/v1/users/me - Update current user info
  • GET /api/v1/users/{user_id} - Get user by ID
  • GET /api/v1/users/ - Get all users (admin only)
  • PUT /api/v1/users/{user_id} - Update user by ID (admin only)

Categories

  • GET /api/v1/categories/ - List all categories
  • POST /api/v1/categories/ - Create a new category (admin only)
  • GET /api/v1/categories/{category_id} - Get category by ID
  • PUT /api/v1/categories/{category_id} - Update category (admin only)
  • DELETE /api/v1/categories/{category_id} - Delete category (admin only)

Products

  • GET /api/v1/products/ - List all active products
  • POST /api/v1/products/ - Create a new product (admin only)
  • GET /api/v1/products/{product_id} - Get product by ID
  • PUT /api/v1/products/{product_id} - Update product (admin only)
  • DELETE /api/v1/products/{product_id} - Delete product (admin only)
  • GET /api/v1/products/category/{category_id} - Get products by category

Orders

  • GET /api/v1/orders/ - List user's orders (or all orders for admin)
  • POST /api/v1/orders/ - Create a new order
  • GET /api/v1/orders/{order_id} - Get order by ID
  • PUT /api/v1/orders/{order_id} - Update order
  • PUT /api/v1/orders/{order_id}/status - Update order status (admin only)
  • GET /api/v1/orders/status/{status} - Get orders by status (admin only)

API Documentation

When the server is running, the API documentation is available at:

Database Schema

Users

  • id: Integer (Primary Key)
  • email: String (Unique)
  • username: String (Unique)
  • hashed_password: String
  • full_name: String (Optional)
  • is_active: Boolean
  • is_admin: Boolean
  • created_at: DateTime
  • updated_at: DateTime

Categories

  • id: Integer (Primary Key)
  • name: String (Unique)
  • description: Text (Optional)

Products

  • id: Integer (Primary Key)
  • name: String
  • description: Text (Optional)
  • price: Float
  • stock: Integer
  • is_active: Boolean
  • category_id: Integer (Foreign Key)
  • image_url: String (Optional)
  • created_at: DateTime
  • updated_at: DateTime

Orders

  • id: Integer (Primary Key)
  • user_id: Integer (Foreign Key)
  • status: Enum (PENDING, PROCESSING, SHIPPED, DELIVERED, CANCELLED)
  • total_amount: Float
  • shipping_address: String
  • created_at: DateTime
  • updated_at: DateTime

Order Items

  • id: Integer (Primary Key)
  • order_id: Integer (Foreign Key)
  • product_id: Integer (Foreign Key)
  • quantity: Integer
  • price: Float (Price at the time of purchase)
Description
Project: E-commerce API
Readme 51 KiB
Languages
Python 98.6%
Mako 1.4%