# System Map This document shows the system boundaries, replaceable module contracts, and primary operating flows for the Automation-Based Email List System. ## System Context ```mermaid flowchart LR human["Human architect
writes Markdown + gives
send-and-schedule directive"] agent["Persistent AI operator
documented skill + restricted
terminal access"] repo[("Public Git repository
Markdown, templates, schemas,
code, tests, sanitized receipts")] subgraph emailvm["Email-list VM"] container["Email-list Docker container
deterministic Python application"] runtime[("Private persistent volume
SQLite, backups, logs,
detailed receipts")] scheduler["Cron / VM scheduler
subscriber imports, welcomes,
due follow-ups, reconciliation"] container <--> runtime scheduler --> container end postmark["Postmark
delivery, broadcast unsubscribe,
suppression"] telemetry["Existing telemetry server
Postmark webhook ingestion
and campaign analysis"] recipient["Email recipient"] human -->|"writes finished campaign"| repo human -->|"one directive authorizes initial send
+ configured follow-up"| agent agent -->|"reads, validates, schedules,
verifies, and reports"| repo agent -->|"runs authorized deterministic commands"| container repo -->|"Git deployment / checked-out content"| container container -->|"provider adapter"| postmark postmark -->|"email"| recipient recipient -->|"open, click, unsubscribe,
complaint"| postmark postmark -->|"existing webhooks"| telemetry container <-->|"versioned telemetry contract"| telemetry container -->|"sanitized receipts only"| repo ``` ## Human Handoff and AI Operating Envelope ```mermaid flowchart LR human["Human"] handoff["Finished Markdown + directive
send now; resend apparent
non-openers in 4 or 5 days"] agent["Authorized AI agent"] cli["Deterministic CLI safety boundary"] send["Validate + send initial campaign"] schedule["Create durable follow-up schedule"] monitor["Monitor + verify + write receipt"] followup["Query telemetry + recheck suppressions
+ send one authorized follow-up"] exception["Return only unresolved exception
or scope change to human"] human --> handoff --> agent --> cli cli --> send --> schedule --> monitor --> followup --> monitor cli -->|"failed check, ambiguous authority,
or material change required"| exception --> human ``` The intended steady state has one human handoff, not one approval per mechanical step. The CLI enforces the authorization and safety boundary while the AI handles orchestration and exceptions. ## Application Modules and Replaceable Boundaries ```mermaid flowchart TB cli["CLI contract
--dry-run, --json, exit codes"] skill["AI skill
workflow, authorization,
and escalation rules"] scheduler["Scheduler entrypoint"] cli --> usecases["Application use cases
campaigns, subscribers, resends,
reconciliation, backups"] skill --> cli scheduler --> cli usecases --> campaign["Campaign module"] usecases --> subscriber["Subscriber module"] usecases --> authorization["Authorization guard"] usecases --> sendstate["Send-state module"] usecases --> receipt["Receipt module"] campaign --> renderer{{"Renderer contract"}} subscriber --> store{{"Storage contract"}} sendstate --> provider{{"Email-provider contract"}} usecases --> telemetrycontract{{"Telemetry contract"}} renderer --> markdown["v1: Markdown + templates"] store --> sqlite[("v1: SQLite")] provider --> postmark["v1: Postmark"] telemetrycontract --> telemetry["v1: existing telemetry server"] migrations["Versioned migrations"] --> sqlite backups["Backup / restore"] --> sqlite schemas["Versioned schemas"] -. "validate boundaries" .-> cli schemas -.-> renderer schemas -.-> telemetrycontract schemas -.-> receipt ``` The diamond-shaped contracts are deliberate swap points. Core campaign and subscriber rules depend on those contracts, not on Postmark, SQLite, a specific Markdown library, or the telemetry server's internal implementation. ## Campaign Send Flow ```mermaid sequenceDiagram participant Human as Human participant Agent as Authorized AI agent participant Repo as Git repository participant CLI as Email-list CLI participant Cron as Cron scheduler participant DB as SQLite participant PM as Postmark participant TS as Telemetry server Human->>Repo: Write or revise campaign Markdown Human->>Agent: Send campaign and follow up in 4 to 5 days Agent->>CLI: Validate and preview exact campaign CLI->>Repo: Read exact content and template CLI-->>Agent: Rendered preview, checks, recipient estimate Agent->>CLI: Record human directive and execute authorized send CLI->>DB: Store authorization hashes and follow-up parameters CLI->>DB: Create immutable recipient snapshot CLI->>PM: Reconcile current suppressions PM-->>CLI: Current suppression result CLI->>DB: Exclude ineligible recipients loop Idempotent batches CLI->>PM: Submit unsent recipients PM-->>CLI: Request and message identifiers CLI->>DB: Record per-recipient acceptance or failure end Agent->>Cron: Schedule durable apparent-non-opener follow-up Agent->>CLI: Verify initial completion and write receipt PM-->>TS: Delivery and engagement webhooks Cron->>CLI: Run due follow-ups CLI->>TS: Query apparent non-openers TS-->>CLI: Versioned campaign telemetry response CLI->>PM: Recheck suppressions and send authorized follow-up PM-->>CLI: Follow-up request and message identifiers CLI->>DB: Record follow-up completion Agent->>CLI: Inspect status and exceptions CLI->>Repo: Write sanitized initial and follow-up receipts ``` ## Subscriber and Welcome Flow ```mermaid flowchart LR request["Human appends subscribe record
to private JSON / JSONL inbox"] cron["Cron reads inbox on schedule"] validate["CLI validates schema, operation ID,
source, consent, and duplication"] apply["Transactional SQLite update
with status history"] welcome["Exactly-once welcome send"] postmark["Postmark"] receipt["Sanitized receipt"] agent["AI inspects exceptions
when needed"] request --> cron --> validate --> apply --> welcome --> postmark apply --> receipt welcome --> receipt receipt --> agent ``` ## Unsubscribe and Suppression Flow ```mermaid flowchart LR recipient["Recipient"] human["Human observes an external
unsubscribe request"] inbox["Private JSON / JSONL
operations inbox"] cron["Cron import"] postmark["Postmark one-click unsubscribe
and Broadcast suppression"] telemetry["Existing telemetry server
subscription-change webhook"] reconcile["Email-list suppression
reconciliation command"] sqlite[("Local SQLite status mirror")] sendguard["Pre-batch suppression guard"] recipient -->|"unsubscribe or complaint"| postmark human -->|"append unsubscribe operation"| inbox --> cron cron -->|"idempotent local suppression"| sqlite postmark -->|"webhook"| telemetry telemetry -->|"versioned query response"| reconcile postmark -->|"authoritative suppression query"| reconcile reconcile -->|"reviewed, idempotent update"| sqlite sqlite --> sendguard postmark --> sendguard sendguard -->|"only eligible recipients proceed"| send["Campaign send"] ``` ## AI Access Rights ```mermaid flowchart TB identity["Dedicated AI agent identity"] terminal["Restricted persistent terminal
or task-runner access"] repo["Read campaign and operational repo
write only through normal Git authority"] commands["Allowed email-list CLI commands"] status["Read health, receipts,
campaign and telemetry status"] secrets["Runtime injects scoped secrets
secrets are not shown or committed"] blocked["Blocked boundaries
no direct SQLite mutation
no telemetry DB access
no suppression bypass
no unauthorized send"] identity --> terminal terminal --> repo terminal --> commands terminal --> status secrets --> commands terminal -. "enforced least privilege" .-> blocked ``` The model and persistent-agent implementation may change. These access boundaries remain stable and determine what any selected agent is allowed to do. ## Trust and Data Boundaries | Boundary | May cross | Must not cross | | --- | --- | --- | | Public Git repository | Code, schemas, templates, campaign content, synthetic examples, sanitized receipts | Subscriber addresses, credentials, production databases, raw telemetry, private logs | | AI/human to CLI | Validated structured input and documented commands | Direct production database manipulation or authorization bypass | | AI agent identity to VM | Allowlisted CLI commands, required repository files, scoped runtime status, and approved network endpoints | General administrator access, unrelated applications, raw secrets, or unrestricted shell authority | | Email app to Postmark | Required recipient and campaign delivery data | Database credentials or unrelated telemetry | | Email app to telemetry server | Authenticated versioned queries and minimum necessary results | Direct access to the telemetry database | | Docker container to host | Declared configuration, network endpoints, persistent-volume paths | Undeclared host filesystem or shared application dependencies | ## Failure Boundaries - A telemetry outage prevents telemetry-dependent resends but does not corrupt subscriber or send state. - A Postmark outage leaves recipients pending or safely retryable; it does not cause a whole-campaign resend. - A renderer replacement cannot approve or send email. - A scheduler failure can be recovered by running the same idempotent CLI command manually. - A container replacement preserves state through the private persistent volume. - A database migration is not allowed without a backup, versioned migration, and validation. - An unresolved suppression mismatch fails closed for the affected recipient. ## Deployment and Release Flow ```mermaid flowchart LR dev["Isolated development
implementation + tests"] review["Human review
docs, diff, tests, receipts"] git["Git remote
approved revision"] deploy["Email-list VM
pull/build pinned revision"] migrate["Backup + versioned migration"] validate["Health check + test-mode send"] release["Validated release + version tag"] dev --> review --> git --> deploy --> migrate --> validate --> release validate -->|"failure: roll back image and restore if needed"| deploy ```