Python reference consumer proving factory reuse across different languages, schemas, and domains.
Same factory release (1.4.0) as the TypeScript billing API. Different language, different schema contract, different PII requirements - zero copied orchestration logic.
The reuse proof · Quick start · API reference · Design patterns · Tests · Factory contract · Contributing
| Property | Billing API | Notification API |
|---|---|---|
| Language | TypeScript | Python |
| Framework | Fastify | FastAPI |
| Compatibility check | OpenAPI (oasdiff breaking) |
JSON Schema (fixture validation) |
| Security constraint | Tenant isolation | PII redaction |
| Delivery contract | API reliability | Outbox, idempotency, retry |
| Factory release | 1.4.0 | 1.4.0 |
| Orchestration code copied | - | None |
| Repo | Role |
|---|---|
ai-software-factory-contract |
Factory engine - same release that runs against this repo |
ai-factory-trusted-verifier |
Posts factory-contract/acceptance for event schema compatibility |
factory-reference-billing-api |
TypeScript billing API - the other reference consumer |
| This repo | Python notification API - reuse proof, event compatibility, PII controls |
The AI Software Factory Contract claims Build Once means reusable production machinery, not a copy-pasted workflow. This repository is the proof.
| Property | Billing API | Notification API |
|---|---|---|
| Language | TypeScript | Python |
| Framework | Fastify | FastAPI |
| Compatibility check | OpenAPI (oasdiff breaking) |
JSON Schema (fixture validation) |
| Security constraint | Tenant isolation | PII redaction |
| Delivery contract | API reliability | Outbox, idempotency, retry |
| Factory release | 1.4.0 | 1.4.0 |
| Orchestration code copied | - | None |
The factory's five stages run against this repo using the same coordinator, the same Claude executor, and the same SKILL.md procedures. The only difference is the RepositoryContract in .factory/repository-contract.yaml, which declares this repo's own build commands, compatibility path, and PII policies.
Prerequisites: Python ≥ 3.12, uv (install), Docker (optional, for PostgreSQL)
git clone https://github.com/Darshitpandya/factory-reference-notification-api.git
cd factory-reference-notification-api
uv sync --devuv run pytest -q
# 17 tests: notifications, PII redaction, outbox patternuv run python scripts/check-event-compatibility.py
# Validates all fixtures in contracts/events/fixtures/ against the current schemauv run ruff check .export DATABASE_URL=postgresql://notifications:notifications@localhost:5432/notifications
uv run python -m src.notifications.app
# FastAPI on :3003; docs at http://localhost:3003/docsOr with Docker Compose:
docker compose -f deploy/docker-compose.yaml up -dAccept a notification request. Returns 202 Accepted immediately; delivery is handled asynchronously via the outbox.
curl -X POST http://localhost:3003/v1/notifications \
-H "Content-Type: application/json" \
-d '{
"eventType": "invoice.issued",
"recipientId": "user-001",
"payload": {
"entityId": "inv-001",
"tenantId": "tenant-a",
"timestamp": "2026-01-01T00:00:00Z",
"metadata": {"amount_cents": 10000, "currency": "USD"}
},
"idempotencyKey": "unique-key-per-request-min-8-chars"
}'Response:
{
"notificationId": "uuid",
"outboxId": "uuid",
"status": "ACCEPTED",
"idempotencyKey": "unique-key-per-request-min-8-chars"
}Idempotency: Submitting the same idempotencyKey twice returns the existing outboxId without creating a duplicate. Delivery intent is persisted before the 202 response.
Supported eventType values: invoice.issued, invoice.overdue, invoice.paid, account.created, account.suspended
PII: recipientId is an opaque ID, not an email address or phone number. The payload is redacted before logging.
Returns delivery status for a notification by ID.
{"status": "ok", "version": "1.0.0"}Delivery intent is written to the notification_outbox table before the 202 response is sent. This guarantees at-least-once delivery even if the process crashes between acknowledgment and actual delivery.
Request → validate → persist to outbox → 202 response
│
background worker
│
deliver → mark DELIVERED
(or) retry up to 5× → mark FAILED
src/notifications/pii.py applies redaction before any logging, error tracing, retry payload, or audit export:
from src.notifications.pii import redact_dict
safe = redact_dict(payload)
logger.info("notification_accepted", extra={"payload_keys": list(payload.keys())})
# NOT: logger.info("notification", extra={"payload": payload})Fields named email, phone, address, ssn, creditCard, password, token, secret, apiKey are always redacted. Email, phone, and SSN patterns in string values are also redacted.
contracts/events/notification-requested.schema.json is the canonical event contract. Any PR that removes an eventType value or adds a required field is a breaking change and will be caught by scripts/check-event-compatibility.py and the trusted verifier.
uv run pytest -q # all 17 tests
uv run pytest tests/test_pii_redaction.py -v # PII tests only
uv run pytest tests/test_outbox.py -v # outbox pattern tests| File | What it covers |
|---|---|
tests/test_notifications.py |
Health, valid notification accepted, invalid event type, idempotency key validation |
tests/test_pii_redaction.py |
Email redaction, phone redaction, SSN redaction, dict traversal, no false positives |
tests/test_outbox.py |
New record insertion, idempotency (no duplicate), mark delivered, mark failed + attempt increment |
# .factory/repository-contract.yaml
consumedRelease: "1.4.0" # same as billing API
acceptance:
requiredChecks:
- factory-contract/acceptance
compatibilityBaselinePath: contracts/events/notification-requested.schema.json
piiPolicies:
- pii-must-be-redacted-in-logs
- no-pii-in-retry-payloadsThe trusted verifier uses notification-requested.schema.json at the base SHA to detect breaking schema changes - equivalent to what oasdiff does for the billing API's OpenAPI spec.
The reference WorkOrder is in .factory/work-orders/notification-schema-update.yaml. To submit it via Port:
- Go to
app.getport.io→ Catalog → Work Orders → click ▶ Trigger Factory Run onwo-notification-schema-001 - Or run:
pnpm factory run --work-order wo-notification-schema-001 --release 1.4.0(requires coordinator running)
# Check all fixtures pass the current schema
uv run python scripts/check-event-compatibility.py
# Adding a new eventType value is non-breaking (backward compatible)
# Removing an eventType value is breaking (existing publishers break)
# Adding a required field is breaking
# Adding an optional field is non-breaking- PII must not appear in logs, traces, exceptions, retries, or audit exports -
src/notifications/pii.pyis the enforcement point - Delivery intent persisted before 202 response (no silent drops)
- No secret or token fields in AGENTS.md, work order files, or PR descriptions
- See SECURITY.md
See CONTRIBUTING.md.
MIT - see LICENSE.

