# marclou/mailcheap architecture

> Architecture diagram of the GitHub repository marclou/mailcheap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marclou/mailcheap
- Repository: https://github.com/marclou/mailcheap

## Overview

Mailcheap is a self-hosted newsletter application. An administrator creates an issue, chooses an audience and send options, then the application sends it through Amazon SES, processes delivery events and engagement, and publishes issues to a public archive. Separate branches cover subscriber acquisition and list health, campaign and audience management, analytics, and archive publishing. The README documents major product capabilities; source excerpts and the SOURCE INDEX provide additional implementation evidence. Some route implementations were not sampled, so those connections are documented rather than inferred from names alone.

Main entry points: [`models/Campaign.js`](https://github.com/marclou/mailcheap/blob/main/models/Campaign.js) (Campaign records), [`models/Contact.js`](https://github.com/marclou/mailcheap/blob/main/models/Contact.js) (Contact records), [`app/(app)/campaigns/actions.js`](https://github.com/marclou/mailcheap/blob/main/app/(app)/campaigns/actions.js) (Campaign editor), [`lib/archive-data.js`](https://github.com/marclou/mailcheap/blob/main/lib/archive-data.js) (Archive data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["Campaign management"]
  node_campaign_ui["Campaign editor<br/>[actions.js]"]
  node_newsletter_settings["Newsletter settings<br/>[actions.js]"]
  node_campaign_record[("Campaign records<br/>[Campaign.js]")]
end

subgraph group_audience["Audience and signup"]
  node_contact_ui["Contact management<br/>[page.js]"]
  node_signup_api["Signup API<br/>[route.js]"]
  node_contact_records[("Contact records<br/>[Contact.js]")]
  node_signup_confirmation["Opt-in confirmation<br/>[actions.js]"]
  node_unsubscribe["Unsubscribe handling<br/>[route.js]"]
end

subgraph group_delivery["Sending and delivery"]
  node_send_rules["Send checks<br/>[sending-rules.js]"]
  node_send_engine["Batch sending<br/>[sending.js]"]
  node_scheduler["Scheduled sends<br/>[scheduling.js]"]
  node_job_routes["Background job routes<br/>[route.js]"]
  node_ses{{"Amazon SES"}}
  node_ses_webhook["SES event webhook<br/>[route.js]"]
end

subgraph group_insights["Tracking and reports"]
  node_event_processor["Event processing<br/>[ses-events.js]"]
  node_tracking["Open and click tracking<br/>[tracking.js]"]
  node_overview["Overview analytics<br/>[page.js]"]
  node_report["Campaign reports<br/>[CampaignReport.jsx]"]
end

subgraph group_publishing["Public archive"]
  node_archive_data["Archive data<br/>[archive-data.js]"]
  node_archive_pages["Public archive<br/>[page.js]"]
  node_archive_issue["Issue page<br/>[page.js]"]
end

node_admin(("Administrator"))
node_database[("MongoDB")]
node_qstash["QStash"]

node_admin -->|"edits and sends"| node_campaign_ui
node_campaign_ui -->|"creates and updates"| node_campaign_record
node_campaign_ui -->|"checks before send"| node_send_rules
node_campaign_ui -->|"starts sending"| node_send_engine
node_newsletter_settings -.->|"configures audience"| node_contact_ui
node_contact_ui -.->|"manages contacts"| node_contact_records
node_signup_api -.->|"adds subscribers"| node_contact_records
node_signup_api -.->|"supports opt-in"| node_signup_confirmation
node_unsubscribe -->|"updates status"| node_contact_records
node_unsubscribe -->|"credits unsubscribe"| node_campaign_record
node_job_routes -->|"runs batches"| node_send_engine
node_job_routes -->|"runs schedules"| node_scheduler
node_scheduler -.->|"queues work"| node_qstash
node_send_engine -->|"sends email"| node_ses
node_ses -->|"posts events"| node_ses_webhook
node_ses_webhook -->|"dispatches events"| node_event_processor
node_event_processor -->|"updates engagement"| node_contact_records
node_event_processor -->|"updates statistics"| node_campaign_record
node_tracking -->|"records views"| node_campaign_record
node_overview -.->|"shows send metrics"| node_campaign_record
node_report -.->|"reports campaign results"| node_campaign_record
node_archive_pages -.->|"loads archive"| node_archive_data
node_archive_issue -.->|"loads issue"| node_archive_data
node_archive_data -->|"reads published issues"| node_campaign_record
node_archive_data -->|"counts readers"| node_contact_records
node_campaign_record -.->|"persists in"| node_database
node_contact_records -.->|"persists in"| node_database

click node_campaign_ui "https://github.com/marclou/mailcheap/blob/main/app/(app)/campaigns/actions.js"
click node_newsletter_settings "https://github.com/marclou/mailcheap/blob/main/app/(app)/newsletters/actions.js"
click node_campaign_record "https://github.com/marclou/mailcheap/blob/main/models/Campaign.js"
click node_contact_ui "https://github.com/marclou/mailcheap/blob/main/app/(app)/contacts/page.js"
click node_signup_api "https://github.com/marclou/mailcheap/blob/main/app/api/v1/contacts/route.js"
click node_contact_records "https://github.com/marclou/mailcheap/blob/main/models/Contact.js"
click node_signup_confirmation "https://github.com/marclou/mailcheap/blob/main/app/confirm/actions.js"
click node_unsubscribe "https://github.com/marclou/mailcheap/blob/main/app/api/unsubscribe/route.js"
click node_send_rules "https://github.com/marclou/mailcheap/blob/main/lib/sending-rules.js"
click node_send_engine "https://github.com/marclou/mailcheap/blob/main/lib/sending.js"
click node_scheduler "https://github.com/marclou/mailcheap/blob/main/lib/scheduling.js"
click node_job_routes "https://github.com/marclou/mailcheap/blob/main/app/api/jobs/send-batch/route.js"
click node_ses_webhook "https://github.com/marclou/mailcheap/blob/main/app/api/webhooks/ses/route.js"
click node_event_processor "https://github.com/marclou/mailcheap/blob/main/lib/ses-events.js"
click node_tracking "https://github.com/marclou/mailcheap/blob/main/lib/tracking.js"
click node_overview "https://github.com/marclou/mailcheap/blob/main/app/(app)/(overview)/page.js"
click node_report "https://github.com/marclou/mailcheap/blob/main/components/CampaignReport.jsx"
click node_archive_data "https://github.com/marclou/mailcheap/blob/main/lib/archive-data.js"
click node_archive_pages "https://github.com/marclou/mailcheap/blob/main/app/archive/%5Bslug%5D/page.js"
click node_archive_issue "https://github.com/marclou/mailcheap/blob/main/app/archive/%5Bslug%5D/p/%5Bpost%5D/page.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_campaign_ui,node_newsletter_settings,node_campaign_record toneBlue
class node_contact_ui,node_signup_api,node_contact_records,node_signup_confirmation,node_unsubscribe,node_database toneAmber
class node_send_rules,node_send_engine,node_scheduler,node_job_routes,node_ses,node_ses_webhook toneMint
class node_event_processor,node_tracking,node_overview,node_report toneRose
class node_archive_data,node_archive_pages,node_archive_issue,node_admin,node_qstash toneIndigo
```

## Components

### Campaign management

- [Campaign editor](https://github.com/marclou/mailcheap/blob/main/app/(app)/campaigns/actions.js): `app/(app)/campaigns/actions.js`
- [Newsletter settings](https://github.com/marclou/mailcheap/blob/main/app/(app)/newsletters/actions.js): `app/(app)/newsletters/actions.js`
- [Campaign records](https://github.com/marclou/mailcheap/blob/main/models/Campaign.js): `models/Campaign.js`

### Audience and signup

- [Contact management](https://github.com/marclou/mailcheap/blob/main/app/(app)/contacts/page.js): `app/(app)/contacts/page.js`
- [Signup API](https://github.com/marclou/mailcheap/blob/main/app/api/v1/contacts/route.js): `app/api/v1/contacts/route.js`
- [Contact records](https://github.com/marclou/mailcheap/blob/main/models/Contact.js): `models/Contact.js`
- [Opt-in confirmation](https://github.com/marclou/mailcheap/blob/main/app/confirm/actions.js): `app/confirm/actions.js`
- [Unsubscribe handling](https://github.com/marclou/mailcheap/blob/main/app/api/unsubscribe/route.js): `app/api/unsubscribe/route.js`

### Sending and delivery

- [Send checks](https://github.com/marclou/mailcheap/blob/main/lib/sending-rules.js): `lib/sending-rules.js`
- [Batch sending](https://github.com/marclou/mailcheap/blob/main/lib/sending.js): `lib/sending.js`
- [Scheduled sends](https://github.com/marclou/mailcheap/blob/main/lib/scheduling.js): `lib/scheduling.js`
- [Background job routes](https://github.com/marclou/mailcheap/blob/main/app/api/jobs/send-batch/route.js): `app/api/jobs/send-batch/route.js`
- **Amazon SES**
- [SES event webhook](https://github.com/marclou/mailcheap/blob/main/app/api/webhooks/ses/route.js): `app/api/webhooks/ses/route.js`

### Tracking and reports

- [Event processing](https://github.com/marclou/mailcheap/blob/main/lib/ses-events.js): `lib/ses-events.js`
- [Open and click tracking](https://github.com/marclou/mailcheap/blob/main/lib/tracking.js): `lib/tracking.js`
- [Overview analytics](https://github.com/marclou/mailcheap/blob/main/app/(app)/(overview)/page.js): `app/(app)/(overview)/page.js`
- [Campaign reports](https://github.com/marclou/mailcheap/blob/main/components/CampaignReport.jsx): `components/CampaignReport.jsx`

### Public archive

- [Archive data](https://github.com/marclou/mailcheap/blob/main/lib/archive-data.js): `lib/archive-data.js`
- [Public archive](https://github.com/marclou/mailcheap/blob/main/app/archive/%5Bslug%5D/page.js): `app/archive/[slug]/page.js`
- [Issue page](https://github.com/marclou/mailcheap/blob/main/app/archive/%5Bslug%5D/p/%5Bpost%5D/page.js): `app/archive/[slug]/p/[post]/page.js`

### Other components

- **Administrator**
- **MongoDB**
- **QStash**

## Connections

- Administrator → Campaign editor: edits and sends
- Campaign editor → Campaign records: creates and updates (evidence: `app/(app)/campaigns/actions.js`)
- Campaign editor → Send checks: checks before send (evidence: `app/(app)/campaigns/actions.js`)
- Campaign editor → Batch sending: starts sending (evidence: `app/(app)/campaigns/actions.js`)
- Newsletter settings → Contact management: configures audience
- Contact management → Contact records: manages contacts
- Signup API → Contact records: adds subscribers
- Signup API → Opt-in confirmation: supports opt-in
- Unsubscribe handling → Contact records: updates status (evidence: `app/api/unsubscribe/route.js`)
- Unsubscribe handling → Campaign records: credits unsubscribe (evidence: `app/api/unsubscribe/route.js`)
- Background job routes → Batch sending: runs batches (evidence: `app/api/jobs/send-batch/route.js`)
- Background job routes → Scheduled sends: runs schedules
- Scheduled sends → QStash: queues work
- Batch sending → Amazon SES: sends email (evidence: `lib/sending.js`)
- Amazon SES → SES event webhook: posts events
- SES event webhook → Event processing: dispatches events (evidence: `app/api/webhooks/ses/route.js`)
- Event processing → Contact records: updates engagement (evidence: `lib/ses-events.js`)
- Event processing → Campaign records: updates statistics (evidence: `lib/ses-events.js`)
- Open and click tracking → Campaign records: records views
- Overview analytics → Campaign records: shows send metrics
- Campaign reports → Campaign records: reports campaign results
- Public archive → Archive data: loads archive
- Issue page → Archive data: loads issue
- Archive data → Campaign records: reads published issues (evidence: `lib/archive-data.js`)
- Archive data → Contact records: counts readers (evidence: `lib/archive-data.js`)
- Campaign records → MongoDB: persists in
- Contact records → MongoDB: persists in
