Skip to content

jdatjedd/Retail-intelligence-pipeline

Repository files navigation

B2B Omnichannel Retail Intelligence Pipeline

A comprehensive retail intelligence system that simulates modern enterprise ERP capabilities. This project demonstrates dimensional modeling, relational database design, ETL processing, and interactive business analytics.

📋 Overview

This pipeline integrates transactional data from three channels:

  • Brick-and-Mortar POS: In-store sales transactions
  • Shopify: E-commerce web sales
  • Amazon: Marketplace sales

The system standardizes multi-source data, loads it into an optimized SQL database, and provides real-time operational insights through an interactive dashboard.

🎯 Key Features

Data Generation

  • Realistic mock data across 3 retail channels
  • Intentional anomalies (mixed date formats, currencies, duplicates) to simulate real-world scenarios
  • ~5,000+ transactions across 90 days

ETL Pipeline

  • Multi-source data extraction
  • Data standardization and normalization
  • Quality validation and deduplication
  • Unified fact table creation

Database Design

  • Star schema with optimized dimensional modeling
  • Fact table: sales_transactions
  • Dimension tables: products, dates, stores, channels
  • Strategic indexing for fast query performance

Streamlit Dashboard

  • Real-time operational KPIs
  • Channel performance analytics
  • Revenue trends and forecasting
  • Inventory alerts (configurable threshold)
  • Interactive filters and drill-downs

🛠️ Tech Stack

  • Python 3.8+ — Data processing with Pandas
  • PostgreSQL/SQLite — Relational database
  • SQLAlchemy — ORM for database operations
  • Streamlit — Interactive dashboard framework
  • Faker — Realistic mock data generation

📁 Project Structure

├── data/
│   ├── raw/              # Generated mock data (CSVs)
│   ├── processed/        # Transformed data
│   └── schemas/          # SQL schema definitions
├── scripts/
│   ├── generate_mock_data.py    # Data generation
│   ├── etl_pipeline.py          # ETL logic
│   └── db_setup.py              # Database initialization
├── dashboard/
│   └── app.py                   # Streamlit dashboard
├── config.py              # Configuration settings
├── requirements.txt       # Python dependencies
├── .env.example           # Environment variables template
└── README.md             # This file

🚀 Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip or conda

Installation

  1. Clone the repository
git clone https://github.com/yourusername/Retail-intelligence-pipeline.git
cd Retail-intelligence-pipeline
  1. Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Configure environment
cp .env.example .env
# Edit .env to configure database settings (optional for SQLite)

Running the Pipeline

Step 1: Generate Mock Data

python scripts/generate_mock_data.py

This creates three CSV files in data/raw/:

  • pos_raw.csv
  • shopify_raw.csv
  • amazon_raw.csv

Step 2: Setup Database

python scripts/db_setup.py

Creates optimized tables with proper indexing in your configured database.

Step 3: Run ETL Pipeline

python scripts/etl_pipeline.py

Transforms raw data and loads it into the database.

Step 4: Launch Dashboard

streamlit run dashboard/app.py

Opens interactive dashboard at http://localhost:8501

📊 Database Schema

Fact Table: sales_transactions

Column Type Description
transaction_id INTEGER Primary Key
channel_id INTEGER Foreign Key → dim_channels
product_id INTEGER Foreign Key → dim_products
date_id INTEGER Foreign Key → dim_dates
store_id INTEGER Foreign Key → dim_stores
quantity INTEGER Units sold
unit_price DECIMAL Price per unit
total_amount DECIMAL Total transaction value
order_status VARCHAR Completed/Cancelled/Refunded

Dimension Tables

  • dim_channels: channel_id, channel_name
  • dim_products: product_id, sku, product_name, category
  • dim_dates: date_id, date, year, month, quarter
  • dim_stores: store_id, store_name, location, channel_id

Key Indexes

  • Composite index on (channel_id, date_id) for fast aggregations
  • Index on product_id for inventory lookups
  • Index on order_status for filtering

🎨 Dashboard Features

KPI Cards

  • Total Revenue (by channel)
  • Transaction Count
  • Average Order Value
  • Inventory Alerts Count

Visualizations

  • Channel Mix: Revenue distribution pie chart
  • Daily Trend: Line chart of revenue over time
  • Cancellation Rate: Bar chart by channel
  • Top Products: Table of best sellers
  • Inventory Alerts: Products below threshold

Filters

  • Date range selector
  • Channel filter
  • Adjustable inventory threshold

🔄 ETL Workflow

RAW DATA (3 Channels)
    ↓
EXTRACT: Load CSV files
    ↓
TRANSFORM:
    • Standardize date formats (YYYY-MM-DD)
    • Normalize product IDs (all → SKU format)
    • Convert currencies (→ base currency)
    • Handle nulls and duplicates
    • Validate data types
    ↓
LOAD: Insert into SQL database
    ↓
UNIFIED DATA SOURCE
    ↓
DASHBOARD: Real-time analytics

📈 What This Demonstrates

Dimensional Modeling — Properly designed star schema
Relational Database Design — Normalized tables with referential integrity
ETL Best Practices — Robust data pipeline with validation
Data Consistency — Multi-source standardization
Responsive Frontend — Interactive Streamlit dashboard
Enterprise Architecture — Scalable, maintainable codebase

🔧 Configuration

Edit config.py to customize:

# Mock Data
NUM_TRANSACTIONS_POS = 2000
NUM_TRANSACTIONS_SHOPIFY = 1500
NUM_TRANSACTIONS_AMAZON = 1800
DATE_RANGE_DAYS = 90

# Inventory Settings
INVENTORY_THRESHOLD = 50

# Database
DATABASE_URL = "sqlite:///./data/retail_intelligence.db"

📝 Database Configuration

SQLite (Default)

No configuration needed. Database file stored at data/retail_intelligence.db

PostgreSQL

Update .env:

DB_TYPE=postgresql
DB_USER=postgres
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=retail_intelligence

🐛 Troubleshooting

Error: Module not found

pip install -r requirements.txt

Error: Database connection failed

  • Verify PostgreSQL is running (if using PostgreSQL)
  • Check .env credentials
  • For SQLite, ensure data/ directory exists

Dashboard not loading

streamlit run dashboard/app.py --logger.level=debug

🚀 Future Enhancements

  • Real-time data ingestion from live APIs
  • Predictive analytics (demand forecasting)
  • Automated data quality reporting
  • Multi-warehouse support
  • Cloud deployment (AWS/Azure)
  • Advanced filtering and drill-down capabilities
  • Export functionality (PDF, Excel)

📚 Learning Resources

📄 License

See LICENSE file for details.

👤 Author

Your Name — jdatjedd

📞 Support

For issues or questions, please open a GitHub issue or contact the maintainer.


Last Updated: July 2026
Status: Development (Phase 1.1 Complete)

About

this visulizes retail pipeline

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors