# anand-analytics/customer-behaviour-dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/anand-analytics/customer-behaviour-dashboard
- Repository: https://github.com/anand-analytics/customer-behaviour-dashboard

## Overview

#### Purpose and Entry Points
This is a retail customer-behaviour analytics project: it transforms raw shopping records into cleaned analytical data, answers business questions in SQL, and presents KPIs in a Power BI dashboard. Primary artifacts are the source dataset at `Data/customer_shopping_behavior.csv`, the cleaning notebook at `Python/Python Data Cleaning.ipynb`, SQL analysis at `SQL/SQL_Queries.sql`, and the dashboard at `Power BI/Customer_Behaviour_Analysis_Dashboard.pbix`.

#### 1. Raw Customer Shopping Data
`Data/customer_shopping_behavior.csv` is the system-of-record input. It contains customer demographics, purchases, product/category information, reviews, discount/promotion behaviour, shipping, subscriptions, and purchase frequency. Its schema is the contract consumed by the Python cleaning stage.

#### 2. Python Cleaning and Feature Engineering
`Python/Python Data Cleaning.ipynb` is the primary transformation entry point. It prepares the CSV for database and reporting use by:
- imputing missing review ratings using the category median;
- converting column names to snake_case;
- removing the redundant `promo_code_used` field;
- deriving `age_group` and numeric `purchase_frequency_days`.

This notebook forms the boundary between source-format data and an analysis-ready relational/reporting dataset.

#### 3. MySQL Analytical Layer
`SQL/SQL_Queries.sql` contains the business-analysis query layer intended to run after cleaned data is loaded into MySQL. Queries aggregate and segment customers, products, revenue, discounts, and ratings. Material analytical techniques include CTEs, `CASE`-based lifecycle segments, ranking, and `ROW_NUMBER()` window functions for top products per category.

The notebook-to-MySQL load step is implied by the workflow but is not represented as a standalone ingestion script in the repository.

#### 4. Customer and Revenue Segmentation
The SQL layer produces decision-oriented segments: revenue by gender and age group, high-spend discount users, discount-dependent products, product rating rankings, and New/Returning/Loyal customer groups based on purchase frequency. These outputs support marketing, engagement, product, and subscription decisions rather than operational transaction processing.

#### 5. Power BI Semantic and Presentation Layer
`Power BI/Customer_Behaviour_Analysis_Dashboard.pbix` is the management-facing consumption endpoint. It imports or connects to the prepared dataset and defines dashboard measures for customer count, average purchase amount, and average review rating. Its visuals cover revenue/category, sales/age group, and subscription status; slicers expose gender, subscription, category, and shipping-type filters.

#### 6. End-to-End Control Flow
The intended flow is:
1. Read `Data/customer_shopping_behavior.csv`.
2. Clean and enrich it in `Python/Python Data Cleaning.ipynb`.
3. Load the cleaned records into a MySQL table.
4. Execute `SQL/SQL_Queries.sql` for advanced analysis and validation.
5. Refresh `Power BI/Customer_Behaviour_Analysis_Dashboard.pbix` to provide interactive KPI exploration.

There is no application server, API, scheduler, or automated orchestration represented in the file tree; execution is analyst-driven through Jupyter, MySQL, and Power BI.

#### 7. Runtime and Infrastructure Boundaries
Material runtimes are Python/Jupyter for transformation and EDA, MySQL for relational querying, and Power BI Desktop/Service-compatible `.pbix` reporting. The repository stores the raw CSV and report artifact, but does not include MySQL schema definitions, database connection settings, packaged Python dependencies, or a persisted cleaned-data export. These are operational integration points for anyone reproducing or automating the workflow.

Main entry points: [`SQL/SQL_Queries.sql`](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/SQL/SQL_Queries.sql) (Business analysis queries), [`Power BI/Customer_Behaviour_Analysis_Dashboard.pbix`](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Power%20BI/Customer_Behaviour_Analysis_Dashboard.pbix) (Customer behaviour dashboard), [`Python/Python Data Cleaning.ipynb`](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Python/Python%20Data%20Cleaning.ipynb) (Cleaning & feature engineering), [`Data/customer_shopping_behavior.csv`](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Data/customer_shopping_behavior.csv) (Customer shopping records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_source["Source Data"]
  node_raw_csv[("Customer shopping records<br/>CSV source")]
end

subgraph group_transform["Preparation"]
  node_cleaning_notebook["Cleaning &amp; feature engineering<br/>Jupyter notebook"]
  node_cleaned_dataset[("Analysis-ready records<br/>prepared dataset")]
end

subgraph group_mysql["MySQL Analytics"]
  node_mysql_table[("Customer analytics table<br/>MySQL table")]
  node_sql_queries["Business analysis queries<br/>SQL script<br/>[SQL_Queries.sql]"]
  node_revenue_segments["Revenue &amp; demographic segments<br/>SQL output"]
  node_product_insights["Product &amp; rating insights<br/>SQL output"]
  node_lifecycle_segments["Customer lifecycle segments<br/>SQL output"]
end

subgraph group_reporting["BI Reporting"]
  node_powerbi_dashboard["Customer behaviour dashboard<br/>Power BI report"]
  node_kpi_measures["KPI measures<br/>Power BI semantic layer"]
  node_interactive_visuals["Interactive visuals &amp; slicers<br/>Power BI presentation"]
end

node_raw_csv -->|"read source schema"| node_cleaning_notebook
node_cleaning_notebook -->|"clean and enrich"| node_cleaned_dataset
node_cleaned_dataset -.->|"analyst loads"| node_mysql_table
node_mysql_table -->|"query"| node_sql_queries
node_sql_queries -->|"aggregate and segment"| node_revenue_segments
node_sql_queries -->|"rank and analyze"| node_product_insights
node_sql_queries -->|"classify lifecycle"| node_lifecycle_segments
node_mysql_table -->|"connect or import"| node_powerbi_dashboard
node_cleaned_dataset -.->|"alternative import"| node_powerbi_dashboard
node_powerbi_dashboard -->|"defines"| node_kpi_measures
node_kpi_measures -->|"powers"| node_interactive_visuals
node_revenue_segments -.->|"informs decisions"| node_interactive_visuals
node_product_insights -.->|"informs decisions"| node_interactive_visuals
node_lifecycle_segments -.->|"informs decisions"| node_interactive_visuals

click node_raw_csv "https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Data/customer_shopping_behavior.csv"
click node_cleaning_notebook "https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Python/Python%20Data%20Cleaning.ipynb"
click node_sql_queries "https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/SQL/SQL_Queries.sql"
click node_powerbi_dashboard "https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Power%20BI/Customer_Behaviour_Analysis_Dashboard.pbix"

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_raw_csv toneBlue
class node_cleaning_notebook,node_cleaned_dataset toneAmber
class node_mysql_table,node_sql_queries,node_revenue_segments,node_product_insights,node_lifecycle_segments toneMint
class node_powerbi_dashboard,node_kpi_measures,node_interactive_visuals toneRose
```

## Components

### Source Data

- [Customer shopping records](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Data/customer_shopping_behavior.csv): CSV source · System-of-record customer and purchase data. · `Data/customer_shopping_behavior.csv`

### Preparation

- [Cleaning & feature engineering](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Python/Python%20Data%20Cleaning.ipynb): Jupyter notebook · Imputes ratings, normalizes fields, and derives analysis features. · `Python/Python Data Cleaning.ipynb`
- **Analysis-ready records**: prepared dataset · Cleaned records with age group and purchase-frequency days.

### MySQL Analytics

- **Customer analytics table**: MySQL table · Implied analyst-loaded relational dataset.
- [Business analysis queries](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/SQL/SQL_Queries.sql): SQL script · Aggregates, segments, ranks, and validates customer behaviour. · `SQL/SQL_Queries.sql`
- **Revenue & demographic segments**: SQL output · Revenue by gender and age group plus high-spend discount users.
- **Product & rating insights**: SQL output · Discount-dependent products and top-rated products per category.
- **Customer lifecycle segments**: SQL output · New, Returning, and Loyal groups based on purchase frequency.

### BI Reporting

- [Customer behaviour dashboard](https://github.com/anand-analytics/customer-behaviour-dashboard/blob/main/Power%20BI/Customer_Behaviour_Analysis_Dashboard.pbix): Power BI report · Management-facing interactive KPI and segmentation reporting. · `Power BI/Customer_Behaviour_Analysis_Dashboard.pbix`
- **KPI measures**: Power BI semantic layer · Customer count, average purchase amount, and average review rating.
- **Interactive visuals & slicers**: Power BI presentation · Revenue, category, age, subscription, gender, and shipping exploration.

## Connections

- Customer shopping records → Cleaning & feature engineering: read source schema
- Cleaning & feature engineering → Analysis-ready records: clean and enrich
- Analysis-ready records → Customer analytics table: analyst loads · No ingestion script is stored in the repository.
- Customer analytics table → Business analysis queries: query
- Business analysis queries → Revenue & demographic segments: aggregate and segment
- Business analysis queries → Product & rating insights: rank and analyze
- Business analysis queries → Customer lifecycle segments: classify lifecycle
- Customer analytics table → Customer behaviour dashboard: connect or import
- Analysis-ready records → Customer behaviour dashboard: alternative import
- Customer behaviour dashboard → KPI measures: defines
- KPI measures → Interactive visuals & slicers: powers
- Revenue & demographic segments → Interactive visuals & slicers: informs decisions
- Product & rating insights → Interactive visuals & slicers: informs decisions
- Customer lifecycle segments → Interactive visuals & slicers: informs decisions
