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.
- Overview
- Features
- Architecture
- Project Structure
- Prerequisites
- Installation
- Configuration
- Usage
- Database Schema
- API Documentation
- Testing
- Contributing
- Authors
- License
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.
- 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
- 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_ERROStable - External Tables: CSV data loading without disk space consumption
- Materialized Views: Pre-computed reports for performance
- 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
- 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
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 ββ
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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
- Python 3.8+
- Oracle Database 12c or higher (local or remote)
- Git (for cloning the repository)
git clone https://github.com/DevPool1/TP-CBD.git
cd TP-CBDpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtcp .streamlit/secrets.toml.example .streamlit/secrets.tomlEdit .streamlit/secrets.toml with your Oracle credentials:
[oracle]
user = "YOUR_USERNAME"
password = "YOUR_PASSWORD"
dsn = "localhost:1521/orcl"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 scriptsScript 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) |
streamlit run app.pyThe application will open automatically at http://localhost:8501
The application uses Streamlit's secrets management. Create .streamlit/secrets.toml:
[oracle]
user = "BSCBD"
password = "your_secure_password"
dsn = "localhost:1521/orcl"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- π Global View: Dashboard with KPIs and materialized views
- π Data Loading: External tables and bulk data generation
- π₯ CRUD & Errors: Customer management with error demonstration
- π Transactions: Order creation workflow
- β Reviews: Product rating system
- π° Financial: Payments and invoices
- π Audit & Logs: Operation tracking
- β‘ Performance: Index impact demonstration
- π§ Administration: System maintenance tools
# The application calls the stored procedure
SP_CLIENTE_INSERT(p_nif, p_nome, p_email, p_password, p_telefone, p_data_nasc)Navigate to "π Data Loading" β "π² Random Generation" and specify the quantity.
Navigate to "π Audit & Logs" to see all recorded DML operations.
| 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 |
See relatorio_e_imagens/Anexos/diagrama_modelo.png for the complete entity-relationship diagram.
# 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])| 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 |
- CRUD Operations: Create, edit, and delete customers
- Audit Verification: Check
AUDITORIAtable after operations - Error Handling: Try duplicate NIF to see error in
LOG_ERROS - Performance: Compare query times with and without indexes
- Data Generation: Generate bulk orders and verify
-- 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';We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Group 3 - Complementos de Base de Dados (CBD)
- Alexandru Tutunaru
- AndrΓ© Nunes
- Cosmin Ciocan
- Firmino Santos
Institution: Universidade do Algarve
This project is licensed under the MIT License - see the LICENSE file for details.
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.