A Flask starter scaffold — I had mostly written small Python scripts before, and this project was a chance to build a proper backend skeleton.
1. JWT token flow
- Use short-lived access tokens for better security.
Workflow
- Request access token + refresh token (refresh token in a secure cookie:
HttpOnly,Secure,SameSite). - Send requests with payload + access token; keep the access token in memory (cleared on logout).
- When the access token expires, use the refresh cookie to obtain a new access token.
- Access tokens often live ~1 minute to limit window for MITM abuse.
- Add a one-way hash over parameters for integrity, ideally including request time.
- Encrypt sensitive header fields with HMAC; the backend uses HMAC when refreshing tokens.
- JWTs can be stored in Redis for revocation / allowlists; we aimed for a stateless API for other systems to call, so we did not persist sessions server-side.
Implementation notes
Set-Cookieis set on the server, not in client JS.- Cookies must use
HttpOnly,Secure, andSameSiteor later requests may not send cookies correctly.
Security trade-offs
This design improves security for the refresh cookie, but browser extensions can still read cookies in some cases. Going stateless is a deliberate compromise.
2. Authorization model

3. Client implementation
- redux-thunk, Redux, React, react-hooks, Konva for unidirectional data flow.
- redux-thunk is simpler than redux-saga for most async flows.
- react-hooks reduce boilerplate vs class lifecycle methods.
- Konva works well with TypeScript for canvas drawing.
4. Database safety (XSS)
- Prefer SQLAlchemy ORM over raw SQL; if you must use raw SQL, escape and validate inputs to avoid injection/XSS-style issues.
- Add indexes where needed for query speed.
- Run EXPLAIN on important queries and optimize.
5. Flask backend basics
Logging (daily rotation, two handlers)
| |
Other baseline pieces
- Per-environment configuration
- CORS response headers and explicit OPTIONS handling (no
flask-corsdependency required) - Serialize DB rows with a small helper:
| |
Singletons (config, logger, etc.)
| |
Sphinx + Postman
- Docs generated from Markdown sources.
- Postman collections live alongside docs so the team can import and develop against the API quickly.