Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v7
- run: uv sync --locked
- run: uv export --frozen --format requirements.txt > dependency-inventory.txt
- uses: actions/upload-artifact@v7
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
fetch-depth: 0

- uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v7

- name: Validate commit messages
run: uv run --no-sync python -m tools.xtask commit-check --range "origin/${{ github.base_ref }}..HEAD"
Expand All @@ -39,7 +39,7 @@ jobs:
with:
fetch-depth: 0

- uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v7

- name: Install dependencies
run: uv sync --locked
Expand All @@ -60,7 +60,7 @@ jobs:
with:
fetch-depth: 0

- uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v7

- name: Read project version
id: version
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ dist/
.env
.env.*
!.env.example
.mypy_cache/
.ruff_cache/
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ Technical operating rules for this Python (`uv` + FastAPI) repository template.
## 2. Toolchain & Validation

- Package & environment manager: `uv` with `pyproject.toml` and `uv.lock` (`requirements.txt` and Node.js tooling are forbidden).
- Compiler & static safety: preserve `[tool.policy]` flags in `pyproject.toml` and AST rules in `tools/lint_check.py` (strict parameter/return annotations, no `Any`, no bare `except:`, no mutable defaults, no `assert`/`print` in `src/`, no `eval`/`exec`/`shell=True`, no boolean flag parameters in public APIs).
- Enable hooks locally with `git config core.hooksPath .githooks` and run `uv run python -m tools.xtask validate` (`TOTAL PASS=8 FAIL=0`) before opening or updating any pull request.
- Do not run `black`, `ruff format`, or `prettier` in hooks, CI, or pre-commit steps.

## 3. Code Layout & Architecture

- Organize domain logic under `src/app/modules/<domain>/` as a six-file layered modular layout (`entity.py`, `dto.py`, `repository.py`, `service.py`, `controller.py`, `module.py`).
- Enforce unidirectional imports: `controller` calls `service` and `dto` (never `repository`); `entity` and `dto` must not import `service`, `repository`, or `controller`.
- Keep every source and documentation file at or below **500 lines**.
- Document all modules and public classes/functions in `src/` with docstrings and keep every source and documentation file at or below **500 lines**.

## 4. Commit, Dependency & License Policy

Expand Down
5 changes: 5 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ The included `src/app/modules/math/` module demonstrates this pattern with an ad
3. Add functional tests in `tests/test_unit.py` and `tests/test_integration.py`, plus boundary assertions in `tests/test_architecture.py`.
4. Run `uv run python -m tools.xtask validate` to verify all eight gates pass.

## Strict AST Policy & Tripwires

- **Policy Lock**: `pyproject.toml` `[tool.policy]` and `tools/lint_check.py` forbid mutable default arguments, bare `except:`, `assert`/`print` in `src/`, dynamic `eval`/`exec`/`shell=True`, `Any` annotations, and public `bool` parameters while enforcing docstrings and full sync/async annotations.
- **Immutable Guardrails**: `tests/test_architecture.py` fails if `[tool.policy]` is weakened, formatter sections are added, or AST lint rules are removed.

## Monorepo Variant Architecture

When scaling into multiple Python services and shared libraries, adopt the `uv` workspace layout:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Production-ready Python (`uv` + FastAPI) repository template featuring a native
## Key Features

- **100% Native Python + `uv` Tooling**: Managed via `uv` (`pyproject.toml` + `uv.lock`) with native AST/compilation checks (`tools/*.py`) and zero Node.js or external formatter dependencies.
- **Strict AST & Annotation Policy Lock**: Enforces complete sync/async type annotations, forbids `Any`, bare `except:`, mutable default args, `assert`/`print` in `src/`, dynamic `eval`/`exec`/`shell=True`, and public `bool` parameter flags; `tests/test_architecture.py` locks all `[tool.policy]` settings.
- **Layered Modular Architecture**: Reference domain module (`src/app/modules/math/`) separating `entity`, `dto`, `repository`, `service`, `controller`, and `module` layers with automated boundary tests.
- **Eight Standardized Validation Gates**: `lint`, `typecheck`, `unit tests`, `integration and architecture tests`, `cooldown`, `hygiene`, `notices`, and `release`.
- **Supply-Chain Hardening**: 3-day dependency publish-age cooldown (`exclude-newer = "3 days"`), CodeQL static analysis, and automated SBOM/dependency inventory artifacts.
Expand Down Expand Up @@ -53,8 +54,8 @@ uv run python -m tools.xtask release --check # Verify pyproject.toml version ma

| Gate | Implementation | Purpose |
| :--- | :--- | :--- |
| `lint` | `tools/lint_check.py` | AST lint rules, forbidden APIs, `compileall` |
| `typecheck` | `tools/lint_check.py` | Return/parameter annotation verification |
| `lint` | `tools/lint_check.py` | Strict AST security/idiom rules, docstrings, policy lock |
| `typecheck` | `tools/lint_check.py` | Sync/async annotation checks and `Any` prohibition |
| `unit tests` | `uv run pytest tests/test_unit.py` | Fast unit test execution |
| `integration and architecture tests` | `uv run pytest tests/test_integration.py tests/test_architecture.py` | FastAPI endpoints and layer boundaries |
| `cooldown` | `pyproject.toml` (`exclude-newer = "3 days"`) | 3-day package release cooldown |
Expand Down
Loading
Loading