Simple Cart System API
A simple cart system API built with FastAPI and SQLite for managing products and shopping carts.
Features
- User registration and authentication with JWT tokens
- Product management (CRUD operations)
- Shopping cart functionality (add, update, remove, clear)
- SQLite database with SQLAlchemy ORM
- Alembic migrations
Tech Stack
- FastAPI: High-performance web framework for building APIs
- SQLAlchemy: SQL toolkit and ORM
- SQLite: Lightweight, file-based database
- Alembic: Database migration tool
- Pydantic: Data validation and settings management
- Python-Jose: JWT token handling
- Uvicorn: ASGI server for running the application
Project Structure
.
├── alembic.ini # Alembic configuration file
├── app # Main application package
│ ├── api # API routes
│ │ └── routes # API route modules
│ ├── core # Core functionality
│ │ ├── config.py # Configuration settings
│ │ └── security.py # Authentication and security utilities
│ ├── db # Database related modules
│ │ ├── models # SQLAlchemy models
│ │ └── session.py # Database session management
│ └── schemas # Pydantic models for request/response validation
├── main.py # Application entry point
├── migrations # Alembic migrations
│ └── versions # Migration script versions
└── requirements.txt # Project dependencies
Getting Started
Prerequisites
- Python 3.8+
- pip
Installation
-
Clone the repository
-
Install dependencies
pip install -r requirements.txt
-
Run database migrations
alembic upgrade head
-
Start the application
uvicorn main:app --reload
-
Access the API documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Authentication
POST /api/v1/login/access-token
- Get access token
Users
POST /api/v1/users/
- Create a new userGET /api/v1/users/
- Get all usersGET /api/v1/users/{user_id}
- Get a specific userPATCH /api/v1/users/{user_id}
- Update a userDELETE /api/v1/users/{user_id}
- Delete a user
Products
POST /api/v1/products/
- Create a new product (admin only)GET /api/v1/products/
- Get all productsGET /api/v1/products/{product_id}
- Get a specific productPATCH /api/v1/products/{product_id}
- Update a product (admin only)DELETE /api/v1/products/{product_id}
- Delete a product (admin only)
Cart
POST /api/v1/cart/items/
- Add an item to cartGET /api/v1/cart/
- Get current user's cartGET /api/v1/cart/summary
- Get cart summaryPATCH /api/v1/cart/items/{item_id}
- Update cart item quantityDELETE /api/v1/cart/items/{item_id}
- Remove an item from cartDELETE /api/v1/cart/
- Clear cart
Health Check
GET /health
- Check application health status
License
MIT
Description
Languages
Python
98.5%
Mako
1.5%