# E-Commerce API A full-featured e-commerce API built with FastAPI and SQLite. ## Features - **User Management**: Registration, authentication, and profile management - **Product Management**: Products with categories, pricing, and inventory management - **Shopping Cart**: Add, update, remove items in user's shopping cart - **Order Processing**: Create orders from cart, track order status - **Authentication**: JWT-based authentication with role-based access control ## Tech Stack - **FastAPI**: Modern, fast API framework - **SQLAlchemy**: SQL toolkit and ORM - **Alembic**: Database migration tool - **SQLite**: Serverless database engine - **JWT**: JSON Web Tokens for authentication - **Pydantic**: Data validation and settings management ## API Endpoints ### Authentication - `POST /api/v1/auth/login`: Login and get access token - `POST /api/v1/auth/register`: Register a new user - `GET /api/v1/auth/me`: Get current user information ### Users - `GET /api/v1/users/`: List all users (admin only) - `POST /api/v1/users/`: Create a new user (admin only) - `GET /api/v1/users/me`: Get current user profile - `PUT /api/v1/users/me`: Update current user profile - `GET /api/v1/users/{user_id}`: Get user by ID - `PUT /api/v1/users/{user_id}`: Update user (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 products (filter by category optional) - `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) ### Cart - `GET /api/v1/cart/`: Get current user's 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 ### Orders - `GET /api/v1/orders/`: List user's orders - `POST /api/v1/orders/`: Create new order from cart - `GET /api/v1/orders/{order_id}`: Get order by ID - `PUT /api/v1/orders/{order_id}`: Update order status (admin only) - `POST /api/v1/orders/{order_id}/cancel`: Cancel order (if pending) ### Health Check - `GET /health`: Application health check ## Installation and Setup ### Prerequisites - Python 3.8+ - pip (Python package installer) ### Installation 1. Clone the repository ```bash git clone cd ecommerceapplication ``` 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 ``` The API will be available at http://localhost:8000. ## Documentation FastAPI provides automatic API documentation: - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## Development ### Database Migrations Create a new migration after model changes: ```bash alembic revision --autogenerate -m "Description of changes" ``` Apply migrations: ```bash alembic upgrade head ``` ### Running Tests ```bash pytest ``` ## License This project is licensed under the MIT License - see the LICENSE file for details.