Relying solely on unit tests is insufficient for a sovereign infrastructure, as tests only explore the interleavings explicitly conceived by the developer24. To mathematically prove that the state-machine transitions of the Passport lifecycle and concurrent recovery operations do not violate the defined invariants, peer-reviewed formal methods are highly recommended.
The Temporal Logic of Actions (TLA+) and its higher-level abstraction, PlusCal, are recommended for modeling the system25. In TLA+, the system is modeled by specifying the initial state and defining the next-state relation (Spec == Init /\ [][Next]_vars)26. By modeling the Optimistic Concurrency Control (OCC) logic, the TLC model checker can explore every possible concurrent interleaving of multiple WSGI processes attempting to supersede a passport simultaneously7. The model checker will mathematically prove whether a race condition exists that could lead to a "Lost Update" or a split-brain identity state9.
While Alloy is a powerful tool for relational modeling, it is deemed overkill for this specific stage of development; engineering effort should be heavily focused on TLA+ to verify concurrency safety24. Additionally, Property-Based Testing (e.g., utilizing Python's Hypothesis library) is highly recommended for verifying the idempotency of migrations and the determinism of JSON serialization formats.
Operations, Observability, Backup, and Supply Chain
Operational integrity requires strict adherence to security protocols. The project-provided requirement dictates that private keys, PII, and recovery shares must never be written to application logs. Observability pipelines must utilize structured error formats emitting deterministic codes rather than raw exception traces.
To secure the software supply chain against poisoning attacks, Patefacere must align with Supply-chain Levels for Software Artifacts (SLSA) Level 2 standards. A CycloneDX Software Bill of Materials (SBOM) must be produced for all Python dependencies. Furthermore, pip-tools must be utilized for rigorous dependency pinning and cryptographic hash checking during deployment.
Database backup strategies must prevent file-level corruption. For the initial SQLite implementation, backups should be conducted via Litestream or the native .backup API, ensuring that snapshots are transactionally consistent. Regular restoration drills are mandatory and must mathematically prove the continuity of the identity log post-restoration.
SQLite-to-Production-Storage Analysis
The architectural transition from SQLite to MySQL is driven by the need for robust concurrency handling, but the migration itself introduces immense risk to the identity log. This migration must utilize idempotent migration scripts, such as those generated by Alembic.
Idempotency guarantees that if a migration script fails midway and is re-run, it will not corrupt the database. This is achieved by strictly utilizing CREATE TABLE IF NOT EXISTS directives and checking the information schema for the existence of columns and indices prior to executing modifications. Before the application write-path is cut over to MySQL, a comprehensive shadow-read validation pass must be executed to ensure absolute parity between the legacy SQLite state and the new MySQL state.
Full Staged Migration Roadmap
The realization of the target architecture is managed through a meticulously phased 16-stage roadmap, designed to minimize disruption and isolate risk.
- Prerequisites: Secure, read-only repository access.
- Intent: Extract and cryptographically secure the current state of the prototype. Verify all facts outlined in the Repository Verification Required Plan (Section 4). Establish a baseline SBOM to map current dependencies.
- Stop Condition: Read-only access is established, and a full audit report is generated without altering any existing configuration.
- Intent: Refactor the domain models to establish a ubiquitous language. Python classes and variables are renamed to strictly match Constitutional terminology (e.g., changing generic Credential objects to specific CitizenIdentity objects).
- Data Changes: No underlying schema changes occur in this phase.
- Intent: Architecturally separate Identity, Credential, and Assurance logic into distinct, isolated Python modules.
- Tests: Implement strict unit tests that fail if modules circularly import or breach domain boundaries.
- Intent: Introduce deterministic database migration tooling. This utilizes SQLite's user_version pragmas or custom standard-library schema tracking tables.
- Invariant: Prove that all forward and backward migrations are mathematically idempotent.
- Intent: Implement Optimistic Concurrency Control (OCC) by introducing version locking on SQLite rows. This prevents concurrent replacement races7.
- Tests: Execute concurrency load tests simulating simultaneous /api/passport/replace calls to prove race conditions are neutralized.
- Intent: Deploy the async CQRS projection generator. Ensure that the public /api/registry endpoints only query the sanitized registry_cache table, permanently severing public read access from the authoritative identity table.
- Intent: Refactor all hardcoded cryptographic logic into the uniform CryptoProvider interface. The ctypes OpenSSL implementation (libcrypto.so) is formalized here to handle standard-library constraints15.
- Rollback: Immediately revert to the hardcoded provider if the new abstraction fails to generate or verify test signatures.
- Intent: Upgrade the reference cryptography to output payloads conforming to W3C Verifiable Credentials and established DID document patterns, while strictly maintaining the zero-dependency constraint.
- Intent: Execute an internal ETL process mapping the legacy, flat user records into the new relational Identity -> Passport supersession graph.
- Phase 9: Recovery and Rotation Hardening
- Intent: Implement the temporal friction logic. Timelocks and multi-party approval requirements are integrated into the Python logic for all major civic changes.
- Phase 10: Trust-Policy Separation
- Intent: Extract all hardcoded constitutional trust rules from Python if/else route blocks. These are migrated into declarative JSON policies that are evaluated deterministically by the pure-function engine.
- Phase 11: Receipt and Evidence Hardening
- Intent: Activate the Evulgare integration contract. The fetcher module begins strictly verifying SHA-256 hashes before allowing external assurance payloads to influence the evaluation engine.
- Phase 12: Production Database Migration (If Justified)
- Intent: Migrate the authoritative data store from SQLite to MySQL, triggered via secure environment variable configurations within Passenger1.
- Data Changes: Execute a full ETL pipeline, strictly followed by a shadow-read verification phase to guarantee zero data loss.
- Phase 13: Partition and Continuity Work
- Intent: Implement offline verification fallbacks. Stale status caching (CRLs) is deployed to ensure verifications survive transient database or network partitions.
- Phase 14: Independent Review
- Intent: Subject the entire architecture, cryptographic ctypes bindings, and TLA+ models to a rigorous external audit.
- Stop Condition: All critical OWASP vulnerabilities and architectural logic flaws must be remediated.
- Phase 15: Staged Production Acceptance (Go Live)
- Intent: Execute the final cutover to the authoritative production state. Perform actual-host acceptance testing on the target cPanel/Passenger environment.
- Phase 8: Credential and Passport Migration
- Phase 7: Audited Public-Key Reference Implementation
- Phase 6: Cryptographic-Provider Abstraction
- Phase 5: Public/Private Record Separation (CQRS Implementation)
- Phase 4: State-Machine Hardening (Lifecycle Security)
- Phase 3: Schema Versioning (Database Idempotency)
- Phase 2: Domain Separation (Bounded Contexts)
- Phase 1: Truth-Boundary and Terminology Corrections (Policy Alignment)
- Phase 0: Repository-Enabled Verification (Baseline Evidence)
Rollback, Acceptance, and Independent Review
To manage deployment risk, rigid rollback conditions are established. Any failure in cryptographic signature verification, the detection of a split-brain state in the MySQL cluster, or an inability to resolve Evulgare hashes mandates an immediate and automatic rollback to the preceding deployment stage.
Production Acceptance is gated by a strict sign-off matrix. Deployment is authorized only upon the presentation of zero critical Common Vulnerabilities and Exposures (CVEs), the documented success of a full backup and restore drill, and a 100% pass rate in the property-based testing suite.
Furthermore, an independent review is a non-negotiable requirement. The system must not claim independent certification based solely on internal, self-executed test suites. A comprehensive, third-party cryptographic engineering review of the ctypes OpenSSL bindings and the FIDO2 CBOR decoding logic is absolutely mandatory prior to initiating Stage 15.
Decision Table
| Decision | Option Selected | Justification |
|---|---|---|
| Database | SQLite transitioning to MySQL | Broad shared hosting support (cPanel); MySQL provides the row-level locking necessary to scale beyond SQLite's strict concurrency limits5. |
| Framework | WSGI / Python Standard Library | Radically minimizes supply chain poisoning risk; adheres to the project request for zero external UI/Node dependencies. |
| Consistency | Strong (Authoritative Write-Model) | Absolutely prevents the creation of duplicate identities or double-spend passport replacement attacks10. |
| Crypto Abstraction | ctypes wrapping libcrypto.so | Enables robust ECDSA and RSA verification natively without requiring external pip packages, fulfilling the standard library constraint15. |
Conflict Register
Architectural conflicts inevitably arise during system design and must be explicitly resolved.
Conflict: The realities of Shared Hosting (cPanel) versus the security mandate for strict KMS/HSM secret custody. Resolution: This is resolved through the CryptoProvider abstraction layer. For Stage 0, secure environment variables (os.environ) populated by Passenger manage custody1. The architecture mandates that high-trust civic keys must eventually migrate to external signing hardware, severing them from the web server's memory space.
Conflict: Preserving citizen Unlinkability versus publishing a Public Civil-Registry.Resolution: This is resolved via the implementation of the CQRS pattern. Only explicitly public, non-correlatable civic hashes are projected into the registry_cache. The detailed transactional graphs and internal mappings remain strictly sequestered within the private, authoritative write-model.
Prioritized Engineering Backlog
To execute the immediate next steps following Phase 0, the engineering backlog must prioritize the highest-risk technical components:
- Extract the CryptoProvider interface and solidify the ctypes bindings for EVP_DigestVerifyInit and ECDSA_verify against libcrypto.so.
- Develop the native Python CBOR parser required to decode WebAuthn authData payloads accurately without third-party dependencies.
- Implement Alembic (or standard-library equivalent) idempotent schema migrations.
- Write comprehensive property-based tests for JSON serialization and projection sanitation.
- Develop and test the async CQRS public registry generator.
Residual Unknowns and Prohibited Claims
To manage expectations and enforce transparency, the following prohibited claims must be explicitly acknowledged: