# kalvium23/ak64_salespulse__kalvium-community architecture

> Architecture diagram of the GitHub repository kalvium23/ak64_salespulse__kalvium-community, 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/kalvium23/ak64_salespulse__kalvium-community
- Repository: https://github.com/kalvium23/ak64_salespulse__kalvium-community

## Overview

#### Purpose and entry points
A Python analytics workspace for B2B sales/CRM data: customers, deals, activities, and email history are processed into sales-performance, funnel, behavioral, anomaly, and KPI outputs. Main operational entry points are `pipeline.py`, `app.py`, and the Streamlit-style multipage dashboard under `pages/`. A second frontend implementation exists under `frontend/`.

#### Dashboard and user-facing layer
The primary UI is organized around a shell plus analytical pages: `app.py`, `components/header.py`, and `components/sidebar.py` provide application composition; `pages/1_Pipeline_Analytics.py`, `pages/2_Sales_Performance.py`, and `pages/4_Behaviour_Analytics.py` expose domain views. The alternate dashboard surface is `frontend/dashboard_app.py` with `frontend/kpi_dashboard.py`. UI consumes locally processed datasets and analysis services rather than a declared backend API.

#### Data ingestion and canonical processing
Raw CSV/JSON sources enter from `data/raw/` and CRM-shaped sources from `data/raw_new/`. The processing layer produces durable CSV artifacts in `data/processed/`, notably `data/processed/master_salespulse.csv`, `data/processed/merged_customer_orders.csv`, and cleaned CRM tables. Pipeline stages are implemented as independently executable scripts, with orchestration-oriented paths `pipeline.py`, `scripts/salespulse_pipeline.py`, and `scripts/data_workflow.py`.

#### Data quality and feature pipeline
Data preparation is a staged file-based boundary: intake/schema validation, cleaning, typing, deduplication, missing-value handling, and features transform raw data into analysis-ready tables. Core stages reside in `scripts/ingest_data.py`, `scripts/validate_intake.py`, and `scripts/feature_engineering.py`; related outputs are materialized rather than dynamically queried. Validation artifacts and audit reports are written under `output/`, allowing downstream analysis to use inspected datasets.

#### Sales, CRM, and behavioral analytics
Domain modules calculate business-facing insights over processed CRM and transaction data. `crm_manager.py` and `deal_predictor.py` cover CRM/deal-oriented logic; `behaviour_analytics.py` handles behavioral analysis; `email_analyzer.py` handles communication history. Segmentation and funnel analysis are represented by `scripts/behavioural_analysis_user_segmentation.py`, `scripts/funnel_analysis.py`, and their persisted outputs such as `data/processed/segment_summary_ranked.csv`.

#### KPI, anomaly, and narrative/reporting layer
KPI calculations are centralized in `kpis/kpi_functions.py`, with reference definitions and validation targets in `kpis/kpi_reference.md` and `kpis/kpi_validation_targets.json`. Risk/investigation processing is supported by `scripts/anomaly_detection_risk.py` and `scripts/root_cause_investigation.py`. Outputs flow into exports and reports through `report_generator.py`, `export_functions.py`, and `output/`, including CSV, JSON, HTML, PDF, and text deliverables. AI coaching and alerting are separate integration points in `ai_coaching.py` and `alert_config.py`.

#### SQL analytics and infrastructure boundary
The repository supports a relational-database analytics path alongside file-based processing. Query definitions live in `queries/`; reusable database abstractions appear in `database/views/vw_active_customers.sql` and `database/aggregations/agg_daily_metrics.sql`; `database_manager.py` and `scripts/sql_environment_database_integration.py` bridge Python to database operations. Database credentials and API keys are expected from environment configuration (`.env.example`), not committed source. CI validation is defined in `.github/workflows/validate.yml` and pipeline automation in `.github/workflows/pipeline.yml`.

Main entry points: [`pages/1_Pipeline_Analytics.py`](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/pages/1_Pipeline_Analytics.py) (Analytical pages), [`report_generator.py`](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/report_generator.py) (Reports and exports), [`scripts/ingest_data.py`](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/ingest_data.py) (Intake and validation), [`crm_manager.py`](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/crm_manager.py) (CRM and deal analytics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Dashboard surfaces"]
  node_primary_dashboard["Primary dashboard shell<br/>Streamlit app<br/>[app.py]"]
  node_dashboard_pages["Analytical pages<br/>dashboard views"]
  node_dashboard_components["Dashboard components<br/>UI composition<br/>[header.py]"]
  node_alternate_dashboard["Alternate dashboard<br/>frontend app<br/>[dashboard_app.py]"]
end

subgraph group_pipeline["File data pipeline"]
  node_raw_data[("Raw sources<br/>CSV/JSON inputs")]
  node_raw_crm[("CRM-shaped sources<br/>CRM inputs")]
  node_pipeline_entry["Pipeline orchestrator<br/>Python entry point<br/>[pipeline.py]"]
  node_intake["Intake and validation<br/>processing stage<br/>[ingest_data.py]"]
  node_feature_pipeline["Clean and feature pipeline<br/>processing stage"]
  node_processed_data[("Processed datasets<br/>durable CSVs")]
  node_validation_output["Validation artifacts<br/>audit output"]
end

subgraph group_analytics["Analytics and reporting"]
  node_crm_deals["CRM and deal analytics<br/>domain service<br/>[crm_manager.py]"]
  node_behavior_analytics["Behavior analytics<br/>domain service"]
  node_segmentation_funnel["Segmentation and funnel<br/>analysis stage<br/>[funnel_analysis.py]"]
  node_email_analytics["Email analysis<br/>domain service<br/>[email_analyzer.py]"]
  node_kpis["KPI calculations<br/>metrics service<br/>[kpi_functions.py]"]
  node_risk_investigation["Risk investigation<br/>anomaly analysis"]
  node_reporting["Reports and exports<br/>delivery service"]
  node_ai_alerts["AI coaching and alerts<br/>integration points<br/>[ai_coaching.py]"]
end

subgraph group_database["SQL analytics path"]
  node_sql_queries["SQL queries and models<br/>database analytics"]
  node_database_bridge["Database bridge<br/>Python integration"]
end

node_raw_data -->|"orchestrated input"| node_pipeline_entry
node_raw_crm -->|"orchestrated input"| node_pipeline_entry
node_pipeline_entry -->|"runs"| node_intake
node_intake -->|"validated data"| node_feature_pipeline
node_intake -->|"audit reports"| node_validation_output
node_feature_pipeline -->|"materializes"| node_processed_data
node_processed_data -->|"CRM tables"| node_crm_deals
node_processed_data -->|"activity data"| node_behavior_analytics
node_processed_data -->|"customer and deal data"| node_segmentation_funnel
node_processed_data -->|"email history"| node_email_analytics
node_processed_data -->|"metrics inputs"| node_kpis
node_processed_data -->|"investigation inputs"| node_risk_investigation
node_segmentation_funnel -->|"segment outputs"| node_processed_data
node_crm_deals -->|"insights"| node_reporting
node_behavior_analytics -->|"insights"| node_reporting
node_kpis -->|"KPI outputs"| node_reporting
node_risk_investigation -->|"findings"| node_reporting
node_risk_investigation -->|"risk signals"| node_ai_alerts
node_processed_data -->|"local datasets"| node_primary_dashboard
node_crm_deals -->|"domain analysis"| node_dashboard_pages
node_behavior_analytics -->|"behavior views"| node_dashboard_pages
node_kpis -->|"metrics"| node_dashboard_pages
node_primary_dashboard -->|"hosts"| node_dashboard_pages
node_dashboard_components -->|"composes"| node_primary_dashboard
node_processed_data -->|"local datasets"| node_alternate_dashboard
node_sql_queries -->|"executed through"| node_database_bridge
node_database_bridge -.->|"relational analytics path"| node_processed_data

click node_pipeline_entry "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/pipeline.py"
click node_intake "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/ingest_data.py"
click node_feature_pipeline "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/feature_engineering.py"
click node_primary_dashboard "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/app.py"
click node_dashboard_pages "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/pages/1_Pipeline_Analytics.py"
click node_dashboard_components "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/components/header.py"
click node_alternate_dashboard "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/frontend/dashboard_app.py"
click node_crm_deals "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/crm_manager.py"
click node_behavior_analytics "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/behaviour_analytics.py"
click node_segmentation_funnel "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/funnel_analysis.py"
click node_email_analytics "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/email_analyzer.py"
click node_kpis "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/kpis/kpi_functions.py"
click node_risk_investigation "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/anomaly_detection_risk.py"
click node_reporting "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/report_generator.py"
click node_ai_alerts "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/ai_coaching.py"
click node_database_bridge "https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/database_manager.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_primary_dashboard,node_dashboard_pages,node_dashboard_components,node_alternate_dashboard toneBlue
class node_raw_data,node_raw_crm,node_pipeline_entry,node_intake,node_feature_pipeline,node_processed_data,node_validation_output toneAmber
class node_crm_deals,node_behavior_analytics,node_segmentation_funnel,node_email_analytics,node_kpis,node_risk_investigation,node_reporting,node_ai_alerts toneMint
class node_sql_queries,node_database_bridge toneRose
```

## Components

### Dashboard surfaces

- [Primary dashboard shell](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/app.py): Streamlit app · `app.py`
- [Analytical pages](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/pages/1_Pipeline_Analytics.py): dashboard views · Pipeline, sales performance, and behavior views. · `pages/1_Pipeline_Analytics.py`
- [Dashboard components](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/components/header.py): UI composition · `components/header.py`
- [Alternate dashboard](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/frontend/dashboard_app.py): frontend app · `frontend/dashboard_app.py`

### File data pipeline

- **Raw sources**: CSV/JSON inputs · Sales and CRM source files.
- **CRM-shaped sources**: CRM inputs
- [Pipeline orchestrator](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/pipeline.py): Python entry point · `pipeline.py`
- [Intake and validation](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/ingest_data.py): processing stage · `scripts/ingest_data.py`
- [Clean and feature pipeline](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/feature_engineering.py): processing stage · Types, deduplication, missing values, and features. · `scripts/feature_engineering.py`
- **Processed datasets**: durable CSVs · Canonical analysis-ready tables.
- **Validation artifacts**: audit output

### Analytics and reporting

- [CRM and deal analytics](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/crm_manager.py): domain service · `crm_manager.py`
- [Behavior analytics](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/behaviour_analytics.py): domain service · `behaviour_analytics.py`
- [Segmentation and funnel](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/funnel_analysis.py): analysis stage · `scripts/funnel_analysis.py`
- [Email analysis](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/email_analyzer.py): domain service · `email_analyzer.py`
- [KPI calculations](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/kpis/kpi_functions.py): metrics service · `kpis/kpi_functions.py`
- [Risk investigation](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/scripts/anomaly_detection_risk.py): anomaly analysis · `scripts/anomaly_detection_risk.py`
- [Reports and exports](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/report_generator.py): delivery service · Produces CSV, JSON, HTML, PDF, and text deliverables. · `report_generator.py`
- [AI coaching and alerts](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/ai_coaching.py): integration points · `ai_coaching.py`

### SQL analytics path

- **SQL queries and models**: database analytics · Reusable queries, views, and aggregations.
- [Database bridge](https://github.com/kalvium23/ak64_salespulse__kalvium-community/blob/main/database_manager.py): Python integration · `database_manager.py`

## Connections

- Raw sources → Pipeline orchestrator: orchestrated input
- CRM-shaped sources → Pipeline orchestrator: orchestrated input
- Pipeline orchestrator → Intake and validation: runs
- Intake and validation → Clean and feature pipeline: validated data
- Intake and validation → Validation artifacts: audit reports
- Clean and feature pipeline → Processed datasets: materializes
- Processed datasets → CRM and deal analytics: CRM tables
- Processed datasets → Behavior analytics: activity data
- Processed datasets → Segmentation and funnel: customer and deal data
- Processed datasets → Email analysis: email history
- Processed datasets → KPI calculations: metrics inputs
- Processed datasets → Risk investigation: investigation inputs
- Segmentation and funnel → Processed datasets: segment outputs
- CRM and deal analytics → Reports and exports: insights
- Behavior analytics → Reports and exports: insights
- KPI calculations → Reports and exports: KPI outputs
- Risk investigation → Reports and exports: findings
- Risk investigation → AI coaching and alerts: risk signals
- Processed datasets → Primary dashboard shell: local datasets
- CRM and deal analytics → Analytical pages: domain analysis
- Behavior analytics → Analytical pages: behavior views
- KPI calculations → Analytical pages: metrics
- Primary dashboard shell → Analytical pages: hosts
- Dashboard components → Primary dashboard shell: composes
- Processed datasets → Alternate dashboard: local datasets
- SQL queries and models → Database bridge: executed through
- Database bridge → Processed datasets: relational analytics path
