A small social-style backend: register and log in with JWTs, upload images and videos via ImageKit, and read a feed of posts. Stack: FastAPI, SQLAlchemy (async) + SQLite, fastapi-users, optional Streamlit demo (frontend.py).
| Area | Choice |
|---|---|
| HTTP API | FastAPI |
| Auth | fastapi-users (JWT) |
| Database | SQLite (test.db), created on startup |
| Media | ImageKit uploads |
| Demo UI | Streamlit → http://localhost:8000 |
Open http://localhost:8000/docs for interactive OpenAPI when the server is running.
- Python 3.13+ (
pyproject.toml) - uv (recommended)
- ImageKit account and keys
-
Clone the repo and enter the project directory.
-
Copy environment template and fill in values:
cp .env.example .env
Variable Notes JWT_SECRET_KEYLong random string; signs JWTs IMAGEKIT_PRIVATE_KEYServer uploads IMAGEKIT_PUBLIC_KEYListed in .env.examplefor parity with ImageKit; wire in app if you need client-side uploadIMAGEKIT_URL_ENDPOINTe.g. https://ik.imagekit.io/your_id— used for URL transforms in Streamlit -
Install dependencies:
uv sync
uv run python main.pyRuns uvicorn on 0.0.0.0:8000 with reload (app.app:app).
Equivalent:
uv run uvicorn app.app:app --reload --host 0.0.0.0 --port 8000Terminal 1: API as above. Terminal 2:
uv run streamlit run frontend.pyUse the URL Streamlit prints (usually http://localhost:8501).
Note: frontend.py calls /upload, /feed, and /posts/{id}. The router mounts posts under /posts, so working paths are POST /posts/upload, GET /posts/feed, and DELETE /posts/posts/{post_id}. If the UI returns 404 on feed or upload, update those URLs in frontend.py to match /docs.
- Auth / users — fastapi-users routes (register, JWT login,
/users/me, etc.) — see/docs - Posts (Bearer token required):
POST /posts/upload— multipart file + optional captionGET /posts/feed— feed JSONDELETE /posts/posts/{post_id}— delete (path reflects current router prefix + handler path)
fast-api/
├── main.py # Dev server entry
├── frontend.py # Streamlit client
├── .env.example # Env template
├── pyproject.toml
├── uv.lock
├── app/
│ ├── app.py # FastAPI app + routers
│ ├── db.py # Engine, models, session
│ ├── users.py # JWT + UserManager
│ ├── images.py # ImageKit client
│ ├── schemas.py
│ └── modules/posts/ # Routes + controllers
└── test.db # Created when the API runs
- JWT errors — Set
JWT_SECRET_KEYin.envand restart the API. - Upload failures — Check
IMAGEKIT_PRIVATE_KEYand ImageKit dashboard. - Port 8000 busy — Change port in
main.pyor pass--portto uvicorn; updatefrontend.pyURLs if you use Streamlit.