Production-style scaffolding for a React app with full user functionality (signup, login, password reset, email verification) and a FastAPI backend with SQLite. Use as a template for any site that requires user accounts.
For scaling to ~1M users (React, API, DB, bottlenecks, infrastructure), see SCALING_ROADMAP.md.
| Responsibility | React app (client) | Backend (FastAPI) |
|---|---|---|
| Passwords | Never hashed or stored; submit over HTTPS | Bcrypt hashing, verification |
| Session | Sends cookies with requests; reads auth state from /auth/me |
Issues httpOnly cookie (JWT); validates on protected routes |
| Auth UI | Login, signup, forgot/reset password, profile | Register, login, logout, forgot/reset, verify-email |
| Protected routes | Route guard redirects to login | /auth/me and any protected API return 401 if invalid |
- Client:
client/— Vite + React + TypeScript + React Router. OnlyVITE_*env vars. - Server:
server/— FastAPI + SQLAlchemy (async) + SQLite. All secrets in env.
cd server
python -m venv .venv
source .venv/bin/activate # or .venv\Scripts\activate on Windows
pip install -r requirements.txt
cp .env.example .env # edit if needed
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Database file auth.db is created in server/ on first run.
cd client
npm install
npm run devOpen http://localhost:5173. The dev server proxies /api to the backend (port 8000), so login/signup work without CORS.
- Set
VITE_API_URLto your backend URL (e.g.https://api.example.com). - Backend: set
SECRET_KEY,COOKIE_SECURE=true, use HTTPS, and optionally switch to PostgreSQL viaDATABASE_URL. - See
server/.env.exampleanddocs/backend-api.mdfor all options.
client/ # React SPA
src/
api/ # API client (credentials: 'include')
auth/ # AuthContext, useAuth
components/ # Layout, Button, Input
features/auth/ # Login, Signup, Forgot/Reset, Verify
features/profile/ # Profile page
routes/ # Router, ProtectedRoute
lib/ # env (VITE_API_URL)
types/
server/ # FastAPI
app/
api/ # auth routes, deps (get_current_user)
core/ # security (hash, JWT), email stub
models/ # User, PasswordResetToken, EmailVerifyToken
schemas/ # Pydantic request/response
requirements.txt
.env.example
docs/
backend-api.md # API contract (any backend can implement this)
POST /auth/register— sign up (body: email, password, optional full_name)POST /auth/login— log in (sets httpOnly session cookie)POST /auth/logout— clear cookieGET /auth/me— current user (401 if not authenticated)POST /auth/forgot-password— send reset link (body: email)POST /auth/reset-password— set new password (body: token, new_password)GET /auth/verify-email?token=...— verify email
OpenAPI: http://localhost:8000/docs when the backend is running.
- Copy this repo (or
client/+server/+docs/backend-api.md). - Point the client at your backend with
VITE_API_URL, or keep the FastAPI backend and change DB/email as needed. - Replace branding, add more profile fields or protected routes as required.