# SimpleEcommerceStore API A simple ecommerce store API built with FastAPI and SQLite. ## Features - User authentication and registration - Product management (CRUD operations) - Shopping cart functionality - Order processing - Admin operations for product and order management ## Tech Stack - **Framework**: FastAPI - **Database**: SQLite with SQLAlchemy ORM - **Authentication**: JWT tokens - **Migrations**: Alembic - **Validation**: Pydantic - **Linting**: Ruff ## Project Structure ``` ├── app/ # Application package │ ├── api/ # API endpoints │ │ ├── v1/ # API version 1 │ │ │ ├── endpoints/ # API endpoint modules │ │ │ └── api.py # API router │ ├── core/ # Core modules │ │ ├── config.py # Configuration settings │ │ └── security.py # Security utilities │ ├── db/ # Database │ │ ├── deps.py # Dependency functions │ │ └── session.py # Database session │ ├── models/ # SQLAlchemy models │ ├── schemas/ # Pydantic schemas │ ├── services/ # Business logic │ └── main.py # FastAPI app ├── migrations/ # Alembic migrations ├── alembic.ini # Alembic configuration ├── main.py # Application entry point ├── pyproject.toml # Project configuration └── requirements.txt # Dependencies ``` ## API Endpoints ### Health Check - `GET /health`: Application health status ### Authentication - `POST /api/v1/auth/login`: Login and get access token - `POST /api/v1/auth/register`: Register a new user ### Users - `GET /api/v1/users/me`: Get current user information - `PATCH /api/v1/users/me`: Update current user - `GET /api/v1/users/{user_id}`: Get user by ID (admin only) - `GET /api/v1/users/`: List all users (admin only) ### Products - `GET /api/v1/products/`: List all products - `GET /api/v1/products/{id}`: Get product by ID - `POST /api/v1/products/`: Create a new product (admin only) - `PUT /api/v1/products/{id}`: Update a product (admin only) - `DELETE /api/v1/products/{id}`: Delete a product (admin only) ### Cart - `GET /api/v1/cart/`: Get user's cart summary - `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 order from cart - `GET /api/v1/orders/{id}`: Get order by ID - `PUT /api/v1/orders/{id}/status`: Update order status (admin only) ## Setup and Running 1. Install dependencies: ```bash pip install -r requirements.txt ``` 2. Run migrations: ```bash alembic upgrade head ``` 3. Run the development server: ```bash python main.py ``` The API will be available at `http://localhost:8000`. API documentation is available at: - Swagger UI: `http://localhost:8000/docs` - ReDoc: `http://localhost:8000/redoc` ## Database The application uses SQLite as its database, stored at `/app/storage/db/db.sqlite`. SQLAlchemy is used as the ORM layer to interact with the database. ## Authentication The API uses JWT tokens for authentication. To access protected endpoints: 1. Login with valid credentials at `/api/v1/auth/login` 2. Use the returned access token in the Authorization header: `Bearer {token}`