Adopting an existing project¶
How to bring archvow to a project that already has code, CI and deployment files, without breaking anything on the first day. The legacy code keeps running; archvow fails only on what is new, and the legacy shrinks until the project follows its spec.
The example is a typical PySpark project of a company:
devops/ RPM spec and Ansible playbook
scripts/ main.py, process_<name>.py, create_tables.hql
scripts_communs/ shell helpers shared by the company's projects
templates/ Oozie workflow and properties templates
tests/ tests, conftest.py, actuals/ and expecteds/
Jenkinsfile makefile requirements README.md sonar-project.properties .coveragerc
If several projects look like this one, first make a company template
with your defaults (Jenkins, Sonar, Oozie, internal image and index) and your deployment
files, in your company's pack (archvow pack template ~/packs/acme acme-pyspark --extends pyspark-pipeline,
then archvow pack add ~/packs/acme in the project); the steps below then use -t acme-pyspark. Files your own tools render later (Oozie templates/*.j2)
go in verbatim_folders, so they are copied untouched. For a single project, use
pyspark-pipeline with -a answers.
1. Initialise, keeping your files¶
On a branch:
git switch -c feature/ARCH-1-adopt-archvow
archvow init my_pipeline -t acme-pyspark -d "What my_pipeline does" -a architects=@acme/architects \
-a ai_tools=jetbrains-ai-chat
init writes the spec folder and the guards, and never overwrites a file you have: your
Jenkinsfile, makefile, requirements, sonar-project.properties and devops/ stay as
they are. Your README.md keeps its text; archvow adds its part (how to work with the spec)
at the end, between <!-- archvow:begin --> and <!-- archvow:end -->, with a comment
saying so - move it or edit around it freely: init --force rewrites only that part. A requirements file or a pyproject.toml means archvow does
not write its own requirements.txt; a makefile means no Makefile. Keeping your own Oozie
files? Add -a scheduler=none.
Your existing files do not get what archvow adds to its own (the checks in the CI, for instance). To see what they would be, initialise a reference project elsewhere with the same answers and merge the parts you want:
(mkdir -p /tmp/ref && cd /tmp/ref && archvow init my_pipeline -t acme-pyspark -a architects=@acme/architects --no-git)
diff /tmp/ref/Jenkinsfile Jenkinsfile # copy the "Architecture guards" stages into yours
At least, your CI must run archvow check, ruff check . and
pytest, and archvow check --base <target branch> on merge requests (with archvow doc --base <target branch> to attach the docs). Add archvow and
ruff to your requirements, pinned (archvow==<version>).
Code that stays where it is: --adopt¶
When the code already lives in the package (src/<package>/core/, crud.py, api/...), it does
not have to move into the layer folders. Add --adopt to init (or to init --force later):
archvow init app -t fastapi-service -a architects=@acme/architects --adopt
archvow reads the folder and file names it knows - foundations (core, config, utils...),
domain (models, schemas...), I/O (crud, db, readers, writers...), services or jobs,
entry points (api, routes, cli, main...) - and writes the mapping it proposes into
.archvow/project.vow, printed on screen:
layer_paths
p0_common [src/app/core/, src/app/utils.py]
p1_domain [src/app/models.py]
p2_io [src/app/crud.py]
p4_api [src/app/api/, src/app/main.py]
A path ending with / is a folder, any other one a file; the longest path wins. Files whose name
archvow does not know are listed, not guessed: an architect adds them by hand, or leaves them
out of the layers. The mapping is a guard: the architects review it in the merge request, and
mapping more code later is ARCH020 (where code sits decides what it may do).
The layer rules then apply where the files are (ARCH005 imports between layers, ARCH007,
SPK001-SPK003). The other code rules (SPK004-SPK014, FAPI001, FAPI004, FAPI005,
STY) run on every Python file, mapped or not, at their usual severity: archvow freeze (step 3)
accepts today's findings, so only new ones fail.
An existing module becomes a component where it is, with the contract it has today (its public functions with their signatures, classes, constants and routes):
archvow component add repository user -d "Users in the database: create, read, update" --file src/app/crud.py
Its layer must be its type's (a repository in p2_io), else archvow says which layer_paths
line is missing.
2. See where the project stands¶
archvow check
Typically: ARCH015 for each Python file outside the architecture (scripts/*.py),
ARCH016 for tests outside the test layout, ARCH023 for imports archvow does not know.
That is expected: none of this code has a spec yet.
ruff check . probably fails too, the legacy code was not written for it. Exclude the legacy
files, by name, in ruff.toml - the list will only shrink:
extend-exclude = [".archvow", "scripts", "tests/test_process_my_pipeline.py"] # legacy code, until it is migrated
Fix small shared files rather than excluding them (a conftest.py needs a docstring and
annotations, nothing more).
3. Freeze the legacy, and commit¶
archvow freeze # records today's violations in .archvow/frozen.json
archvow check # passes: frozen violations are reported as warnings
git add -A && git commit -m "Adopt archvow: spec, guards, frozen legacy"
From now on, any new violation fails, the frozen ones are warnings. The frozen list can
only shrink: adding to it in a branch is a guard change (ARCH020). The adoption merge request
passes archvow check --base main (there is nothing to weaken yet); the architects approve
it, then switch on the branch rules init printed.
A violation is recorded by rule, file and message. An archvow upgrade that changes what a rule
finds or says (the release notes tell) shows some frozen violations as fixed and new ones in
their place: run archvow freeze again in the upgrade merge request.
4. Write the spec of what exists¶
Describe the pipeline as it should be, with the normal commands
(Getting started): component add, show, specify, decision make, rule add, hazard add, invariant add.
One merge request, approved by the architects:
archvow component add schema sales -d "Input file: id string" -s NUM-1
archvow component add reader sales -d "Read one CSV file with a header; enforce SALES_SCHEMA" -s NUM-1 -u sales_schema
archvow component add transformation clean_sales -d "Keep the rows with an id" -s NUM-1 -u sales_schema
# ... writer, job, entry point; then the decisions, hazards and invariants
Table scripts move to ddl/ (git mv scripts/create_tables.hql ddl/001_<table>.sql, in
Spark SQL with CREATE TABLE IF NOT EXISTS): ./entrypoint.sh --ddl runs them.
With GDPR on (the default), the spec of each schema also classifies its columns (archvow
column set <schema> <columns> personal|special|none), and a job or writer handling personal data
answers its regimes' questions (P for GDPR); until then their code fails (PRIV001), unless the freeze
above recorded it. Leaving the privacy regimes out of -a rules=... keeps these rules off - switch them on when the legacy is in order.
5. Migrate, component by component¶
For each component in archvow next order: write it from its spec (yourself or with
the AI assistant: implement <component>), move the logic out of the legacy script, and delete
what is no longer used. As legacy files disappear:
archvow freeze # the list shrinks (allowed: only growing it is a guard change)
and remove them from extend-exclude in ruff.toml. Move the coverage and Sonar sources
from scripts to src (.coveragerc, sonar-project.properties), and point your
scheduler's files at ./entrypoint.sh (tables, then the entry point).
Done when¶
archvow freeze # "Froze 0 existing violation(s)"
git rm .archvow/frozen.json
archvow check --complete # every planned component is written; no error
ruff check . # with extend-exclude = [".archvow"] only
The project now follows its spec, and every change goes through it.