Skip to content

AuliaNurArkan/Python-MySQL-Car-Rental

Repository files navigation

Car Rental Data Engine & Management System

Language: English | Bahasa Indonesia


🇬🇧 English Version

📌 Project Description

This application is a Python-based backend system and data engine integrated directly with a MySQL relational database. Built with a strong focus on Defensive Programming and Database Automation, the system dynamically handles full CRUD (Create, Read, Update, Delete) operations while ensuring automated schema adjustments and strict data sanitization to prevent runtime failures in a production environment.

As a foundational portfolio project for the AI Engineer track, this system focuses on building a clean, structured operational data pipeline—a critical engineering skill required before moving into advanced data manipulation, feature engineering, or Machine Learning modeling.


🚀 Key Features & Engineering Highlights

  1. Automated Schema Tuning & Initialization

    • Upon application startup, the system automatically verifies database readiness and table availability.
    • Features automated DDL (ALTER TABLE) execution that programmatically checks if the primary key rental_id is configured with AUTO_INCREMENT. If not, it self-heals the table structure via backend scripts to guarantee smooth data ingestion.
  2. Modular & Clean Architecture (Separation of Concerns)

    • Business logic is decoupled into atomic, reusable regular functions (e.g., connection helper, table rendering, data manipulation modules).
    • This modular design ensures that the code remains clean, maintainable, and easily scalable for future migrations to larger backend frameworks or web-based analytical dashboards.
  3. Robust Data Sanitization & Integrity (Defensive Programming)

    • Input Protection: Utilizes .strip() methods to sanitize user inputs, preventing accidental whitespaces or trailing lines from corrupting SQL queries.
    • Multi-Layer Validation: Prevents application crashes by enforcing strict type validation before hitting the MySQL database:
      • Enforces positive integer validation via .isdigit() for rental durations.
      • Adaptively sanitizes floating-point inputs (handling both comma , and dot . formats) for rental costs.
      • Validates temporal dimensions using exception handling from the datetime library to ensure inputs strictly comply with the standard YYYY-MM-DD format.
  4. Explanatory Business Analytics & Visualizations

    • Descriptive Statistics Summary: Instantly computes comprehensive summary statistics (mean, categorical frequency, value distribution) directly from the database to support data-driven decisions.
    • Interactive Visualization Engine: Integrates Pandas, Matplotlib, and Seaborn to transform raw transactional data into 5 core business insights:
      • Pie Chart: Best-selling vehicle proportions for inventory analysis.
      • Bar Plot: Transaction volumes per branch city to measure regional performance.
      • Histogram: Rental cost distribution to analyze customer purchasing power.
      • Scatter Plot: Correlation analysis between rental duration and total revenue.
      • Line Plot: Accumulated daily revenue trends for basic financial forecasting.
  5. Advanced CRUD Operations & State Persistence

    • Enables dynamic records management natively synced with the relational database.
    • Features a built-in data export module that allows the entire transactional record in MySQL to be instantly backed up into an external .csv file for external data auditing.

📁 Repository Structure

  • app_rental.py: The main application containing all business logic, database configurations, inputs validation, and the analytical visualization interface.
  • requirements.txt: List of external Python library dependencies required to run the application.
  • moduleone.sql & SQL_Query.sql: SQL initialization scripts to spin up the schema, set up tables, and execute relation queries.
  • car_rental.csv: Backup data storage file generated directly by the system's export feature.
  • create_rental_data.py: Utility script to seed dummy/synthetic data into the database for testing.

🛠️ Tech Stack

  • Language: Python 3.x
  • Database: MySQL (Relational Database Management System)
  • Data Processing: Pandas
  • Data Visualization: Matplotlib & Seaborn
  • Database Connector: mysql-connector-python

📊 Database Schema

The system manages a database named moduleone containing the car_rental table with the following architecture:

Column Name Data Type Description
rental_id INT (PK, Auto Increment) Unique transaction identifier.
car_type VARCHAR / TEXT Type/category of the rented vehicle.
rental_duration INT Rental duration in days.
rental_cost FLOAT / DOUBLE Total cost charged for the rental.
customer_gender VARCHAR / TEXT Customer's gender.
rental_date DATE Date of transaction (YYYY-MM-DD).
branch_city VARCHAR / TEXT Branch city where the rental occurred.

🚀 Setup & Installation

  1. Clone the Repository:
    git clone [https://github.com/your_username/your_repository_name.git](https://github.com/your_username/your_repository_name.git)
    cd your_repository_name
  2. Install Dependencies:
    pip install -r requirements.txt
  3. Database Configuration:
    • Run/import moduleone.sql inside your local MySQL instance.
    • Open app_rental.py and modify your MySQL connection parameters:
      HOST = "localhost"
      USER = "your_mysql_user"
      PASSWORD = "your_mysql_password"
      DATABASE = "moduleone"
  4. Run the Application:
    python app_rental.py

🎓 Educational Context

This independent project was developed as a Capstone Project Module 1 in the AI Engineer Job Connector program at Purwadhika Digital Technology School. It validates core competencies in relational database integration, structured modular programming, and descriptive analytical reporting prior to entering advanced feature engineering and machine learning phases.



🇮🇩 Versi Bahasa Indonesia

📌 Deskripsi Proyek

Aplikasi ini merupakan sistem backend dan mesin pengolahan data (data engine) berbasis Python yang terintegrasi langsung dengan database relasional MySQL. Dirancang dengan mengedepankan pendekatan Defensive Programming dan Database Automation, sistem ini tidak hanya menangani operasi CRUD (Create, Read, Update, Delete) secara dinamis, tetapi juga memastikan otomatisasi skema dan sanitasi data yang ketat untuk mencegah kegagalan sistem di lingkungan produksi.

Sebagai proyek portofolio awal untuk penjaluran AI Engineer, sistem ini berfokus pada pembangunan data pipeline operasional yang bersih dan terstruktur—sebuah kompetensi fundamental yang wajib dikuasai sebelum melakukan manipulasi data tingkat lanjut atau pemodelan Machine Learning.


🚀 Fitur Utama & Keunggulan Teknis

  1. Automated Schema Tuning & Initialization

    • Saat program pertama kali dijalankan, sistem secara otomatis memeriksa kesiapan database dan struktur tabel.
    • Dilengkapi fitur otomatisasi DDL (ALTER TABLE) yang akan mendeteksi apakah kolom unik rental_id sudah bertipe AUTO_INCREMENT atau belum. Jika belum, sistem akan memperbaikinya secara otomatis lewat backend script untuk menjamin kelancaran penambahan data baru.
  2. Modular & Clean Architecture (Separation of Concerns)

    • Seluruh logika bisnis diisolasi ke dalam regular functions yang spesifik (seperti fungsi koneksi, fungsi render tabel, hingga modul manipulasi data).
    • Pendekatan modular ini menjamin kode tetap bersih (clean code), mudah dirawat (maintainable), serta scalable jika nantinya ingin dimigrasikan ke framework backend atau dashboard analitis yang lebih besar.
  3. Robust Data Sanitization & Integrity (Defensive Programming)

    • Proteksi Input: Menggunakan metode .strip() untuk membersihkan spasi tidak disengaja atau karakter newline yang sering merusak struktur query SQL.
    • Validasi Berlapis: Mencegah system crash melalui pengecekan tipe data yang ketat sebelum data dikirim ke MySQL, meliputi:
      • Validasi bilangan bulat positif menggunakan .isdigit() untuk durasi sewa.
      • Konversi adaptif karakter desimal (mengubah koma , menjadi titik .) pada input biaya sewa.
      • Verifikasi format temporal menggunakan error-catching dari library datetime untuk memastikan input tanggal selalu patuh pada standar YYYY-MM-DD.
  4. Explanatory Business Analytics & Visual Visualizations

    • Ringkasan Statistik Deskriptif: Menyajikan kalkulasi statistik menyeluruh (termasuk distribusi nilai, mean, frekuensi kategori) dari database secara instan untuk mendukung pengambilan keputusan berbasis data.
    • Engine Visualisasi Interaktif: Mengintegrasikan library Pandas, Matplotlib, dan Seaborn untuk memetakan data transaksional menjadi 5 visualisasi bisnis utama:
      • Pie Chart: Proporsi jenis kendaraan terlaris untuk analisis inventaris.
      • Bar Plot: Tren volume transaksi per cabang kota untuk melihat performa regional.
      • Histogram: Distribusi biaya rental guna memahami segmentasi daya beli pelanggan.
      • Scatter Plot: Analisis korelasi antara durasi sewa terhadap total biaya.
      • Line Plot: Tren akumulasi pendapatan harian untuk keperluan forecasting finansial.
  5. Advanced CRUD Operations & State Persistence

    • Manajemen data rental mobil secara dinamis langsung terintegrasi dengan database relasional.
    • Fitur ekspor data terintegrasi yang memungkinkan seluruh rekaman data transaksi dalam database MySQL diekspor secara instan ke dalam format berkas .csv untuk keperluan audit data eksternal.

📁 Struktur Berkas Proyek

  • app_rental.py: Aplikasi utama yang berisi seluruh logika bisnis, pengelolaan database, validasi input, dan menu visualisasi.
  • requirements.txt: Daftar dependensi library Python yang dibutuhkan untuk menjalankan sistem.
  • moduleone.sql & SQL_Query.sql: Berkas skrip SQL untuk menginisialisasi skema database dan tabel.
  • car_rental.csv: Berkas penyimpanan data cadangan (backup) hasil ekspor langsung dari sistem.
  • create_rental_data.py: Skrip utilitas untuk membuat data tiruan (dummy) ke dalam database.

🛠️ Tech Stack yang Digunakan

  • Language: Python 3.x
  • Database: MySQL (Relational Database Management System)
  • Data Processing: Pandas
  • Data Visualization: Matplotlib & Seaborn
  • Database Connector: mysql-connector-python

📊 Arsitektur & Skema Database

Sistem ini mengelola basis data bernama moduleone dengan tabel utama car_rental:

Nama Kolom Tipe Data Deskripsi
rental_id INT (PK, Auto Increment) Kunci unik pengidentifikasi transaksi.
car_type VARCHAR / TEXT Jenis atau kategori mobil yang disewa.
rental_duration INT Durasi penyewaan dalam satuan hari.
rental_cost FLOAT / DOUBLE Total biaya sewa yang dikenakan.
customer_gender VARCHAR / TEXT Jenis kelamin pelanggan.
rental_date DATE Tanggal pelaksanaan rental (YYYY-MM-DD).
branch_city VARCHAR / TEXT Lokasi kota cabang tempat rental terjadi.

🚀 Cara Instalasi & Menjalankan Aplikasi

  1. Kloning Repositori:
    git clone [https://github.com/username_anda/nama_repositori_anda.git](https://github.com/username_anda/nama_repositori_anda.git)
    cd nama_repositori_anda
  2. Instalasi Dependensi:
    pip install -r requirements.txt
  3. Konfigurasi Database:
    • Impor berkas moduleone.sql ke MySQL Server lokal Anda.
    • Sesuaikan kredensial database di dalam berkas app_rental.py:
      HOST = "localhost"
      USER = "username_mysql_anda"
      PASSWORD = "password_mysql_anda"
      DATABASE = "moduleone"
  4. Jalankan Aplikasi:
    python app_rental.py

🎓 Konteks Pendidikan

Proyek mandiri ini dikembangkan sebagai bagian dari tugas Capstone Project Module 1 dalam program AI Engineer Job Connector di Purwadhika Digital Technology School. Proyek ini merepresentasikan pemahaman mendalam mengenai penanganan database relasional, pemrograman modular terstruktur, serta analisis deskriptif data transaksional sebelum melangkah ke fase rekayasa fitur (feature engineering) untuk AI modeling.

About

A robust Python-MySQL backend and data analytics engine for a Car Rental Management System, featuring automated database schema tuning and dynamic descriptive reporting.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages