106 lines
3.2 KiB
Markdown
106 lines
3.2 KiB
Markdown
# 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
|
|
|
|
1. Clone the repository
|
|
|
|
2. Install dependencies
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run database migrations
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
4. Start the application
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
5. 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 user
|
|
- `GET /api/v1/users/` - Get all users
|
|
- `GET /api/v1/users/{user_id}` - Get a specific user
|
|
- `PATCH /api/v1/users/{user_id}` - Update a user
|
|
- `DELETE /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 products
|
|
- `GET /api/v1/products/{product_id}` - Get a specific product
|
|
- `PATCH /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 cart
|
|
- `GET /api/v1/cart/` - Get current user's cart
|
|
- `GET /api/v1/cart/summary` - Get cart summary
|
|
- `PATCH /api/v1/cart/items/{item_id}` - Update cart item quantity
|
|
- `DELETE /api/v1/cart/items/{item_id}` - Remove an item from cart
|
|
- `DELETE /api/v1/cart/` - Clear cart
|
|
|
|
### Health Check
|
|
- `GET /health` - Check application health status
|
|
|
|
## License
|
|
|
|
MIT |