Architecture

GitHub repository

flask-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 .env file
  • 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 root
Template repositoryPurpose
scaffold.ps1Scaffold for Windows (PowerShell 5.1+)
scaffold.shScaffold 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.mdTemplate changelog
Contents of skeleton
skeleton/Purpose
app/Flask app: web layer and shared layer
alembic/Migrations
tests/pytest
scripts/bootstrap · tailwind · versions.env
ARCHITECTURE.mdArchitecture reference (SSOT)
AGENTS.md · CLAUDE.mdAI agent instructions
.claude/skills/5 task skills (domains, migrations, screens, commits, versions)
.github/workflows/ci.ymlCI 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.

  1. 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.

  2. Check minimum Python

    If Python is older than 3.13, runs bootstrap and checks again. If that fails, stops before copying.

  3. 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.

  4. Copy skeleton

    Build output and .env are excluded.

  5. Replace tokens

    Replaces the project name and its snake_case form (used for the DB and cookie names).

  6. Create .env

    Generates DATABASE_URL, a random SECRET_KEY, and the admin password.

  7. venv + pip install

    Installs the versions pinned in requirements.txt.

  8. Create DB

    Creates the database with psql and sets its default time zone to Asia/Seoul.

  9. alembic upgrade head

    Applies the initial schema.

  10. Download Tailwind CLI and build CSS

    Builds app.css with the standalone CLI after verifying its SHA-256.

  11. Summary

    Prints how to run the app and which steps succeeded or failed.

0 Done
1 Stopped: invalid input or runtime requirement not met
2 Some steps incomplete: see the summary

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

HTML forms and links, partial swaps with htmx

Flask :5000

app/web/

CSRF check · form parsing · Jinja template selection

Services

app/services/

Domain logic. Errors are raised as ServiceError.

PostgreSQL

timezone = Asia/Seoul

Per-request dependencies

app/dependencies.py

DB session · current user · permission decorators · auth cookie

Error responses

app/web/errors.py

STATUS_BY_CODE sets the status code. htmx requests show errors in #alerts.

Alembic

alembic/

The only way to change the schema. No create_all at runtime.

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

Creates an auth_sessions row

Cookie

Opaque token · httpOnly · SameSite=Lax

Every request

Session validated against the DB

Version pinning

AreaPinning methodValueSource file
Python minimumExisting install is reused if it meets the minimum≥ 3.13versions.env
Python install pinInstalled and activated with pyenv3.13.14.python-version
Python packagesExact == pins20 packages, including flask 3.1.3 · sqlalchemy 2.1.8 · alembic 1.20.1requirements.txt
Tailwind CSSstandalone CLI + SHA-256 check4.3.5versions.env
htmxVendored2.0.11static/js/htmx.min.js
PostgreSQLNot pinned16 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 --audit option runs an OSV security audit.
check_common_layer.py
Checks that the shared layer matches the source in the FastAPI sibling template.
Back to top