Architecture¶
Internal structure and design principles for azure-functions-scaffold.
Overview¶
A CLI tool built with Typer and Jinja2. It provides offline-capable, deterministic project generation for Azure Functions Python v2.
Runtime Flow¶
new Command¶
- CLI Parsing:
cli.pyreceives user input and options via Typer. - Options Normalization:
scaffolder.pycreates aProjectOptionsinstance. - Template Discovery:
template_registry.pyidentifies the requested template path. - Context Preparation:
models.pybuilds theTemplateContextobject. - Generation:
generator.pyprocesses Jinja2 templates and writes to the filesystem. - Post-Processing:
scaffolder.pyinitializes git or runs optional checks if requested.
add Command¶
- Root Verification:
generator.pyensures the target directory is a valid scaffolded project. - Function Rendering:
generator.pycreates the function module and test file. - Registration:
generator.pyupdatesfunction_app.pywith the new import and registration. - Settings Update:
generator.pyensureshost.jsonandlocal.settings.jsonhave required entries.
Module Boundaries¶
| Module | Responsibility |
|---|---|
cli.py |
Entry point, CLI command definitions, Typer logic. |
scaffolder.py |
High-level workflow coordination and orchestration. |
generator.py |
Jinja2 rendering, file system I/O, placeholder expansion. |
template_registry.py |
Mapping template names to source directories. |
models.py |
Data structures, type definitions, and validation logic. |
errors.py |
Custom exception types for the scaffolding lifecycle. |
templates/ |
Source Jinja2 and static files for project generation. |
Data Model¶
TemplateContext: Flat dictionary containing all variables for Jinja2 rendering.ProjectOptions: Frozen dataclass for validated CLI inputs.TemplateSpec: Metadata for a trigger template (name, description, default files).PresetSpec: Configuration object defining which linters and test tools to include.ScaffoldError: Base exception class for all tool-specific errors.
Template System¶
- Bundled: All templates are shipped with the package; no network calls required.
- Offline: No external API dependencies during the generation process.
- Deterministic: Given the same inputs, the generated output is identical every time.
- Conditional Rendering: Uses Jinja2 logic for optional features like OpenAPI or validation.
Design Constraints¶
- Python v2 Programming Model Only: Does not support the legacy v1 model.
- Zero Runtime Dependencies for Generated Projects: Generated code uses standard libraries or specified Azure packages only.
- Explicit over Implicit: No hidden configuration files; all generation logic is visible in templates.