Skip to content

DevPool1/e-commerce-Management-System-with-Oracle-Database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺ E-commerce Management System with Oracle Database

Python Oracle Streamlit License

A comprehensive e-commerce management system demonstrating advanced Oracle database concepts including tablespaces, partitioning, PL/SQL procedures, triggers, and materialized views, with a modern Streamlit web interface.

πŸ“‹ Table of Contents

Overview

This project implements a complete e-commerce management system focusing on:

  • Oracle Database Architecture with custom tablespaces, partitioning, and optimized indexes
  • PL/SQL Business Logic with generic CRUD procedures and error handling
  • Audit Mechanisms through triggers for complete operation tracking
  • Web Interface built with Streamlit for functional demonstration

The system is designed to showcase advanced database administration and programming concepts in Oracle.

Features

πŸ—„οΈ Database Layer

  • Custom Tablespaces: Separate storage for data (TBS_ALFATECH_DATA) and indexes (TBS_ALFATECH_IDX)
  • Automatic Sequences: Primary key generation for all entities
  • Strategic Indexes: Optimized query performance
  • Range Partitioning: Order table partitioned by date for efficient data management

βš™οΈ Business Logic

  • Generic CRUD Procedures: PR_GENERICO_INSERT, PR_GENERICO_UPDATE, PR_GENERICO_DELETE
  • Specific Business Procedures: Customer management, orders, payments, stock control
  • Exception Handling: Centralized error logging in LOG_ERROS table
  • External Tables: CSV data loading without disk space consumption
  • Materialized Views: Pre-computed reports for performance

πŸ“ Audit & Monitoring

  • DML Triggers: Automatic tracking of all INSERT/UPDATE/DELETE operations
  • Audit Table: Complete operation history with user and timestamp
  • Error Logging: Failed operation tracking for debugging
  • History Purge: Automated data archival process

πŸ–₯️ Web Interface

  • Dashboard: KPIs and aggregated data visualization
  • Customer Management: Full CRUD operations with validation
  • Order Processing: Multi-step transaction workflow
  • Product Reviews: Rating and comment system
  • Performance Demo: Index impact visualization with hints
  • Administration: Tablespace and partition management

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Streamlit Frontend                        β”‚
β”‚  (Dashboard | Customers | Orders | Reviews | Admin)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Python Layer                             β”‚
β”‚              (utils/db.py - Connection Pool)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Oracle Database 12c                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  PL/SQL     β”‚  β”‚  Triggers   β”‚  β”‚  Materialized Views β”‚  β”‚
β”‚  β”‚  Procedures β”‚  β”‚  (Audit)    β”‚  β”‚  (Reports)          β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚              Tables (Partitioned)                        β”‚β”‚
β”‚  β”‚  CLIENTE | PRODUTO | ENCOMENDA | PAGAMENTO | AUDITORIA  β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚         Tablespaces: TBS_ALFATECH_DATA | _IDX           β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

TP-CBD/
β”œβ”€β”€ app.py                      # Main Streamlit application
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ .gitignore                  # Git ignore rules
β”œβ”€β”€ LICENSE                     # MIT License
β”œβ”€β”€ README.md                   # This file
β”œβ”€β”€ CONTRIBUTING.md             # Contribution guidelines
β”‚
β”œβ”€β”€ .streamlit/
β”‚   └── secrets.toml.example    # Database configuration template
β”‚
β”œβ”€β”€ modules/                    # Application modules
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ dashboard.py            # KPIs and materialized views
β”‚   β”œβ”€β”€ clientes.py             # Customer CRUD operations
β”‚   β”œβ”€β”€ produtos.py             # Product and stock management
β”‚   β”œβ”€β”€ encomendas.py           # Order processing
β”‚   β”œβ”€β”€ financeiro.py           # Payments and invoices
β”‚   β”œβ”€β”€ auditoria.py            # Audit log visualization
β”‚   β”œβ”€β”€ performance.py          # Index performance demo
β”‚   β”œβ”€β”€ avaliacoes.py           # Product reviews
β”‚   └── avancado.py             # Data loading and administration
β”‚
β”œβ”€β”€ utils/
β”‚   └── db.py                   # Database connection utilities
β”‚
β”œβ”€β”€ scripts/                    # SQL scripts
β”‚   β”œβ”€β”€ hostshare/              # Main SQL scripts (execute in order)
β”‚   β”‚   β”œβ”€β”€ 01_structure_tablespaces.sql
β”‚   β”‚   β”œβ”€β”€ 02_structure_sequences.sql
β”‚   β”‚   β”œβ”€β”€ 03_structure_tables.sql
β”‚   β”‚   β”œβ”€β”€ ...
β”‚   β”‚   └── 25_app_generate_data.sql
β”‚   └── sql_loader/             # SQL*Loader control files
β”‚
β”œβ”€β”€ docs/                       # Additional documentation
β”‚
└── relatorio_e_imagens/        # Reports and diagrams
    └── Anexos/                 # ER diagrams and screenshots

Prerequisites

  • Python 3.8+
  • Oracle Database 12c or higher (local or remote)
  • Git (for cloning the repository)

Installation

1. Clone the Repository

git clone https://github.com/DevPool1/TP-CBD.git
cd TP-CBD

2. Create Virtual Environment (Recommended)

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Database Connection

cp .streamlit/secrets.toml.example .streamlit/secrets.toml

Edit .streamlit/secrets.toml with your Oracle credentials:

[oracle]
user = "YOUR_USERNAME"
password = "YOUR_PASSWORD"
dsn = "localhost:1521/orcl"

5. Execute SQL Scripts

Run the SQL scripts in numerical order using SQL*Plus or SQL Developer:

# Connect to Oracle as your user
sqlplus YOUR_USERNAME/YOUR_PASSWORD@localhost:1521/orcl

# Execute scripts in order
@scripts/hostshare/01_structure_tablespaces.sql
@scripts/hostshare/02_structure_sequences.sql
@scripts/hostshare/03_structure_tables.sql
# ... continue with remaining scripts

Script Categories:

Scripts Description
01-06 Database structure (tablespaces, tables, indexes)
07-09 Core functionality (error handling, generic CRUD)
10-16 Data loading (seed data, external tables)
17-22 Maintenance (partitioning, audit, purge)
23-25 Application support (views, specific procedures)

6. Run the Application

streamlit run app.py

The application will open automatically at http://localhost:8501

Configuration

Database Connection

The application uses Streamlit's secrets management. Create .streamlit/secrets.toml:

[oracle]
user = "BSCBD"
password = "your_secure_password"
dsn = "localhost:1521/orcl"

Environment Variables (Alternative)

You can also configure the connection using environment variables:

export ORACLE_USER=BSCBD
export ORACLE_PASSWORD=your_secure_password
export ORACLE_DSN=localhost:1521/orcl

Usage

Web Interface Navigation

  1. 🏠 Global View: Dashboard with KPIs and materialized views
  2. πŸ“‚ Data Loading: External tables and bulk data generation
  3. πŸ‘₯ CRUD & Errors: Customer management with error demonstration
  4. πŸ›’ Transactions: Order creation workflow
  5. ⭐ Reviews: Product rating system
  6. πŸ’° Financial: Payments and invoices
  7. πŸ“ Audit & Logs: Operation tracking
  8. ⚑ Performance: Index impact demonstration
  9. πŸ”§ Administration: System maintenance tools

Example Operations

Create a Customer

# The application calls the stored procedure
SP_CLIENTE_INSERT(p_nif, p_nome, p_email, p_password, p_telefone, p_data_nasc)

Generate Test Data

Navigate to "πŸ“‚ Data Loading" β†’ "🎲 Random Generation" and specify the quantity.

View Audit Trail

Navigate to "πŸ“ Audit & Logs" to see all recorded DML operations.

Database Schema

Core Entities

Table Description
CLIENTE Customer information
PRODUTO Product catalog
ENCOMENDA Order headers (partitioned by date)
LINHA_ENCOMENDA Order line items
PAGAMENTO Payment records
FATURA Invoice documents
AVALIACAO Product reviews
AUDITORIA Audit trail
LOG_ERROS Error logging

ER Diagram

See relatorio_e_imagens/Anexos/diagrama_modelo.png for the complete entity-relationship diagram.

API Documentation

Database Utilities (utils/db.py)

# Execute SELECT query
df = run_query("SELECT * FROM CLIENTE")

# Call stored procedure
success, message = run_proc("SP_CLIENTE_INSERT", [nif, nome, email, pwd, tel, data])

Stored Procedures

Procedure Parameters Description
SP_CLIENTE_INSERT nif, nome, email, password, telefone, data_nasc Create customer
SP_CLIENTE_UPDATE id, nome, email, telefone, ativo Update customer
SP_CLIENTE_DELETE id Remove customer
SP_ENCOMENDA_INSERT cliente_id, tipo, morada_id, loja_id, endereco_fat_id Create order
SP_EXPURGAR_HISTORICO data_corte Archive old orders
PR_GENERICO_INSERT tabela, colunas, valores Generic insert

Testing

Manual Testing

  1. CRUD Operations: Create, edit, and delete customers
  2. Audit Verification: Check AUDITORIA table after operations
  3. Error Handling: Try duplicate NIF to see error in LOG_ERROS
  4. Performance: Compare query times with and without indexes
  5. Data Generation: Generate bulk orders and verify

Validation Queries

-- Check audit records
SELECT * FROM AUDITORIA ORDER BY DATA_AUDITORIA DESC;

-- View error logs
SELECT * FROM LOG_ERROS ORDER BY ID_LOG DESC;

-- Partition statistics
SELECT PARTITION_NAME, NUM_ROWS 
FROM USER_TAB_PARTITIONS 
WHERE TABLE_NAME='ENCOMENDA';

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Quick Start for Contributors

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Authors

Group 3 - Complementos de Base de Dados (CBD)

  • Alexandru Tutunaru
  • AndrΓ© Nunes
  • Cosmin Ciocan
  • Firmino Santos

Institution: Universidade do Algarve

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments


Note: This project was developed as part of the "Complementos de Base de Dados" course to demonstrate advanced database concepts and their practical application in a real-world scenario.

About

Trabalho pratico referente a unidade curricular Complemento de Base de Dados

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors