Logo: Architecture As Code Python

Architecture As Code Python

Organisatioun
l-gevity
architecture-as-code-python

Python implementation of the `architecture-as-code` pattern. Per-package `architecture.toml` files merged into a single `import-linter` config and enforced via `lint-imports` (over a Grimp-built import graph). TRIGGER when: implementing or extending architecture-as-code in a Python repo, debugging an `import-linter` contract, or adapting the assembler. SKIP for routine edits inside a governed package. Reads in conjunction with `architecture-as-code` (the pattern, source of truth for schema, rule placement, anti-patterns, and audit checklist) — this skill defines only the Python-specific encoding, assembler code, and gotchas.

Add to TypingMind

Iwwersiicht

Editeurl-gevity
Repositoryl-gevity-skills
Skill-Nummarchitecture-as-code-python
Stären
72
Forks
13
Matgeliwwert Dateien
Nëmmen Instruktiounen
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    l-gevity huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Architecture As Code Python an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/l-gevity/l-gevity-skills/tree/main/.agents/skills/architecture-as-code-python
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/l-gevity/l-gevity-skills.git /tmp/l-gevity-skills
mkdir -p .claude/skills
cp -r /tmp/l-gevity-skills/.agents/skills/architecture-as-code-python .claude/skills/architecture-as-code-python
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Architecture As Code Python an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Architecture As Code Python automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Architecture As Code Python net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Architecture-as-Code — Python Implementation

Prerequisite. Read architecture-as-code first. The schema (§1), subsystems (§2), forbidden edges (§3), rule placement (§4), assembler concept (§5), and anti-patterns / audit (§6) are defined there and apply identically here. This file documents only what is Python-specific.

1. File format

  • Filename: architecture.toml. Plain TOML — no Python code, no imports.
  • TOML arrays-of-tables: [[subsystems]], [[forbidden]]. [[components]] is read as a deprecated alias for [[subsystems]] (§3).
  • Pattern syntax: dotted module paths (mypkg.core.tier1). The package and all submodules match by default; set single = true to match only the exact module.
  • Subsystem patterns may overlap (e.g. mypkg.core and mypkg.core.tier1 both match files under mypkg/core/tier1/). That's fine — import-linter checks each contract independently; there's no first-match-wins.
toml
# architecture.toml — example for a package with internal layering
[[subsystems]]
name = "core-facade"
pattern = "mypkg.core.api"           # public sub-package = the facade

[[subsystems]]
name = "core-tier1"
pattern = "mypkg.core.tier1"

[[subsystems]]
name = "core-tier3"
pattern = "mypkg.core.tier3"

[[subsystems]]
name = "core-other"
pattern = "mypkg.core"               # whole-package catch-all, last

[[forbidden]]
# Efferent — self-knowledge, lives in own file.
from = "core-*"
to = "*"
except_to = ["core-*"]
why = "Core purity: no imports outside the core package."

[[forbidden]]
# Internal layering.
from = "core-tier3"
to = "core-tier1"
why = "Tier 3 must go through tier 2."

Parametric "not equal" syntax for cross-domain isolation: !{from.captured.domain} (single braces).

[!NOTE] Facade pattern in Python. Python's idiomatic facade is a sub-package (e.g. mypkg.core.api) exposing public API via __init__.py and __all__. The "single file as facade" pattern from the JS skill maps awkwardly here; prefer a public sub-package plus forbidden edges that ban imports to the internal sub-packages.

2. Specialized contract types

The assembler emits forbidden contracts by default. For two common shapes import-linter offers more specific contract types that produce cleaner violations:

  • Sibling-isolation across N subsystems → one independence contract listing the N module patterns.
  • Strict tier ordering (e.g. tier1 < tier2 < tier3, where higher tiers may import lower) → a layers contract. Optional — explicit [[forbidden]] edges between specific tiers also work.

3. Assembler

A small Python script invoked by pre-commit and CI. Discovers all architecture.toml files, merges them, generates a .importlinter config in INI form, and invokes lint-imports.

Why generate .importlinter rather than mutate pyproject.toml? The generated file is a build artifact (gitignored alongside .import_linter_cache/); the source of truth is the per-package architecture.tomls. import-linter natively reads .importlinter ahead of pyproject.toml.

python
# tools/arch_lint.py
import subprocess
import sys
import tomllib
from pathlib import Path

# Coverage gate (pattern Directive 7): the graph roots must cover every source
# package. Derive them; one hardcoded root silently excludes whatever top-level
# directory lands next.
SOURCE_PACKAGES = sorted(
    p.name
    for p in Path(".").iterdir()
    if p.is_dir() and (p / "__init__.py").exists() and not p.name.startswith(".")
)
GENERATED_CONFIG = Path(".importlinter")

# 1. Discover — recursive walk, skipping the configured ignore-list
#    (.venv, dist, build, .tox, __pycache__, .import_linter_cache).
arch_files = sorted(
    Path(".").rglob("architecture.toml"),
    key=lambda p: -len(p.parts),  # deeper-first
)

# 2. Concat. [[components]] is the deprecated alias for [[subsystems]]
#    (pattern Directive 1): warn on it, reject a file that carries both.
subsystems, forbidden = [], []
for f in arch_files:
    data = tomllib.loads(f.read_text(encoding="utf-8"))
    if "subsystems" in data and "components" in data:
        sys.exit(f"{f}: declare [[subsystems]] or [[components]], not both")
    if "components" in data:
        print(f"{f}: [[components]] is a deprecated alias for [[subsystems]]", file=sys.stderr)
    subsystems.extend(data.get("subsystems", data.get("components", [])))
    forbidden.extend(data.get("forbidden", []))

# 3. Expand wildcards against the live registry.
names = [c["name"] for c in subsystems]

def expand(spec, except_=None):
    if isinstance(spec, dict):
        return spec  # parametric — handled separately
    items = spec if isinstance(spec, list) else [spec]
    def resolve(lst):
        out = []
        for t in lst:
            if t == "*":
                out.extend(names)
            elif t.endswith("*"):
                p = t[:-1]
                out.extend(n for n in names if n.startswith(p))
            else:
                out.append(t)
        return out
    types = resolve(items)
    if except_:
        sub = set(resolve(except_))
        types = [t for t in types if t not in sub]
    return types

# 4. Emit import-linter contracts (INI format).
subsystem_pattern = {c["name"]: c["pattern"] for c in subsystems}
subsystem_single  = {c["name"]: c.get("single", False) for c in subsystems}

if not SOURCE_PACKAGES:
    sys.exit("No source packages discovered — the import graph would be empty.")
ini = ["[importlinter]", "root_packages ="]
ini.extend(f"    {p}" for p in SOURCE_PACKAGES)
ini.append("")
for i, edge in enumerate(forbidden):
    src = expand(edge["from"], edge.get("except"))
    dst = expand(edge["to"],   edge.get("except_to"))
    if not src or not dst:
        continue   # nothing to forbid after exceptions

    src_modules = [subsystem_pattern[n] for n in src]
    dst_modules = [subsystem_pattern[n] for n in dst]
    as_packages = not any(subsystem_single[n] for n in src + dst)

    ini.append(f"[importlinter:contract:{i}]")
    ini.append(f"name = {edge['why'][:80]}")
    ini.append("type = forbidden")
    ini.append("source_modules =")
    ini.extend(f"    {m}" for m in src_modules)
    ini.append("forbidden_modules =")
    ini.extend(f"    {m}" for m in dst_modules)
    if not as_packages:
        ini.append("as_packages = False")
    ini.append("")

GENERATED_CONFIG.write_text("\n".join(ini), encoding="utf-8")

# 5. Invoke lint-imports
result = subprocess.run(
    ["lint-imports", "--config", str(GENERATED_CONFIG)],
    check=False,
)
sys.exit(result.returncode)

Install & run:

bash
pip install import-linter      # pulls in grimp; tomli on Python <3.11
python tools/arch_lint.py      # discover + assemble + lint

Pre-commit hook:

yaml
# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: arch-lint
        name: "Architecture lint"
        entry: "python tools/arch_lint.py"
        language: system
        pass_filenames: false

language: system is required — lint-imports must run inside the project's virtualenv to import the analyzed packages.

Gitignore:

.importlinter            # generated by tools/arch_lint.py
.import_linter_cache/    # import-linter's own cache

4. Output Contract

When applying this implementation, emit:

Scope:          <repo / package / subsystem path>
Decision:       Add architecture.toml | Update assembler | Update import-linter config | Blocked
Generated config:<path, if any>
Contracts changed:<forbidden / layers / independence contracts>
Verification:   <lint-imports command / assembler command / Not run + reason>
Next action:    <specific file edit, package install, cache clear, or unresolved question>

5. Python-specific gotchas

[!NOTE] Dynamic imports bypass enforcement. import-linter reads static import and from ... import statements via Grimp. Imports through importlib.import_module(...), __import__, or string-based dispatch don't appear in the graph. If a package uses dynamic imports for plugin loading, mark the entry-point as a single-module declared subsystem (single = true) so its rules are explicit, and consider banning the dynamic style elsewhere.

[!IMPORTANT] The graph root is the coverage gate. import-linter builds its graph from root_package / root_packages. A new top-level package or directory outside that list is not in the graph, so no contract can fail on it and the run still reports success — the Python form of pattern Directive 7 ("the emitted rule's scope must equal the linted source set"). Derive root_packages from the tree at assembly time rather than hardcoding one root, and fail the assembler when the derived list is empty or a top-level source package is missing. import-linter has no native file-existence rule (Directive 8), so that comparison — packages on disk vs. packages in the generated config — is the check that catches an undeclared directory.

[!NOTE] import-linter * is single-segment. In forbidden_modules and similar fields, mypkg.* matches mypkg.foo but not mypkg.foo.bar. The pattern's prefix wildcards (core-*) operate on subsystem names and are expanded by the assembler before contracts are emitted, so they don't hit this limit. But if you write raw module patterns yourself, mind the difference.

[!NOTE] import-linter forbids; it never requires. An aspect coverage check — every subsystem in the governed set uses the mechanism — has no contract type. Express it as a grimp-based test over the same registry; defect-shift-left places that check.

[!NOTE] Cache staleness during refactors. .import_linter_cache/ speeds up subsequent runs but can mislead during heavy refactors. Delete it if results don't match what your import statements actually say.

[!NOTE] Root package must be importable. import-linter imports the root package to walk it. Make sure pip install -e . (or equivalent) has been run in the active venv before invoking the assembler.

[!NOTE] Mixing pattern-level and subsystem-level wildcards. A single rule that uses both mypkg.* (single-segment, import-linter native) and core-* (multi-match, assembler-expanded) will surprise you. Subsystem- name wildcards are the assembler's domain; raw * in import-linter patterns is single-segment only. Don't mix in one rule.

Heefeg gestallte Froen

Wat mécht de KI-Skill Architecture As Code Python?

Python implementation of the `architecture-as-code` pattern. Per-package `architecture.toml` files merged into a single `import-linter` config and enforced via `lint-imports` (over a Grimp-built import graph). TRIGGER when: implementing or extending architecture-as-code in a Python repo, debugging an `import-linter` contract, or adapting the assembler. SKIP for routine edits inside a governed package. Reads in conjunction with `architecture-as-code` (the pattern, source of truth for schema, rule placement, anti-patterns, and audit checklist) — this skill defines only the Python-specific enc...

Firwat Architecture As Code Python op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Architecture As Code Python besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Architecture As Code Python an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/l-gevity/l-gevity-skills/tree/main/.agents/skills/architecture-as-code-python an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Architecture As Code Python benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Architecture As Code Python benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Architecture As Code Python domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Architecture As Code Python gratis?

Jo. l-gevity huet de Skill ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇