Skip to content

Tags: yuting1214/Fullstack-FastAPI

Tags

0.1.0

Toggle 0.1.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Optimized version (#2)

* [FEAT] Add locust file to benchmark performance.

* [EHN] 1. orjson for parse 2. lifespan with increased thread pools 3. refactor middleware and add gzip compression 4.

* [EHN] add locust in dependency.

* [REFACTOR] Restructure project, migrate to uv, apply FastAPI best practices

Project structure:
- Reorganize from backend/fastapi/ to src/backend/, frontend/ to src/frontend/
- Move tests to root tests/ directory with shared conftest.py
- Remove dead files (constants.py, authorization.py, rate_limiter.py)

Package management:
- Replace requirements.txt with pyproject.toml + uv
- Pin Python 3.12 via .python-version
- Drop unused deps (trio, databases), add uvloop

Environment & security:
- Replace tracked .env with .env.example template
- Add .env, .cursor/, .claude/ to .gitignore
- Fix hardcoded SECRET_KEY in SessionMiddleware
- Auth reads from pydantic-settings instead of os.getenv()

FastAPI best practices (from Kludex/fastapi-tips):
- Convert all endpoints and CRUD to async (Tips #2, #9)
- Pure ASGI DocProtectMiddleware replacing BaseHTTPMiddleware (Tip #8)
- Typed lifespan state yielding session factory (Tip #6)
- Async DB init and proper engine disposal on shutdown
- SQLAlchemy 2.0: select(), DeclarativeBase, Mapped, async_sessionmaker
- Portable UUID column (String(36)) for SQLite + PostgreSQL compat

Testing:
- All-async test suite with httpx.AsyncClient + pytest-anyio (Tips #5, #10)
- conftest.py handles DB lifecycle since ASGITransport skips lifespan
- Consolidated test_api_sync.py + test_api_async.py into test_api.py

Deployment:
- Dockerfile updated for Python 3.12 + uv
- Docker build and test run verified in container (7/7 pass)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* [FIX] Use SQLAlchemy Uuid type for PostgreSQL + SQLite compatibility

Replace String(36) with SQLAlchemy 2.0 native Uuid type which maps to
PostgreSQL UUID and SQLite CHAR(32) automatically. Fixes startup crash
when deploying against an existing PostgreSQL database that has UUID
columns from the previous schema.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>