# sanjayrk2007/morningdrop architecture

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

- Interactive diagram: https://gitdiagram.com/sanjayrk2007/morningdrop
- Repository: https://github.com/sanjayrk2007/morningdrop

## Overview

#### Purpose and Entry Points
The Morning Drop is a Python-based daily newsletter curation pipeline for Indian Gen-Z/young professionals. It ingests news, uses LLMs to select and rewrite stories, adds live sports context, formats HTML, and sends via email.

Primary CLI entry point: `main.py`, supporting draft/review (`--draft`, `--approve`) and unattended execution (`--auto`). Windows scheduling is provided by `setup_scheduler.ps1` and `run_morning_drop.bat`; CI/scheduled automation may also run through `.github/workflows/morning_drop.yml`.

#### Workflow Orchestration
`graph.py` defines the LangGraph state-machine pipeline and its transitions. The graph separates acquisition/selection from downstream enrichment and delivery, allowing a human approval boundary after curation.

Core flow: fetch RSS stories → exclude prior deliveries → LLM-select stories → cross-category deduplicate → either persist a draft or continue automatically → inject sports data → narrate by category persona → produce HTML → email delivery.

Paths: `graph.py`, `main.py`, `config.py`.

#### Content Acquisition and Curation
RSS source/category definitions and behavioral settings are externalized in `config.yaml`, loaded through `config.py`. The curation stage operates on recent feed items and uses configured LLM providers/models to choose a compact set of newsletter-worthy stories.

Semantic/fuzzy cross-deduplication is an explicit architecture stage, preventing repeated stories across domains. Its output is the normalized candidate set that becomes either the review draft or final newsletter input.

Paths: `graph.py`, `config.yaml`, `config.py`.

#### LLM Provider Boundary
The system uses a dual LLM strategy: OpenRouter-hosted models are preferred when `OPENROUTER_API_KEY` is available; a local Ollama runtime is the resilience/offline fallback. LLMs serve two distinct roles: editorial selection and category-specific conversational narration.

This isolates variable provider availability from the rest of the graph: rate limits, missing cloud credentials, or cloud failures should route work to local models rather than block newsletter generation.

Paths: `graph.py`, `config.py`, `requirements.txt`.

#### Human Review and Persistent Memory
Manual execution has a two-phase control boundary: `--draft` saves curated output for editorial review; `--approve` resumes narration and delivery from that curated selection. Auto mode bypasses this approval gate.

SQLite stores sent-story/history state so previously delivered URLs can be filtered before selection, preserving continuity across scheduled runs. The checked-in database represents the local persistence artifact.

Paths: `main.py`, `db.py`, `news.db`.

#### Sports Enrichment, Presentation, and Delivery
Sports content is enriched late in the pipeline so live cricket and football information remains current at send time. `sports_api.py` encapsulates external scoreboard/API access; its result is fed into the sports narration rather than treated as a normal RSS source.

The final stage turns narrated sections into an HTML email and sends it through Gmail SMTP using environment-provided credentials. Delivery is therefore an external side-effect boundary after all curation and rendering work succeeds.

Paths: `sports_api.py`, `email_sender.py`, `graph.py`.

#### Runtime and Operations
The runtime is Python with LangGraph/LangChain-style LLM integration, SQLite local state, OpenRouter and Ollama inference backends, RSS sources, sports APIs, and Gmail SMTP. Daily unattended operation targets Windows Task Scheduler via `setup_scheduler.ps1`; repository automation is also represented in `.github/workflows/morning_drop.yml`.

Paths: `requirements.txt`, `setup_scheduler.ps1`, `.github/workflows/morning_drop.yml`.

Main entry points: [`graph.py`](https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py) (LangGraph workflow), [`config.py`](https://github.com/sanjayrk2007/morningdrop/blob/main/config.py) (LLM provider routing), [`sports_api.py`](https://github.com/sanjayrk2007/morningdrop/blob/main/sports_api.py) (Live sports data), [`email_sender.py`](https://github.com/sanjayrk2007/morningdrop/blob/main/email_sender.py) (Gmail SMTP sender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Pipeline Control"]
  node_cli["CLI modes<br/>Python entry point<br/>[main.py]"]
  node_workflow{{"LangGraph workflow<br/>state machine<br/>[graph.py]"}}
  node_settings["Settings loader<br/>configuration<br/>[config.py]"]
  node_review["Draft approval gate<br/>human review<br/>[main.py]"]
end

subgraph group_content["Curation &amp; Enrichment"]
  node_rss_config["RSS sources &amp; rules<br/>YAML configuration<br/>[config.yaml]"]
  node_history[("Delivery history<br/>SQLite persistence<br/>[news.db]")]
  node_curation["Select &amp; deduplicate<br/>curation stage<br/>[graph.py]"]
  node_sports_api["Live sports data<br/>sports API client<br/>[sports_api.py]"]
  node_narration["Category narration<br/>LLM editorial stage<br/>[graph.py]"]
  node_html["HTML newsletter<br/>rendering stage<br/>[graph.py]"]
end

subgraph group_integrations["External Services"]
  node_rss["RSS feeds<br/>news sources"]
  node_llm_boundary{{"LLM provider routing<br/>inference boundary<br/>[config.py]"}}
  node_openrouter["OpenRouter models<br/>cloud LLM"]
  node_ollama["Ollama runtime<br/>local LLM"]
  node_sports_service["Scoreboard APIs<br/>external sports services"]
  node_sender["Gmail SMTP sender<br/>email delivery<br/>[email_sender.py]"]
  node_gmail["Gmail SMTP<br/>email service"]
end

subgraph group_operations["Automation"]
  node_windows_schedule["Windows daily schedule<br/>Task Scheduler setup"]
  node_github_schedule["GitHub scheduled run<br/>CI workflow<br/>[morning_drop.yml]"]
end

node_windows_schedule -->|"launches"| node_cli
node_github_schedule -->|"runs"| node_cli
node_cli -->|"selects mode"| node_workflow
node_settings -->|"configures"| node_workflow
node_rss_config -->|"loaded by"| node_settings
node_workflow -->|"fetches stories"| node_rss
node_workflow -->|"excludes prior deliveries"| node_history
node_workflow -->|"passes recent stories"| node_curation
node_curation -->|"uses for selection"| node_llm_boundary
node_llm_boundary -->|"preferred"| node_openrouter
node_llm_boundary -.->|"fallback"| node_ollama
node_curation -->|"persists draft"| node_review
node_review -->|"approved selection resumes"| node_workflow
node_workflow -->|"enriches late"| node_sports_api
node_sports_api -->|"retrieves live scores"| node_sports_service
node_sports_api -->|"sports context"| node_narration
node_workflow -->|"curated stories"| node_narration
node_narration -->|"uses for rewriting"| node_llm_boundary
node_narration -->|"sections"| node_html
node_html -->|"rendered email"| node_sender
node_sender -->|"sends via SMTP"| node_gmail
node_sender -->|"records sent stories"| node_history

click node_cli "https://github.com/sanjayrk2007/morningdrop/blob/main/main.py"
click node_workflow "https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py"
click node_settings "https://github.com/sanjayrk2007/morningdrop/blob/main/config.py"
click node_rss_config "https://github.com/sanjayrk2007/morningdrop/blob/main/config.yaml"
click node_history "https://github.com/sanjayrk2007/morningdrop/blob/main/news.db"
click node_curation "https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py"
click node_review "https://github.com/sanjayrk2007/morningdrop/blob/main/main.py"
click node_llm_boundary "https://github.com/sanjayrk2007/morningdrop/blob/main/config.py"
click node_sports_api "https://github.com/sanjayrk2007/morningdrop/blob/main/sports_api.py"
click node_narration "https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py"
click node_html "https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py"
click node_sender "https://github.com/sanjayrk2007/morningdrop/blob/main/email_sender.py"
click node_windows_schedule "https://github.com/sanjayrk2007/morningdrop/blob/main/setup_scheduler.ps1"
click node_github_schedule "https://github.com/sanjayrk2007/morningdrop/blob/main/.github/workflows/morning_drop.yml"

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_cli,node_workflow,node_settings,node_review toneBlue
class node_rss_config,node_history,node_curation,node_sports_api,node_narration,node_html toneAmber
class node_rss,node_llm_boundary,node_openrouter,node_ollama,node_sports_service,node_sender,node_gmail toneMint
class node_windows_schedule,node_github_schedule toneRose
```

## Components

### Pipeline Control

- [CLI modes](https://github.com/sanjayrk2007/morningdrop/blob/main/main.py): Python entry point · Runs draft, approval, or unattended modes. · `main.py`
- [LangGraph workflow](https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py): state machine · Coordinates curation, review, enrichment, rendering, and delivery. · `graph.py`
- [Settings loader](https://github.com/sanjayrk2007/morningdrop/blob/main/config.py): configuration · `config.py`
- [Draft approval gate](https://github.com/sanjayrk2007/morningdrop/blob/main/main.py): human review · Draft mode pauses after curated selection; approval resumes delivery. · `main.py`

### Curation & Enrichment

- [RSS sources & rules](https://github.com/sanjayrk2007/morningdrop/blob/main/config.yaml): YAML configuration · `config.yaml`
- [Delivery history](https://github.com/sanjayrk2007/morningdrop/blob/main/news.db): SQLite persistence · Filters URLs already sent and records continuity state. · `news.db`
- [Select & deduplicate](https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py): curation stage · Chooses newsletter stories and removes cross-category repeats. · `graph.py`
- [Live sports data](https://github.com/sanjayrk2007/morningdrop/blob/main/sports_api.py): sports API client · Fetches current cricket and football context late in the run. · `sports_api.py`
- [Category narration](https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py): LLM editorial stage · Produces persona-specific conversational sections. · `graph.py`
- [HTML newsletter](https://github.com/sanjayrk2007/morningdrop/blob/main/graph.py): rendering stage · `graph.py`

### External Services

- **RSS feeds**: news sources
- [LLM provider routing](https://github.com/sanjayrk2007/morningdrop/blob/main/config.py): inference boundary · Prefers OpenRouter and falls back to local Ollama. · `config.py`
- **OpenRouter models**: cloud LLM
- **Ollama runtime**: local LLM · Resilience and offline inference fallback.
- **Scoreboard APIs**: external sports services
- [Gmail SMTP sender](https://github.com/sanjayrk2007/morningdrop/blob/main/email_sender.py): email delivery · `email_sender.py`
- **Gmail SMTP**: email service

### Automation

- [Windows daily schedule](https://github.com/sanjayrk2007/morningdrop/blob/main/setup_scheduler.ps1): Task Scheduler setup · `setup_scheduler.ps1`
- [GitHub scheduled run](https://github.com/sanjayrk2007/morningdrop/blob/main/.github/workflows/morning_drop.yml): CI workflow · `.github/workflows/morning_drop.yml`

## Connections

- Windows daily schedule → CLI modes: launches
- GitHub scheduled run → CLI modes: runs
- CLI modes → LangGraph workflow: selects mode
- Settings loader → LangGraph workflow: configures
- RSS sources & rules → Settings loader: loaded by
- LangGraph workflow → RSS feeds: fetches stories
- LangGraph workflow → Delivery history: excludes prior deliveries
- LangGraph workflow → Select & deduplicate: passes recent stories
- Select & deduplicate → LLM provider routing: uses for selection
- LLM provider routing → OpenRouter models: preferred
- LLM provider routing → Ollama runtime: fallback
- Select & deduplicate → Draft approval gate: persists draft
- Draft approval gate → LangGraph workflow: approved selection resumes
- LangGraph workflow → Live sports data: enriches late
- Live sports data → Scoreboard APIs: retrieves live scores
- Live sports data → Category narration: sports context
- LangGraph workflow → Category narration: curated stories
- Category narration → LLM provider routing: uses for rewriting
- Category narration → HTML newsletter: sections
- HTML newsletter → Gmail SMTP sender: rendered email
- Gmail SMTP sender → Gmail SMTP: sends via SMTP
- Gmail SMTP sender → Delivery history: records sent stories
