# sachinlade/pl_email_report architecture

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

- Interactive diagram: https://gitdiagram.com/sachinlade/pl_email_report
- Repository: https://github.com/sachinlade/pl_email_report

## Overview

#### Purpose and Entry Point
This is a Python reporting pipeline that appears to read database data, calculate report metrics, build charts and email content, and deliver reports. The likely orchestration entry point is `send_report.py`; supporting dependencies are declared in `requirements.txt`.

#### Report Orchestration
`send_report.py` is the top-level control boundary: it likely coordinates data acquisition, calculations, rendering, delivery, and logging. Configuration is centralized in `config.py`, separating environment-specific settings such as database and mail connection details from report logic.

Paths: `send_report.py`, `config.py`

#### Data Access and Synchronization
Database interaction is divided into a read-oriented component and a synchronization component. `db_reader.py` likely provides report-query inputs, while `sql_sync.py` likely updates or synchronizes SQL-backed source/derived data before or alongside report generation.

Paths: `db_reader.py`, `sql_sync.py`

#### Calculation Layer
`calculations.py` is the business/analytics boundary. It should transform raw database results into report-ready aggregates, KPIs, comparisons, or other derived values. This keeps SQL retrieval and presentation concerns outside the core calculation stage.

Paths: `calculations.py`, `db_reader.py`

#### Presentation Assembly
The presentation path is split between chart generation and email composition. `chart_builder.py` likely converts calculated datasets into chart artifacts or embedded visual content; `email_builder.py` likely combines metrics, narrative, and chart output into a mail-ready body.

Paths: `chart_builder.py`, `email_builder.py`, `calculations.py`

#### Delivery and Operational Observability
`mailer.py` is the external delivery boundary, responsible for handing assembled messages to an email service or SMTP runtime. `report_logging.py` likely records report execution, send status, failures, or audit information, enabling operational visibility around scheduled or repeatable report runs.

Paths: `mailer.py`, `report_logging.py`, `send_report.py`

#### Primary Flow and Boundaries
The expected control flow is: `send_report.py` loads `config.py`, optionally invokes `sql_sync.py`, retrieves data through `db_reader.py`, derives metrics in `calculations.py`, renders visuals via `chart_builder.py`, creates message content in `email_builder.py`, sends through `mailer.py`, and records outcomes in `report_logging.py`. The principal external boundaries are the SQL database and email transport; both should remain isolated behind their respective modules.

Main entry points: [`send_report.py`](https://github.com/sachinlade/pl_email_report/blob/master/send_report.py) (Report runner), [`calculations.py`](https://github.com/sachinlade/pl_email_report/blob/master/calculations.py) (Metrics calculations), [`db_reader.py`](https://github.com/sachinlade/pl_email_report/blob/master/db_reader.py) (Database reader), [`mailer.py`](https://github.com/sachinlade/pl_email_report/blob/master/mailer.py) (Mailer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Report pipeline"]
  node_orchestrator["Report runner<br/>Python entry point<br/>[send_report.py]"]
  node_config["Configuration<br/>Settings module<br/>[config.py]"]
  node_calculations["Metrics calculations<br/>Analytics module<br/>[calculations.py]"]
  node_chart_builder["Chart builder<br/>Visualization module<br/>[chart_builder.py]"]
end

subgraph group_data["Data boundary"]
  node_sql_sync["SQL synchronization<br/>Sync module<br/>[sql_sync.py]"]
  node_db_reader["Database reader<br/>Data access module<br/>[db_reader.py]"]
  node_database[("SQL database<br/>External data store")]
end

subgraph group_delivery["Delivery &amp; operations"]
  node_email_builder["Email builder<br/>Message composition module<br/>[email_builder.py]"]
  node_mailer["Mailer<br/>Delivery module<br/>[mailer.py]"]
  node_email_transport{{"Email transport<br/>External mail service"}}
  node_logging["Report logging<br/>Observability module<br/>[report_logging.py]"]
end

node_orchestrator -->|"loads"| node_config
node_orchestrator -->|"optionally runs"| node_sql_sync
node_sql_sync -->|"synchronizes"| node_database
node_orchestrator -->|"requests data"| node_db_reader
node_db_reader -->|"queries"| node_database
node_db_reader -->|"raw results"| node_calculations
node_calculations -->|"chart data"| node_chart_builder
node_calculations -->|"metrics"| node_email_builder
node_chart_builder -->|"charts"| node_email_builder
node_email_builder -->|"mail-ready message"| node_mailer
node_mailer -->|"delivers"| node_email_transport
node_orchestrator -.->|"records run status"| node_logging
node_mailer -.->|"delivery outcome"| node_logging

click node_orchestrator "https://github.com/sachinlade/pl_email_report/blob/master/send_report.py"
click node_config "https://github.com/sachinlade/pl_email_report/blob/master/config.py"
click node_sql_sync "https://github.com/sachinlade/pl_email_report/blob/master/sql_sync.py"
click node_db_reader "https://github.com/sachinlade/pl_email_report/blob/master/db_reader.py"
click node_calculations "https://github.com/sachinlade/pl_email_report/blob/master/calculations.py"
click node_chart_builder "https://github.com/sachinlade/pl_email_report/blob/master/chart_builder.py"
click node_email_builder "https://github.com/sachinlade/pl_email_report/blob/master/email_builder.py"
click node_mailer "https://github.com/sachinlade/pl_email_report/blob/master/mailer.py"
click node_logging "https://github.com/sachinlade/pl_email_report/blob/master/report_logging.py"

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_orchestrator,node_config,node_calculations,node_chart_builder toneBlue
class node_sql_sync,node_db_reader,node_database toneAmber
class node_email_builder,node_mailer,node_email_transport,node_logging toneMint
```

## Components

### Report pipeline

- [Report runner](https://github.com/sachinlade/pl_email_report/blob/master/send_report.py): Python entry point · Coordinates the report run. · `send_report.py`
- [Configuration](https://github.com/sachinlade/pl_email_report/blob/master/config.py): Settings module · `config.py`
- [Metrics calculations](https://github.com/sachinlade/pl_email_report/blob/master/calculations.py): Analytics module · Transforms query results into report metrics. · `calculations.py`
- [Chart builder](https://github.com/sachinlade/pl_email_report/blob/master/chart_builder.py): Visualization module · `chart_builder.py`

### Data boundary

- [SQL synchronization](https://github.com/sachinlade/pl_email_report/blob/master/sql_sync.py): Sync module · Prepares or updates SQL-backed data. · `sql_sync.py`
- [Database reader](https://github.com/sachinlade/pl_email_report/blob/master/db_reader.py): Data access module · `db_reader.py`
- **SQL database**: External data store

### Delivery & operations

- [Email builder](https://github.com/sachinlade/pl_email_report/blob/master/email_builder.py): Message composition module · Combines metrics and charts into email content. · `email_builder.py`
- [Mailer](https://github.com/sachinlade/pl_email_report/blob/master/mailer.py): Delivery module · `mailer.py`
- **Email transport**: External mail service
- [Report logging](https://github.com/sachinlade/pl_email_report/blob/master/report_logging.py): Observability module · Records execution and delivery outcomes. · `report_logging.py`

## Connections

- Report runner → Configuration: loads
- Report runner → SQL synchronization: optionally runs
- SQL synchronization → SQL database: synchronizes
- Report runner → Database reader: requests data
- Database reader → SQL database: queries
- Database reader → Metrics calculations: raw results
- Metrics calculations → Chart builder: chart data
- Metrics calculations → Email builder: metrics
- Chart builder → Email builder: charts
- Email builder → Mailer: mail-ready message
- Mailer → Email transport: delivers
- Report runner → Report logging: records run status
- Mailer → Report logging: delivery outcome
