A Flask business system from a single command

One script run generates a Flask + PostgreSQL project with login, an admin panel, notices, DB migrations, and CI. It runs on Python alone, with no Node or frontend build.

  • Flask3.1.3
  • Jinja3.1.6
  • SQLAlchemy2.1.8
  • Alembic1.20.1
  • PostgreSQL16+
  • htmx2.0.11
  • Tailwind CSS4.3.5
  • pydantic2.14.2
  • pytest9.2.0
  • waitress3.0.2
  • Python3.13

Request handling layers

Screens, views, services, and the database each have their own layer. New features go into the matching layer.

  • Browser

    Works with plain HTML forms and links, and swaps only the parts that need it with htmx.

  • Flask viewsapp/web/

    Check CSRF, verify the DB session, and choose the template.

  • Servicesapp/services/

    Hold the domain logic and pydantic validation, and report errors as ServiceError.

  • PostgreSQL

    The schema changes only through Alembic. The time zone is set to Asia/Seoul.

Built-in screens

Public and admin screens for managing accounts, sessions, notices, and banners are included, with tests. New domains follow the same structure.

Login and sessions
Each login records a session in the DB, and repeated failures lock the account. Admins can revoke sessions.
Admin dashboard
Shows users, sessions, notices, banners, DB status, and the migration revision on one screen.
Notices
Written in a WYSIWYG editor, with image and YouTube embeds, file attachments, and pinning to the top.
Banners
Shown on the home page for a set period and in a set order.
User management
Change roles, deactivate users, and unlock locked logins.
Admin account
The scaffold script generates a random password, and the account is created when the app starts.

Server rendering with htmx partial swaps

Every screen works with plain forms and links alone. Where only part of the page updates, as in search, you add htmx attributes, and the view responds with either the full page or just the list fragment, built from the same data.

public/notices.html
<form method="get" action="/notices"
      hx-get="/notices"
      hx-target="#notice-list"
      hx-push-url="true"
      hx-trigger="input changed delay:300ms">
  <input type="search" name="q">
</form>
{% include "partials/notice_list.html" %}
app/web/public.py
@bp.get("/notices")
def notices():
    result = notice_service.list_published(...)
    # List fragment for htmx requests, full page otherwise
    return render_page_or_partial(
        "public/notices.html",
        "partials/notice_list.html",
        result=result,
    )

Secure defaults

Key security settings are on by default. In production, the app refuses to start if any unsafe setting remains.

Security headers on every response
Content-Security-Policy: default-src 'self';
  script-src 'self'; style-src 'self';
  img-src 'self' data: blob: https:; object-src 'none'
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Set-Cookie: orders_session=…; HttpOnly; SameSite=Lax
  • CSRF checks on every state-changing request

    Forms and htmx requests both send the token, and no view is exempt.

  • DB-backed session checks

    The cookie holds only an opaque token, and every request checks the session in the DB.

  • No inline scripts

    Scripts and styles all live in separate files, and notice bodies are sanitized before they are saved.

Rule documents in the repository

The architecture reference, a work plan, and instructions and task skills for AI coding agents are generated with the project. Developers and AI agents work from the same documents.

Generated documents and task skills
ARCHITECTURE.mdArchitecture reference and a summary of the required rules
PLAN.mdTDD work plan that starts from one failing test
AGENTS.md, CLAUDE.mdShared agent instructions for Codex, Cursor, and Claude Code
add-domainSteps for adding a domain: model, migration, service, screens, then tests
db-migrationSteps for changing the schema with Alembic
add-screenSteps for adding a screen, covering templates, htmx fragments, CSRF, and CSP
pr-workflowChecks to run before push, and the commit message format
stack-versionsCautions and checks for version upgrades
  • No notices have been posted yet.

Get started

The script checks for the tools it needs first. Missing tools are handled as shown below.

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.
Windows PowerShell
git clone https://github.com/al8bright/flask-starter.git
cd flask-starter
.\scaffold.ps1
macOS, Linux, Git Bash
git clone https://github.com/al8bright/flask-starter.git
cd flask-starter
./scaffold.sh
Tests in the generated project
189
Version-pinned packages
20
AI task skills
5
Node dependencies
0
Back to top