Automated Action a28e115e4f Implement simple cart system with FastAPI and SQLite
- Set up project structure with FastAPI and SQLite
- Create models for products and cart items
- Implement schemas for API request/response validation
- Add database migrations with Alembic
- Create service layer for business logic
- Implement API endpoints for cart operations
- Add health endpoint for monitoring
- Update documentation
- Fix linting issues
2025-05-18 23:36:40 +00:00
2025-05-18 23:26:35 +00:00

Simple Cart System

A simple shopping cart system API built with FastAPI and SQLite.

Features

  • Product management (CRUD operations)
  • Shopping cart functionality
  • User-specific carts
  • Stock management

Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)

Installation

  1. Clone the repository:
git clone <repository-url>
cd simplecartsystem
  1. Install the dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head
  1. Start the application:
uvicorn main:app --reload

The API will be available at http://localhost:8000.

API Documentation

Interactive API documentation is available at:

API Endpoints

Health Check

  • GET /api/v1/health - Check API and database health

Products

  • GET /api/v1/products - List all products (with pagination)
  • GET /api/v1/products/{product_id} - Get a specific product
  • POST /api/v1/products - Create a new product
  • PUT /api/v1/products/{product_id} - Update a product
  • DELETE /api/v1/products/{product_id} - Delete a product

Cart

  • GET /api/v1/cart - View current cart
  • POST /api/v1/cart/items - Add item to cart
  • PUT /api/v1/cart/items/{item_id} - Update cart item quantity
  • DELETE /api/v1/cart/items/{item_id} - Remove item from cart
  • DELETE /api/v1/cart - Clear cart

Cart Usage Example

Add Product to Cart

curl -X POST "http://localhost:8000/api/v1/cart/items" \
  -H "Content-Type: application/json" \
  -H "user-id: user123" \
  -d '{
    "product_id": 1,
    "quantity": 2
  }'

View Cart

curl -X GET "http://localhost:8000/api/v1/cart" \
  -H "user-id: user123"

Database Schema

The system uses SQLite with the following main tables:

  • products: Stores product information
  • carts: Stores user cart information
  • cart_items: Stores items in user carts

Technology Stack

Description
Project: Simple Cart System
Readme 46 KiB
Languages
Python 98.4%
Mako 1.6%