# mreflow/control-center architecture

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

- Interactive diagram: https://gitdiagram.com/mreflow/control-center
- Repository: https://github.com/mreflow/control-center

## Overview

#### Purpose and runtime

Control Center is a local-first Next.js dashboard for collecting and curating industry news, verified brand mentions, newsletter intelligence, public audience metrics, and personal action items. It runs as a loopback-only Node.js service, with durable local settings/files and SQLite storage. Main UI entry points are `app/page.tsx` and `app/layout.tsx`; API entry points are Next route handlers under `app/api/`.

#### UI and API boundary

The single-page dashboard composes its live areas and settings controls from client components, principally `components/control-center.tsx`, `components/audience-insights.tsx`, and `components/ai-provider-settings.tsx`. Browser interactions call narrowly scoped local APIs for workspace state, settings, brief data, library/archive actions, and collectors:
- `app/api/workspace/route.ts`
- `app/api/settings/route.ts`
- `app/api/brief/route.ts`

Server-side routes form the trust boundary: secrets never return to the client, and loopback/host protections are enforced before local data or external services are accessed.

#### Local persistence and workspace state

SQLite is the primary durable record for discovered content, queues, archives, newsletter metadata, tasks, reminders, and historical audience readings. Server persistence and data-directory initialization center on `lib/server/database.ts`; settings/secrets are handled in `lib/server/settings.ts`. Domain stores isolate each saved queue:
- `lib/industry-store.ts`
- `lib/newsletter-store.ts`
- `lib/archive-store.ts`

A workspace/brief layer combines saved collector state rather than recollecting when users navigate or open Today, via `lib/workspace-store.ts`, `lib/brief-store.ts`, and `lib/daily-brief-snapshot.ts`.

#### Industry collection pipeline

Industry collection discovers feeds from configured sites, then falls back to robots/sitemap traversal and optional Google News topic search. Discovery and ranking stages are separated so broad raw results do not directly become cards. Key stages are feed/sitemap discovery, cached collection, canonical deduplication, freshness/topic/source prioritization, optional AI reranking, then persistence of the bounded active queue:
- `lib/feed-discovery.ts`
- `lib/sitemap.ts`
- `lib/industry-curation.ts`

External public-web access is hardened through server fetch/RSS modules such as `lib/server/safe-fetch.ts` and `lib/server/rss.ts`.

#### Mention research and verification

Mentions begin with public news search and optional cloud-AI broad-web discovery, but are only surfaced after direct canonical-page verification against configured identities, domains, anchors, and exclusions. The flow deliberately separates untrusted search/AI candidates from literal page-local evidence, then applies summaries/priority ranking and stable archival identity:
- `lib/server/mention-research.ts`
- `lib/server/mention-curation.ts`
- `lib/mention-filter.ts`

Google News and Bing/public pages are external discovery sources; AI is advisory and cannot qualify an otherwise unverified mention.

#### Newsletter and Gmail intelligence

Gmail OAuth is a separate optional integration. OAuth start/callback routes establish read-only access, then bounded background collection reads matching unseen issues. Bodies are masked for privacy and passed to the selected AI model for extraction, ranking, cross-newsletter event consolidation, and persistent topic aliases:
- `app/api/auth/google/start/route.ts`
- `app/api/auth/google/callback/route.ts`
- `lib/server/newsletter-collector.ts`

The Gmail API client resides in `lib/server/gmail.ts`; `lib/server/newsletter-ai.ts` handles AI extraction. Without a usable AI runtime, newsletter processing pauses rather than degrading into an inbox mirror.

#### AI runtime and provider boundary

AI is optional for industry reranking, mention research/summaries, and required for newsletters. Provider selection, saved credentials, model discovery, and bounded requests are separated across:
- `lib/ai-settings.ts`
- `lib/ai-model-discovery.ts`
- `lib/server/ai.ts`

Supported external providers include OpenAI, Anthropic, Gemini, and Grok; local LM Studio/Ollama endpoints are restricted to numeric loopback addresses. The models endpoint, `app/api/ai/models/route.ts`, exposes discovered selectable models without exposing keys. Deterministic local ranking provides failure fallback where AI is optional.

#### Scheduling, audience, and connector ingestion

Startup/manual refresh and 15-minute recurring collection are coordinated by `lib/server/scheduler.ts` and `lib/tasks.ts`. Audience collection validates configured public profiles before storing verified readings and deriving comparable growth/chart data:
- `lib/server/audience.ts`
- `lib/audience-growth.ts`
- `app/api/live/audience/route.ts`

Optional private connector automations submit normalized action/meeting/message summaries to the local brief boundary rather than receiving direct account access; its contract is documented in `docs/CONNECTOR_BRIDGE.md` and ingested through `app/api/brief/route.ts`.

Main entry points: [`lib/server/database.ts`](https://github.com/mreflow/control-center/blob/main/lib/server/database.ts) (SQLite content store), [`lib/server/ai.ts`](https://github.com/mreflow/control-center/blob/main/lib/server/ai.ts) (AI provider runtime), [`components/control-center.tsx`](https://github.com/mreflow/control-center/blob/main/components/control-center.tsx) (Control Center UI), [`lib/server/scheduler.ts`](https://github.com/mreflow/control-center/blob/main/lib/server/scheduler.ts) (Collection scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Dashboard &amp; local API"]
  node_dashboard["Control Center UI<br/>Next.js client UI<br/>[control-center.tsx]"]
  node_workspace_api["Workspace API<br/>route handler<br/>[route.ts]"]
  node_settings_api["Settings API<br/>route handler<br/>[route.ts]"]
  node_brief_api["Brief API<br/>route handler<br/>[route.ts]"]
  node_models_api["Model discovery API<br/>route handler<br/>[route.ts]"]
  node_google_oauth_start["Google OAuth start<br/>route handler<br/>[route.ts]"]
  node_google_oauth_callback["Google OAuth callback<br/>route handler<br/>[route.ts]"]
end

subgraph group_core["Local state &amp; scheduling"]
  node_database[("SQLite content store<br/>local persistence<br/>[database.ts]")]
  node_settings["Settings &amp; secrets<br/>local persistence<br/>[settings.ts]"]
  node_workspace["Workspace &amp; daily brief<br/>state composition<br/>[workspace-store.ts]"]
  node_scheduler["Collection scheduler<br/>background coordinator<br/>[scheduler.ts]"]
end

subgraph group_collection["Curation pipelines"]
  node_feed_discovery["Feed &amp; sitemap discovery<br/>industry discovery<br/>[feed-discovery.ts]"]
  node_industry_curation["Industry curation<br/>ranking pipeline"]
  node_mention_research["Mention research<br/>candidate discovery"]
  node_mention_curation["Mention verification<br/>evidence curation"]
  node_newsletter_collector["Newsletter collector<br/>background pipeline"]
  node_newsletter_ai["Newsletter AI extraction<br/>AI processing<br/>[newsletter-ai.ts]"]
end

subgraph group_integrations["Optional integrations"]
  node_ai_runtime["AI provider runtime<br/>server AI boundary<br/>[ai.ts]"]
  node_audience_collector["Audience validation<br/>public metrics collector<br/>[audience.ts]"]
  node_audience_growth["Audience growth analysis<br/>metrics derivation<br/>[audience-growth.ts]"]
  node_connector_bridge["Connector bridge<br/>ingestion contract"]
  node_public_web(("Public web sources<br/>external sources"))
  node_external_ai(("AI providers<br/>external providers"))
end

node_dashboard -->|"loads state"| node_workspace_api
node_dashboard -->|"updates settings"| node_settings_api
node_dashboard -->|"reads brief"| node_brief_api
node_dashboard -->|"lists models"| node_models_api
node_workspace_api -->|"serves"| node_workspace
node_settings_api -->|"reads/writes"| node_settings
node_brief_api -->|"composes"| node_workspace
node_models_api -->|"discovers"| node_ai_runtime
node_google_oauth_start -->|"OAuth redirect"| node_google_oauth_callback
node_google_oauth_callback -->|"stores authorization"| node_settings
node_workspace -->|"saved queues and snapshots"| node_database
node_scheduler -->|"triggers"| node_feed_discovery
node_scheduler -->|"triggers"| node_mention_research
node_scheduler -->|"triggers"| node_newsletter_collector
node_scheduler -->|"triggers"| node_audience_collector
node_feed_discovery -->|"discovers"| node_public_web
node_feed_discovery -->|"raw candidates"| node_industry_curation
node_industry_curation -.->|"optional reranking"| node_ai_runtime
node_industry_curation -->|"active queue"| node_database
node_mention_research -->|"searches"| node_public_web
node_mention_research -->|"candidates"| node_mention_curation
node_mention_curation -->|"verifies pages"| node_public_web
node_mention_curation -->|"verified mentions"| node_database
node_newsletter_collector -->|"masked issues"| node_newsletter_ai
node_newsletter_ai -->|"requires extraction"| node_ai_runtime
node_newsletter_ai -->|"events and aliases"| node_database
node_ai_runtime -->|"provider selection"| node_settings
node_ai_runtime -->|"bounded requests"| node_external_ai
node_audience_collector -->|"validates profiles"| node_public_web
node_audience_collector -->|"verified readings"| node_database
node_audience_growth -->|"reads history"| node_database
node_brief_api -->|"accepts summaries"| node_connector_bridge

click node_dashboard "https://github.com/mreflow/control-center/blob/main/components/control-center.tsx"
click node_workspace_api "https://github.com/mreflow/control-center/blob/main/app/api/workspace/route.ts"
click node_settings_api "https://github.com/mreflow/control-center/blob/main/app/api/settings/route.ts"
click node_brief_api "https://github.com/mreflow/control-center/blob/main/app/api/brief/route.ts"
click node_models_api "https://github.com/mreflow/control-center/blob/main/app/api/ai/models/route.ts"
click node_google_oauth_start "https://github.com/mreflow/control-center/blob/main/app/api/auth/google/start/route.ts"
click node_google_oauth_callback "https://github.com/mreflow/control-center/blob/main/app/api/auth/google/callback/route.ts"
click node_database "https://github.com/mreflow/control-center/blob/main/lib/server/database.ts"
click node_settings "https://github.com/mreflow/control-center/blob/main/lib/server/settings.ts"
click node_workspace "https://github.com/mreflow/control-center/blob/main/lib/workspace-store.ts"
click node_scheduler "https://github.com/mreflow/control-center/blob/main/lib/server/scheduler.ts"
click node_feed_discovery "https://github.com/mreflow/control-center/blob/main/lib/feed-discovery.ts"
click node_industry_curation "https://github.com/mreflow/control-center/blob/main/lib/industry-curation.ts"
click node_mention_research "https://github.com/mreflow/control-center/blob/main/lib/server/mention-research.ts"
click node_mention_curation "https://github.com/mreflow/control-center/blob/main/lib/server/mention-curation.ts"
click node_newsletter_collector "https://github.com/mreflow/control-center/blob/main/lib/server/newsletter-collector.ts"
click node_newsletter_ai "https://github.com/mreflow/control-center/blob/main/lib/server/newsletter-ai.ts"
click node_ai_runtime "https://github.com/mreflow/control-center/blob/main/lib/server/ai.ts"
click node_audience_collector "https://github.com/mreflow/control-center/blob/main/lib/server/audience.ts"
click node_audience_growth "https://github.com/mreflow/control-center/blob/main/lib/audience-growth.ts"
click node_connector_bridge "https://github.com/mreflow/control-center/blob/main/docs/CONNECTOR_BRIDGE.md"

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_dashboard,node_workspace_api,node_settings_api,node_brief_api,node_models_api,node_google_oauth_start,node_google_oauth_callback toneBlue
class node_database,node_settings,node_workspace,node_scheduler toneAmber
class node_feed_discovery,node_industry_curation,node_mention_research,node_mention_curation,node_newsletter_collector,node_newsletter_ai toneMint
class node_ai_runtime,node_audience_collector,node_audience_growth,node_connector_bridge,node_public_web,node_external_ai toneRose
```

## Components

### Dashboard & local API

- [Control Center UI](https://github.com/mreflow/control-center/blob/main/components/control-center.tsx): Next.js client UI · Live dashboard, audience, and AI settings surfaces. · `components/control-center.tsx`
- [Workspace API](https://github.com/mreflow/control-center/blob/main/app/api/workspace/route.ts): route handler · `app/api/workspace/route.ts`
- [Settings API](https://github.com/mreflow/control-center/blob/main/app/api/settings/route.ts): route handler · `app/api/settings/route.ts`
- [Brief API](https://github.com/mreflow/control-center/blob/main/app/api/brief/route.ts): route handler · Local trust boundary for brief state and connector submissions. · `app/api/brief/route.ts`
- [Model discovery API](https://github.com/mreflow/control-center/blob/main/app/api/ai/models/route.ts): route handler · Returns selectable models without credentials. · `app/api/ai/models/route.ts`
- [Google OAuth start](https://github.com/mreflow/control-center/blob/main/app/api/auth/google/start/route.ts): route handler · `app/api/auth/google/start/route.ts`
- [Google OAuth callback](https://github.com/mreflow/control-center/blob/main/app/api/auth/google/callback/route.ts): route handler · `app/api/auth/google/callback/route.ts`

### Local state & scheduling

- [SQLite content store](https://github.com/mreflow/control-center/blob/main/lib/server/database.ts): local persistence · Durable queues, archives, tasks, newsletters, and audience history. · `lib/server/database.ts`
- [Settings & secrets](https://github.com/mreflow/control-center/blob/main/lib/server/settings.ts): local persistence · Keeps provider credentials server-side. · `lib/server/settings.ts`
- [Workspace & daily brief](https://github.com/mreflow/control-center/blob/main/lib/workspace-store.ts): state composition · Reuses saved collector state instead of recollecting on navigation. · `lib/workspace-store.ts`
- [Collection scheduler](https://github.com/mreflow/control-center/blob/main/lib/server/scheduler.ts): background coordinator · Runs startup, manual, and 15-minute collection. · `lib/server/scheduler.ts`

### Curation pipelines

- [Feed & sitemap discovery](https://github.com/mreflow/control-center/blob/main/lib/feed-discovery.ts): industry discovery · Finds feeds, robots/sitemaps, and topic-search candidates. · `lib/feed-discovery.ts`
- [Industry curation](https://github.com/mreflow/control-center/blob/main/lib/industry-curation.ts): ranking pipeline · Deduplicates, prioritizes, optionally reranks, and bounds the active queue. · `lib/industry-curation.ts`
- [Mention research](https://github.com/mreflow/control-center/blob/main/lib/server/mention-research.ts): candidate discovery · Search and AI candidates remain untrusted until verified. · `lib/server/mention-research.ts`
- [Mention verification](https://github.com/mreflow/control-center/blob/main/lib/server/mention-curation.ts): evidence curation · Requires canonical-page evidence before ranking and archival. · `lib/server/mention-curation.ts`
- [Newsletter collector](https://github.com/mreflow/control-center/blob/main/lib/server/newsletter-collector.ts): background pipeline · Reads bounded unseen Gmail issues and masks bodies before AI processing. · `lib/server/newsletter-collector.ts`
- [Newsletter AI extraction](https://github.com/mreflow/control-center/blob/main/lib/server/newsletter-ai.ts): AI processing · Extracts, ranks, consolidates events, and stores topic aliases. · `lib/server/newsletter-ai.ts`

### Optional integrations

- [AI provider runtime](https://github.com/mreflow/control-center/blob/main/lib/server/ai.ts): server AI boundary · Selects providers, discovers models, and bounds requests. · `lib/server/ai.ts`
- [Audience validation](https://github.com/mreflow/control-center/blob/main/lib/server/audience.ts): public metrics collector · Validates profiles and stores verified readings. · `lib/server/audience.ts`
- [Audience growth analysis](https://github.com/mreflow/control-center/blob/main/lib/audience-growth.ts): metrics derivation · Builds comparable growth and chart data. · `lib/audience-growth.ts`
- [Connector bridge](https://github.com/mreflow/control-center/blob/main/docs/CONNECTOR_BRIDGE.md): ingestion contract · Private automations submit normalized summaries without direct account access. · `docs/CONNECTOR_BRIDGE.md`
- **Public web sources**: external sources · Feeds, sites, search, canonical pages, and public profiles.
- **AI providers**: external providers · Cloud providers or restricted loopback local models.

## Connections

- Control Center UI → Workspace API: loads state
- Control Center UI → Settings API: updates settings
- Control Center UI → Brief API: reads brief
- Control Center UI → Model discovery API: lists models
- Workspace API → Workspace & daily brief: serves
- Settings API → Settings & secrets: reads/writes
- Brief API → Workspace & daily brief: composes
- Model discovery API → AI provider runtime: discovers
- Google OAuth start → Google OAuth callback: OAuth redirect
- Google OAuth callback → Settings & secrets: stores authorization
- Workspace & daily brief → SQLite content store: saved queues and snapshots
- Collection scheduler → Feed & sitemap discovery: triggers
- Collection scheduler → Mention research: triggers
- Collection scheduler → Newsletter collector: triggers
- Collection scheduler → Audience validation: triggers
- Feed & sitemap discovery → Public web sources: discovers
- Feed & sitemap discovery → Industry curation: raw candidates
- Industry curation → AI provider runtime: optional reranking
- Industry curation → SQLite content store: active queue
- Mention research → Public web sources: searches
- Mention research → Mention verification: candidates
- Mention verification → Public web sources: verifies pages
- Mention verification → SQLite content store: verified mentions
- Newsletter collector → Newsletter AI extraction: masked issues
- Newsletter AI extraction → AI provider runtime: requires extraction
- Newsletter AI extraction → SQLite content store: events and aliases
- AI provider runtime → Settings & secrets: provider selection
- AI provider runtime → AI providers: bounded requests
- Audience validation → Public web sources: validates profiles
- Audience validation → SQLite content store: verified readings
- Audience growth analysis → SQLite content store: reads history
- Brief API → Connector bridge: accepts summaries
