# marcom-meniac/reddit-insights architecture

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

- Interactive diagram: https://gitdiagram.com/marcom-meniac/reddit-insights
- Repository: https://github.com/marcom-meniac/reddit-insights

## Overview

#### Purpose and Execution

This is a read-only Reddit marketing-intelligence pipeline. It collects public posts from configured technology communities, enriches them with rule-based topic labels and VADER sentiment, then persists results to PostgreSQL for downstream analysis.

`main.py` is the application entry point and coordinates logging, Reddit collection, processing, and database persistence.

Paths: `main.py`, `README.md`, `config.example.py`

#### Reddit Collection Boundary

The Reddit adapter encapsulates access to Reddit’s official API, expected to use PRAW and configured credentials. It should be the only component that communicates with Reddit and must preserve the repository’s read-only constraint: no posting, voting, messaging, moderation, or other mutations.

Collection scope—such as monitored subreddits and query limits—is configuration-driven rather than embedded in the orchestration layer.

Paths: `reddit.py`, `config.example.py`, `main.py`

#### Processing and Enrichment

Raw Reddit post content flows through two independent enrichment stages:

- Topic classification applies a rule-based technology taxonomy to identify themes such as trends, adoption, or customer pain points.
- Sentiment analysis uses VADER to score discussion sentiment.

These stages should remain pure or near-pure transformations over collected text, allowing their rules/models to evolve independently of API and persistence code.

Paths: `classifier.py`, `sentiment.py`, `main.py`

#### Domain Model Contract

`models.py` defines the internal representation of collected and enriched Reddit data. It is the contract between ingestion, analysis, and storage: Reddit-specific source fields are normalized into application records, then classification and sentiment outputs are attached before persistence.

Changes to stored fields or enrichment outputs should be coordinated through this model boundary.

Paths: `models.py`, `reddit.py`, `database.py`

#### Persistence Layer

The database module owns PostgreSQL and SQLAlchemy integration. It provides the boundary between application records and durable relational storage, including connection/session lifecycle and writes. Database schema assets live under `sql/reddit`, although the exact SQL files are not exposed in the provided tree.

The intended control flow is: retrieve posts → normalize/model → classify and score sentiment → save to PostgreSQL.

Paths: `database.py`, `models.py`, `sql/reddit`

#### Shared Runtime Concerns

Structured logging is centralized rather than scattered through collectors and processors. Shared utilities support cross-cutting normalization or helper behavior without becoming a second orchestration path. Runtime dependencies include Python 3.11+, PRAW, SQLAlchemy, PostgreSQL, VADER Sentiment, and python-dotenv.

Local output is reserved under `output/`; it is not the primary system of record, which is PostgreSQL.

Paths: `logging_config.py`, `utils.py`, `requirements.txt`

#### Operational Boundaries

Secrets and environment-specific database/API settings are expected outside versioned source via a copied `config.py`, derived from `config.example.py`. The application is a batch-style Python process invoked with `python main.py`, not a web service. External failure domains are Reddit API availability/rate limits and PostgreSQL connectivity; orchestration should log and isolate failures at those boundaries.

Paths: `config.example.py`, `main.py`, `logging_config.py`

Main entry points: [`main.py`](https://github.com/marcom-meniac/reddit-insights/blob/main/main.py) (Application entry point), [`models.py`](https://github.com/marcom-meniac/reddit-insights/blob/main/models.py) (Application records), [`database.py`](https://github.com/marcom-meniac/reddit-insights/blob/main/database.py) (Database layer), [`reddit.py`](https://github.com/marcom-meniac/reddit-insights/blob/main/reddit.py) (Reddit adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Batch Runtime"]
  node_main["Application entry point<br/>Python orchestrator<br/>[main.py]"]
  node_config["Configuration template<br/>configuration contract<br/>[config.example.py]"]
  node_logging["Structured logging<br/>logging setup<br/>[logging_config.py]"]
  node_utils["Shared utilities<br/>utility module<br/>[utils.py]"]
  node_requirements["Runtime dependencies<br/>dependency manifest<br/>[requirements.txt]"]
  node_output["Local output<br/>local artifacts"]
end

subgraph group_pipeline["Collection &amp; Enrichment"]
  node_reddit_adapter["Reddit adapter<br/>read-only API adapter<br/>[reddit.py]"]
  node_reddit_api{{"Reddit API<br/>external service"}}
  node_domain_model["Application records<br/>domain model<br/>[models.py]"]
  node_classifier["Topic classifier<br/>rule-based enrichment<br/>[classifier.py]"]
  node_sentiment["VADER sentiment<br/>text enrichment<br/>[sentiment.py]"]
end

subgraph group_storage["Persistence"]
  node_database["Database layer<br/>SQLAlchemy persistence<br/>[database.py]"]
  node_schema["Database schema assets<br/>SQL schema"]
  node_postgres[("PostgreSQL<br/>external database")]
end

node_config -.->|"runtime settings"| node_main
node_config -.->|"credentials and scope"| node_reddit_adapter
node_config -.->|"connection settings"| node_database
node_logging -.->|"configures logging"| node_main
node_utils -.->|"shared helpers"| node_main
node_requirements -.->|"provides runtime libraries"| node_main
node_main -->|"collect posts"| node_reddit_adapter
node_reddit_adapter -->|"read-only requests"| node_reddit_api
node_reddit_adapter -->|"normalize source posts"| node_domain_model
node_main -->|"classify text"| node_classifier
node_main -->|"score text"| node_sentiment
node_domain_model -->|"post content"| node_classifier
node_domain_model -->|"post content"| node_sentiment
node_classifier -->|"attach topics"| node_domain_model
node_sentiment -->|"attach score"| node_domain_model
node_main -->|"persist enriched records"| node_database
node_domain_model -->|"storage contract"| node_database
node_database -->|"SQLAlchemy writes"| node_postgres
node_schema -.->|"defines relational schema"| node_database

click node_main "https://github.com/marcom-meniac/reddit-insights/blob/main/main.py"
click node_config "https://github.com/marcom-meniac/reddit-insights/blob/main/config.example.py"
click node_logging "https://github.com/marcom-meniac/reddit-insights/blob/main/logging_config.py"
click node_utils "https://github.com/marcom-meniac/reddit-insights/blob/main/utils.py"
click node_requirements "https://github.com/marcom-meniac/reddit-insights/blob/main/requirements.txt"
click node_reddit_adapter "https://github.com/marcom-meniac/reddit-insights/blob/main/reddit.py"
click node_domain_model "https://github.com/marcom-meniac/reddit-insights/blob/main/models.py"
click node_classifier "https://github.com/marcom-meniac/reddit-insights/blob/main/classifier.py"
click node_sentiment "https://github.com/marcom-meniac/reddit-insights/blob/main/sentiment.py"
click node_database "https://github.com/marcom-meniac/reddit-insights/blob/main/database.py"
click node_schema "https://github.com/marcom-meniac/reddit-insights/blob/main/sql/reddit"

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_main,node_config,node_logging,node_utils,node_requirements,node_output toneBlue
class node_reddit_adapter,node_reddit_api,node_domain_model,node_classifier,node_sentiment toneAmber
class node_database,node_schema,node_postgres toneMint
```

## Components

### Batch Runtime

Python batch process and shared runtime concerns.

- [Application entry point](https://github.com/marcom-meniac/reddit-insights/blob/main/main.py): Python orchestrator · Coordinates collection, enrichment, and persistence. · `main.py`
- [Configuration template](https://github.com/marcom-meniac/reddit-insights/blob/main/config.example.py): configuration contract · Defines copied local API, database, and collection settings. · `config.example.py`
- [Structured logging](https://github.com/marcom-meniac/reddit-insights/blob/main/logging_config.py): logging setup · `logging_config.py`
- [Shared utilities](https://github.com/marcom-meniac/reddit-insights/blob/main/utils.py): utility module · `utils.py`
- [Runtime dependencies](https://github.com/marcom-meniac/reddit-insights/blob/main/requirements.txt): dependency manifest · `requirements.txt`
- **Local output**: local artifacts · Reserved for non-primary local output.

### Collection & Enrichment

Read-only ingestion and independent text enrichment stages.

- [Reddit adapter](https://github.com/marcom-meniac/reddit-insights/blob/main/reddit.py): read-only API adapter · The sole boundary communicating with Reddit. · `reddit.py`
- **Reddit API**: external service · Public Reddit data source subject to rate limits.
- [Application records](https://github.com/marcom-meniac/reddit-insights/blob/main/models.py): domain model · Normalized contract between ingestion, enrichment, and storage. · `models.py`
- [Topic classifier](https://github.com/marcom-meniac/reddit-insights/blob/main/classifier.py): rule-based enrichment · Assigns technology taxonomy themes. · `classifier.py`
- [VADER sentiment](https://github.com/marcom-meniac/reddit-insights/blob/main/sentiment.py): text enrichment · Scores discussion sentiment. · `sentiment.py`

### Persistence

Relational storage boundary and schema assets.

- [Database layer](https://github.com/marcom-meniac/reddit-insights/blob/main/database.py): SQLAlchemy persistence · Owns PostgreSQL sessions and durable writes. · `database.py`
- [Database schema assets](https://github.com/marcom-meniac/reddit-insights/blob/main/sql/reddit): SQL schema · `sql/reddit`
- **PostgreSQL**: external database · Primary system of record.

## Connections

- Configuration template → Application entry point: runtime settings
- Configuration template → Reddit adapter: credentials and scope
- Configuration template → Database layer: connection settings
- Structured logging → Application entry point: configures logging
- Shared utilities → Application entry point: shared helpers
- Runtime dependencies → Application entry point: provides runtime libraries
- Application entry point → Reddit adapter: collect posts
- Reddit adapter → Reddit API: read-only requests
- Reddit adapter → Application records: normalize source posts
- Application entry point → Topic classifier: classify text
- Application entry point → VADER sentiment: score text
- Application records → Topic classifier: post content
- Application records → VADER sentiment: post content
- Topic classifier → Application records: attach topics
- VADER sentiment → Application records: attach score
- Application entry point → Database layer: persist enriched records
- Application records → Database layer: storage contract
- Database layer → PostgreSQL: SQLAlchemy writes
- Database schema assets → Database layer: defines relational schema
