The python-app template¶
The default template: any Python application or library, no framework imposed. Business rules
live in a pure domain, files, databases and other services behind repositories and clients,
each operation in a service, and the command line in an entry point. It follows the Python
Packaging User Guide (the src layout, pyproject.toml), PEP 8, typing (mypy) and the Zen of
Python.
archvow init invoicing -a architects=@my-team # python-app is the default
archvow init invoicing -t python-app -a architects=@my-team # the same, explicitly
It shares with the other templates everything that is not about the stack - the init answers
(language, platform, CI, AI assistants, Sonar, internal sources), the Git hook, the code owners,
the CI files - through a common base, python-base. The questions, the safety analysis and
their tests work the same way.
init answers¶
All the answers of the pyspark-pipeline template except the
Spark ones (spark_version, scheduler), with these defaults:
| Answer | Default | Meaning |
|---|---|---|
dependencies |
none | approved third-party packages besides pytest and hypothesis, as imported (-a dependencies=requests,yaml) |
python_version |
3.12 |
minimum Python: 3.11 to 3.13 |
Layout¶
The package lives in src/<package>/ - the src layout the Python Packaging User Guide
recommends: the tests always import the installed package (pip install -e ., done by
requirements.txt), never a copy that happens to sit in the working folder, and nothing but
the package is importable.
| File | Holds |
|---|---|
pyproject.toml |
the package (setuptools), what it needs at run time, pytest's settings, mypy's settings |
requirements.txt |
the development tools: the package itself (editable), archvow, ruff, mypy, pytest, Hypothesis |
Makefile |
make install, make check (ruff, mypy, archvow), make test, make run |
ruff.toml |
PEP 8, docstrings, annotations, security (S) |
uv works as well as pip: uv venv && uv pip install -r requirements.txt.
Layers¶
| Layer | Holds | May import | Never |
|---|---|---|---|
p0_common |
settings, logging, small helpers | - | business rules |
p1_domain |
data classes, domain errors, pure business rules | p0_common |
files, database, network, environment, logging, the clock |
p2_io |
repositories and clients of other systems | p0_common, p1_domain |
business rules, command-line arguments |
p3_services |
one operation each | p0_common, p1_domain, p2_io |
command-line arguments, printing |
p4_entrypoints |
the command line | p0_common, p1_domain, p3_services |
a repository or a client directly, business rules |
The command line never reaches a repository: p4_entrypoints may not import p2_io, so every
command goes through a service (ARCH005); a service builds the repositories it needs.
Component types¶
| Type | File | Public API | Test | Questions |
|---|---|---|---|---|
utility |
p0_common/<name>.py (verb_noun) |
<name>(...) |
unit | 2: what it takes and returns, invalid input |
model |
p1_domain/<name>_model.py |
class <Name> (a data class) |
unit | 4: required fields, valid values, fields that never appear in a log, frozen or not |
error |
p1_domain/<name>_error.py |
class <Name>Error |
unit | 2: the exit code, what the message must never say |
logic |
p1_domain/<name>.py (verb_noun) |
<name>(...) |
unit | 3: the rule, invalid input, rounding |
repository |
p2_io/<name>_repository.py |
class <Name>Repository |
integration | 4: where and in which format, not found, a crash while writing, two writers |
client |
p2_io/<name>_client.py |
class <Name>Client |
integration | 3: timeout, retries, the other system down |
service |
p3_services/<name>.py (verb_noun) |
<name>(...) |
integration | 4: the steps, missing data, run twice, all or nothing |
cli |
p4_entrypoints/<name>_cli.py |
main(argv) -> int |
unit | 3: bad arguments, exit codes, what goes to stdout and stderr |
Business examples (archvow example add, Concepts) go on cli (the arguments and files in, what it prints and its exit code out: the default home of a ticket's examples), logic and utility; their tests are unit tests, like these types' own.
init creates two foundations: config (Config, load_config(), read from the environment)
and logging_setup (setup_logging(), called once by the entry points: the only place that
configures logging, ARCH059; every module logs through logging.getLogger(__name__)). The parameters of a
utility, logic or service function are the implementer's, unless the spec fixes them with
--signature.
Rules¶
archvow's generic rules (ARCH*, STY*, and the families chosen with -a rules=: GDPR, TST,
DORA), ruff (PEP 8, docstrings, annotations, security) and mypy (make check: every function
typed). See Rules.
What must never happen¶
| Guide word | Typical hazard | Example invariant |
|---|---|---|
| missing | a missing file is processed as an empty one | "a missing input stops with a clear error" |
| partial | a file is half written when the disk is full | "a file is complete or absent" (write a temporary file, then rename it) |
| repeated | running twice applies the change twice | "running twice gives the same result as once" |
| exposed | a secret appears in a log | "secrets never appear in a log or an output" |
| concurrent | two runs overwrite each other | "two runs never lose a change" |
Running¶
make run CLI=invoices ARGS="pay F-42" # python -m <package>.p4_entrypoints.invoices_cli pay F-42
make check # ruff, mypy, archvow check
make test # every test, with coverage
archvow next ends with the run line of each cli component once it and everything it uses
is coded: Try it locally: python -m <package>.p4_entrypoints.<name>_cli --<setting> <value> --help.
To give the program a command of its own, add [project.scripts] to pyproject.toml (an
architect approves the change).
The finished example¶
The archvow repository holds a finished project of this template: examples/python-app,
invoicing - a command line that marks invoices paid, one JSON file per invoice. Its spec was
written with archvow commands, its code from the specs, and every check passes:
archvow check --complete, ruff, mypy and the tests, including its three invariants (an invoice
never has a negative amount, an invoice file is complete or absent, paying twice is paying
once).
cd examples/python-app
python3 -m pip install -r requirements.txt
make check && make test
mkdir -p data && echo '{"number": "F-7", "customer": "Ada", "amount": "9.90", "status": "sent"}' > data/F-7.json
make run CLI=invoices ARGS="--data-dir data pay F-7" # F-7 Ada 9.90 paid