3.5 KiB
3.5 KiB
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 tokenPOST /api/v1/auth/register
: Register a new user
Users
GET /api/v1/users/me
: Get current user informationPATCH /api/v1/users/me
: Update current userGET /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 productsGET /api/v1/products/{id}
: Get product by IDPOST /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 summaryPOST /api/v1/cart/items
: Add item to cartPUT /api/v1/cart/items/{item_id}
: Update cart item quantityDELETE /api/v1/cart/items/{item_id}
: Remove item from cartDELETE /api/v1/cart/
: Clear cart
Orders
GET /api/v1/orders/
: List user's ordersPOST /api/v1/orders/
: Create order from cartGET /api/v1/orders/{id}
: Get order by IDPUT /api/v1/orders/{id}/status
: Update order status (admin only)
Setup and Running
- Install dependencies:
pip install -r requirements.txt
- Run migrations:
alembic upgrade head
- Run the development server:
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:
- Login with valid credentials at
/api/v1/auth/login
- Use the returned access token in the Authorization header:
Bearer {token}