Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ E-Commerce Database Management Dashboard

Modern web dashboard for MySQL e-commerce databases with Role-Based Access Control, CRUD operations, database views, and real-time analytics.

Built with Database Python


🌟 Overview

Complete web-based interface for managing MySQL e-commerce databases with enterprise-grade security and intuitive operations.

Key Features:

  • Role-Based Access Control - 6 user roles with specific permissions
  • CRUD Operations - Create, Read, Update, Delete with smart forms
  • Database Views - Access role-specific views with search and export
  • Audit Trails - Track all changes with who, what, when
  • Interactive Visualizations - Real-time charts powered by Plotly
  • Security - SQL injection prevention, data masking, security logs

Perfect for: Database administrators, developers, business analysts, and students.


πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • MySQL Server 8.0+

Installation

# 1. Clone/Download the project
git clone <repository-url>
cd new_database_project

# 2. Configure database connection
# Copy .env.example to .env and update with your credentials
cp .env.example .env
# Edit .env with your MySQL credentials

# 3. Install and run
pip install -r requirements.txt
streamlit run app.py

Windows users: Double-click run_dashboard.bat

Dashboard opens at: http://localhost:8501 πŸŽ‰


✨ Main Features

1. πŸ” Role-Based Access Control

Login with different roles to access role-specific features:

Role Username Access
Administrator admin_user Full access + audit trails + security logs
Sales Manager sales_manager Customers, orders, sales view
Customer Service customer_service Customer data, returns, service view
Warehouse Staff warehouse_staff Products, inventory, suppliers
Marketing Team marketing_team Analytics view, customer insights
Delivery Coordinator delivery_coordinator Deliveries, active delivery view

2. πŸ“‹ CRUD Operations

Features:

  • Auto-generated smart forms (date pickers, dropdowns, number inputs)
  • Primary key protection (auto-increment, read-only)
  • CHECK constraint validation
  • Foreign key awareness
  • Confirmation dialogs for deletions

3. πŸ‘οΈ View Data Mode (NEW)

Access role-specific database views:

  • Browse pre-filtered, pre-joined data
  • Search and filter by any column
  • View numeric statistics
  • Export to CSV with timestamps
  • Views include: OrderSummaryView, CustomerServiceView, ReturnManagementView, MarketingAnalyticsView, ActiveDeliveryView

4. πŸ”’ Audit Trails & Security Logs (Admin Only)

Quick Access Panel for:

  • customer_audit - Track customer changes
  • card_audit - Monitor payment card updates
  • product_audit - Product modifications
  • orders_audit - Order changes
  • payment_audit - Payment modifications
  • security_log - Security events and access attempts

Each log captures: User, action, old/new values, timestamp

5. πŸ“Š Visualizations

8 Interactive Charts:

  • Customer Age Distribution
  • Customer Growth Over Time
  • Customer Account Status
  • Product Sales Analysis
  • Product Stock Status
  • Order Amount Distribution
  • Order Status Overview
  • Payment Status Breakdown

Features: Hover details, zoom, pan, download


πŸ“š Setup Guide

1. Create Database

mysql -u root -p
CREATE DATABASE ecommerce_db;
exit

# Import schema
mysql -u root -p ecommerce_db < normal_Schema_MySQL.sql

# Insert sample data (optional)
mysql -u root -p ecommerce_db < normal_insert.sql

2. Enable Security Features

# Create user accounts
mysql -u root -p ecommerce_db < security/userAccountCreation.sql

# Grant privileges
mysql -u root -p ecommerce_db < security/GrantPrivilages.sql

# Create audit tables
mysql -u root -p ecommerce_db < security/AuditTrailTables.sql

# Enable triggers
mysql -u root -p ecommerce_db < security/Trigers.sql

# Create views
mysql -u root -p ecommerce_db < security/ViewAccessControl.sql
mysql -u root -p ecommerce_db < security/DataMaskingView.sql
mysql -u root -p ecommerce_db < security/SecurityLog.sql

3. Login

Use the credentials you set in security/userAccountCreation.sql. Default usernames are:

Admin: admin_user
Sales: sales_manager
CS: customer_service
Warehouse: warehouse_staff
Marketing: marketing_team
Delivery: delivery_coordinator

Note: Change the default passwords in security/userAccountCreation.sql before running it in production!


🎯 Usage

CRUD Operations

  1. Select CRUD Operations mode
  2. Choose table from dropdown (or use Quick Access for audit tables)
  3. Select operation: Create, Read, Update, or Delete
  4. Complete the form/action

View Data (NEW)

  1. Select View Data mode
  2. Choose a view from dropdown (only shows views you can access)
  3. Search/filter data
  4. Export to CSV if needed

Visualizations

  1. Select Visualizations mode
  2. Choose chart from dropdown (based on role permissions)
  3. Interact with charts (hover, zoom, download)

πŸ“ Project Structure

new_database_project/
β”œβ”€β”€ app.py                          # Main dashboard (1088 lines)
β”œβ”€β”€ requirements.txt                # Dependencies
β”œβ”€β”€ run_dashboard.bat              # Windows launcher
β”‚
β”œβ”€β”€ πŸ“– Documentation
β”‚   β”œβ”€β”€ README.md                  # This file
β”‚   β”œβ”€β”€ README_DASHBOARD.md        # Dashboard-specific docs
β”‚   β”œβ”€β”€ VIEW_ACCESS_GUIDE.md       # View data mode guide
β”‚   β”œβ”€β”€ AUDIT_TRAIL_GUIDE.md       # Audit trails guide
β”‚   └── Database_Security_Implementation_Report.md
β”‚
β”œβ”€β”€ security/                      # Security implementation
β”‚   β”œβ”€β”€ userAccountCreation.sql    # User roles
β”‚   β”œβ”€β”€ GrantPrivilages.sql        # Permissions
β”‚   β”œβ”€β”€ ViewAccessControl.sql      # Role-specific views
β”‚   β”œβ”€β”€ AuditTrailTables.sql       # Audit tables
β”‚   β”œβ”€β”€ Trigers.sql                # Auto-audit triggers
β”‚   β”œβ”€β”€ DataMaskingView.sql        # Sensitive data masking
β”‚   └── SecurityLog.sql            # Security event log
β”‚
β”œβ”€β”€ UserRoleTests/                 # Test scripts
β”‚   └── *RoleTest.sql              # SQL tests for each role
β”‚
β”œβ”€β”€ normal_Schema_MySQL.sql        # Database schema
└── normal_insert.sql              # Sample data

πŸ›‘οΈ Security Features

SQL Injection Prevention

  • All queries use parameterized statements (:placeholder format)
  • Password URL encoding for special characters
  • Input validation on all forms

Role-Based Access Control (RBAC)

  • 6 user roles with specific table/view permissions
  • Operations restricted by role (create/read/update/delete)
  • Visualizations filtered by role

Audit Trail System

  • Automatic logging of all data modifications
  • Captures: User, action (INSERT/UPDATE/DELETE), old/new values, timestamp
  • Triggered automatically via MySQL triggers

Data Masking

  • Credit cards: ****-****-****-1234
  • Emails: j***@example.com
  • Phone: ***-***-5678

Security Event Logging

  • Failed login attempts
  • Permission denials
  • Suspicious activity
  • Admin-only access

πŸ› Troubleshooting

Issue Solution
Can't connect to MySQL Check MySQL is running: services.msc (Windows)
Access denied Verify credentials in .env file
Unknown database Create database: CREATE DATABASE ecommerce_db;
No tables found Import schema: mysql ... < normal_Schema_MySQL.sql
No views for role The views are lowercase (e.g., activedeliveryview)
Audit tables not visible Click dropdown and scroll to find *_audit tables
Foreign key constraint Create parent record first (e.g., customer before order)

Clear cache: Press C in browser or restart dashboard


πŸ“Š Technical Details

Dependencies

streamlit>=1.28.0     # Web framework
pandas>=2.0.0         # Data manipulation
plotly>=5.17.0        # Visualizations
sqlalchemy>=2.0.0     # Database ORM
pymysql>=1.1.0        # MySQL driver

Architecture

  • Cached database connections (@st.cache_resource)
  • SQLAlchemy connection pooling
  • Parameterized queries for security
  • Auto-schema detection
  • Responsive wide layout

πŸ”„ Recent Updates (v2.0)

  • βœ… View Data Mode - Access role-specific database views with search/export
  • βœ… Audit Trail Access - Admin quick access panel for audit tables
  • βœ… Security Logs - Comprehensive security event tracking
  • βœ… Improved RBAC - Table and view permissions per role
  • βœ… View Names - Fixed lowercase view name handling
  • βœ… Documentation - Added VIEW_ACCESS_GUIDE.md and AUDIT_TRAIL_GUIDE.md

πŸ“– Additional Documentation


🎨 Customization

Connect to Different Database

Update the .env file:

MYSQL_HOST=your-host
MYSQL_PORT=3306
MYSQL_USER=your-username
MYSQL_PASSWORD=your-password
MYSQL_DATABASE=your-database

Dashboard auto-detects tables, columns, and generates forms!


πŸ†˜ Support

Error messages include hints! Also check:

  1. Troubleshooting section above
  2. VIEW_ACCESS_GUIDE.md
  3. AUDIT_TRAIL_GUIDE.md
  4. Error logs in MySQL

πŸ“ License

Created for educational purposes. Free to use and modify.


πŸ›’ E-Commerce Database Management Dashboard v2.0

Built with ❀️ using Streamlit, SQLAlchemy, and MySQL

Quick Start β€’ Features β€’ Setup β€’ Documentation


Ready to manage your database? πŸš€

Run: run_dashboard.bat or streamlit run app.py

Login as: admin_user (with password from userAccountCreation.sql)

About

MySQL e-commerce database with role-based access control and Streamlit analytics dashboard

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages