Architecture
GitHub repositoryflask-starter is a scaffold template that generates a Flask + Jinja + PostgreSQL business web project with a single script run. This page walks through the template repository layout, the scaffold steps, and the structure of the generated app.
Components
Server
- Flask 3 + Jinja server-side rendering
- SQLAlchemy 2.1 · Alembic migrations
- PostgreSQL (time zone Asia/Seoul)
- waitress / gunicorn
- pytest + ruff
UI
- Full-page server rendering by default
- Optional htmx enhancement (works without htmx)
- Tailwind CSS v4 standalone CLI
- CSP
script-src 'self' - No Node or npm build step
Built-in features
- Cookie login with DB sessions · login rate limiting
- Global CSRF protection
- Automatic admin account seeding
- Notices (WYSIWYG editor, attachments) · banners · uploads
- Admin dashboard · users · sessions
Automation
- scaffold.ps1 / scaffold.sh
- Runtime bootstrap (minimum Python check)
- GitHub Actions CI (template and generated projects)
- 5 AI development skills
Fixed rules
- DB schema changes only through Alembic
- All settings in a single root
.envfile - All times in KST, regardless of OS
- TDD + Tidy First (Structural and Behavioral changes kept separate)
- No auth state in JWTs or the Flask session
- No inline scripts or
style=attributes
Repository layout
Scripts at the template repository root copy skeleton/ to create a new project. tools/ and docs/ are not copied.
| Template repository | Purpose |
|---|---|
| scaffold.ps1 | Scaffold for Windows (PowerShell 5.1+) |
| scaffold.sh | Scaffold for macOS, Linux, and Git Bash (same output as Windows) |
| skeleton/ | The full skeleton copied into each new project |
| tools/ | Generated project checks and shared-layer parity check |
| docs/ | Template review notes |
| .github/ | CI for the template itself (template-ci.yml) |
| CHANGELOG.md | Template changelog |
| skeleton/ | Purpose |
|---|---|
| app/ | Flask app: web layer and shared layer |
| alembic/ | Migrations |
| tests/ | pytest |
| scripts/ | bootstrap · tailwind · versions.env |
| ARCHITECTURE.md | Architecture reference (SSOT) |
| AGENTS.md · CLAUDE.md | AI agent instructions |
| .claude/skills/ | 5 task skills (domains, migrations, screens, commits, versions) |
| .github/workflows/ci.yml | CI for the generated project |
Scaffold flow
One script run performs the steps below in order. If the DB, install, or CSS step fails, the skeleton is still created and the script exits with code 2.
-
Validate name and target location
Only ASCII names (up to 64 characters) are allowed. The template repository itself and its parent or child folders are rejected.
-
Check minimum Python
If Python is older than 3.13, runs bootstrap and checks again. If that fails, stops before copying.
-
Enter DB connection details and pre-check
Looks for psql on PATH and in standard install locations. If it is missing, prints the commands to run yourself.
-
Copy skeleton
Build output and .env are excluded.
-
Replace tokens
Replaces the project name and its snake_case form (used for the DB and cookie names).
-
Create .env
Generates DATABASE_URL, a random SECRET_KEY, and the admin password.
-
venv + pip install
Installs the versions pinned in requirements.txt.
-
Create DB
Creates the database with psql and sets its default time zone to Asia/Seoul.
-
alembic upgrade head
Applies the initial schema.
-
Download Tailwind CLI and build CSS
Builds app.css with the standalone CLI after verifying its SHA-256.
-
Summary
Prints how to run the app and which steps succeeded or failed.
Requirements and how they're handled
| Node.js | Not needed | CSS is built with the Tailwind standalone CLI, so Node.js and npm aren't used. |
|---|---|---|
| Python 3.13 | Installed automatically | An existing Python 3.13 or later is used as is; otherwise it is installed with pyenv. On macOS and Linux, pyenv itself is installed with Homebrew if missing. On Windows, pyenv-win must already be installed. |
| PostgreSQL | Install separately | The scaffold doesn't install it. You can install it with bootstrap -WithPostgres (--with-postgres on macOS and Linux). The project is still generated without it, and the DB commands to run are printed. |
| Tailwind CLI | Installed automatically | Downloaded on the first build and used only if its SHA-256 matches. |
| Python packages | Installed automatically | Installs the versions pinned in requirements.txt into the project's .venv. |
Generated app
Request flow
Browser
Flask :5000
app/web/
Services
app/services/
PostgreSQL
Per-request dependencies
app/dependencies.py
Error responses
app/web/errors.py
Alembic
alembic/
Flask-specific layer and shared layer
Flask-specific This template
- app/main.py — app factory
- app/web/ — views, htmx helpers, security headers
- app/dependencies.py
- app/templates/ · app/static/
Shared layers Identical, file by file, to the FastAPI sibling template
- app/config.py · app/cli.py
- app/core/ — security, time, sanitizing, storage
- app/db/ · app/models/ · app/schemas/
- app/services/ · alembic/
The shared layer tracks its source repository one way and is never edited directly in this repository. As a result, the DB schema and service rules match the sibling template.
Checking login state
Log in
Cookie
Every request
Version pinning
| Area | Pinning method | Value | Source file |
|---|---|---|---|
| Python minimum | Existing install is reused if it meets the minimum | ≥ 3.13 | versions.env |
| Python install pin | Installed and activated with pyenv | 3.13.14 | .python-version |
| Python packages | Exact == pins | 20 packages, including flask 3.1.3 · sqlalchemy 2.1.8 · alembic 1.20.1 | requirements.txt |
| Tailwind CSS | standalone CLI + SHA-256 check | 4.3.5 | versions.env |
| htmx | Vendored | 2.0.11 | static/js/htmx.min.js |
| PostgreSQL | Not pinned | 16 or later recommended | — |
Verification and automation
Template CI template-ci.yml
- .ps1 and .sh syntax checks (ShellCheck)
- Version consistency between versions.env and vendored assets
- Real scaffold runs on Ubuntu, macOS, and Windows, then pytest and a CSS build on the output
- PowerShell and bash outputs compared for parity
- Alembic round trip on PostgreSQL 16 · pip-audit
Generated project CI ci.yml
- ruff + pytest(Ubuntu·Windows)
- CSS build (tailwind.sh · tailwind.ps1)
- Alembic round trip on a PostgreSQL 16 service container
- PowerShell 5.1 syntax check
- pip-audit (warnings only)
Check tools tools/
- check_projects.py
- Compares runtimes, package pins, and shared files between the starter and generated projects in one report. The
--auditoption runs an OSV security audit. - check_common_layer.py
- Checks that the shared layer matches the source in the FastAPI sibling template.