FastAPI + SQLite service for the fashion storefront. The backend follows Domain-Driven Design (DDD), seeds demo data automatically, and exposes REST + WebSocket endpoints under /api/v1.
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env # customize secrets before running
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000- API docs: http://localhost:8000/api/v1/docs (Swagger)
- Health check:
GET /health - Convenience script to launch frontend + backend together:
./backend/run_local.sh
backend/app/main.py– App factory, CORS, table creation, DB seedingbackend/app/api/endpoints/– Routers forauth,products,categories,orders,reviews,support(WebSocket at/api/v1/support/ws)backend/app/domains/– DDD layers per domain (catalog,category,order,review,support,identity)backend/app/infrastructure/– SQLite models/session/seeder, PDF invoice generator, SMTP email sender, local storage for support attachmentsbackend/app/core/– Settings, JWT/password utilities, structured loggingbackend/tests/– Pytest suite using its own SQLite DB (tests/test_database.db)
SECRET_KEY,JWT_ALGORITHM,ACCESS_TOKEN_EXPIRE_MINUTES,REFRESH_TOKEN_EXPIRE_DAYSSQLITE_DATABASE_URL(defaultsqlite:///./database.db)- Cookie settings:
COOKIE_DOMAIN,COOKIE_SECURE,COOKIE_SAMESITE,COOKIE_PATH - SMTP (optional for invoice email):
SMTP_HOST,SMTP_PORT,SMTP_USERNAME,SMTP_PASSWORD,SMTP_STARTTLS,EMAIL_FROM - Support chat/attachments:
SUPPORT_ATTACHMENT_DIR,SUPPORT_ATTACHMENT_MAX_MB,SUPPORT_ALLOWED_MIME_PREFIXES,SUPPORT_HISTORY_LIMIT,SUPPORT_QUEUE_LIMIT
- On startup tables are created and seed data is added if the DB is empty (
backend/database.db). - Seeded accounts:
manager@example.com(product manager),sales@example.com(sales manager) with password12345678. A support agent (support@example.com/12345678) is recreated automatically if missing. New registrations default to thecustomerrole. - Reset database:
rm backend/database.dbthen restart the server.
- Auth (
/api/v1/auth): register, login, refresh, logout, andGET /me. JWTs are issued as HTTP-only cookies. Roles:customer,product_manager,sales_manager,support_agent. - Catalog (
/api/v1/products): list/get products, update fields, delete, apply or clear percentage discounts via/discountendpoints. - Categories (
/api/v1/categories): CRUD with name uniqueness; deleting fails if products still reference the category. - Orders (
/api/v1/orders): customers create orders (8% tax, $10 shipping under $100). Product managers can update status; customers can cancel whileprocessing; refunds followrequest→ managerapprove/reject. All orders can be listed by managers, while customers only see their own. Invoice PDFs are emailed in a background task when SMTP is configured. - Reviews (
/api/v1/products/{id}/reviews): customers can review products they purchased in a delivered order (one review per product). Ratings-only are auto-approved; comments need product manager approval. Pending queue and approval/rejection endpoints live under/api/v1/reviews. - Support (
/api/v1/support): authenticated or guest users can start conversations, exchange messages, and upload attachments (size/type validated, stored instorage/support_attachments). Agents claim/close conversations and view a live queue. Real-time chat uses WebSocket at/api/v1/support/ws.
cd backend
source venv/bin/activate
pytestThe test suite boots a fresh SQLite database (tests/test_database.db) and seeds it automatically; no manual cleanup is needed between runs.