{"id":15289148,"url":"https://github.com/al-ghaly/ruleengineusingscala","last_synced_at":"2026-05-01T10:32:30.438Z","repository":{"id":239470018,"uuid":"796932755","full_name":"al-ghaly/RuleEngineUsingScala","owner":"al-ghaly","description":"A Rule-Based discount calculating engine for a retail store. The engine reads transaction data, applies various discount rules based on the product, date, and other criteria, and writes the results back to a database.","archived":false,"fork":false,"pushed_at":"2024-05-13T09:05:16.000Z","size":265,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T12:22:35.377Z","etag":null,"topics":["database","etl","etl-automation","functional-programming","jdbc","oracle","programming","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/al-ghaly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-06T22:22:52.000Z","updated_at":"2024-05-13T09:05:19.000Z","dependencies_parsed_at":"2024-10-14T20:00:41.403Z","dependency_job_id":"13c30095-6105-4f13-99bc-f2d830abfd24","html_url":"https://github.com/al-ghaly/RuleEngineUsingScala","commit_stats":null,"previous_names":["al-ghaly/ruleengineusingscala"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/al-ghaly%2FRuleEngineUsingScala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/al-ghaly%2FRuleEngineUsingScala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/al-ghaly%2FRuleEngineUsingScala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/al-ghaly%2FRuleEngineUsingScala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/al-ghaly","download_url":"https://codeload.github.com/al-ghaly/RuleEngineUsingScala/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245223857,"owners_count":20580361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","etl","etl-automation","functional-programming","jdbc","oracle","programming","scala"],"created_at":"2024-09-30T15:59:24.513Z","updated_at":"2026-05-01T10:32:30.305Z","avatar_url":"https://github.com/al-ghaly.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scala ETL Rule Engine\n\n## Project Overview\n\nThis project is a Scala-based ETL (Extract, Transform, Load) application designed as a rule-based discount calculating engine for a large retail company. The engine reads transaction data from a CSV file, processes each transaction according to predefined rules to calculate discounts, and loads the processed data into an Oracle database for further analysis and reporting.\n\n### Project Requirements\n\n1. **Qualifying Rules and Calculation:**\n   - Discounts based on product expiry, with a tiered discount system depending on how close the product is to its expiration date.\n   - Special discounts for cheese and wine products.\n   - A 50% discount for products sold on the 23rd of March.\n   - Quantity-based discounts, encouraging bulk purchases.\n   - Additional discounts for transactions made through the app and payments made using Visa cards.\n\n2. **Technical Considerations:**\n   - All core logic must be written in a pure functional manner:\n     - Use only `vals`, no `vars`.\n     - Avoid mutable data structures.\n     - Exclude loops; instead, use recursion or higher-order functions.\n     - Ensure all functions are pure; they should not produce side effects.\n   - The application logs events in a specific format and writes them to `rules_engine.log`.\n\n3. **Logging Format:**\n   ```\n   TIMESTAMP     LOGLEVEL      MESSAGE\n   ```\n\n4. **Technical Specifications:**\n   - Scala and a JVM-compatible environment for execution.\n   - Oracle Database for data persistence.\n   - Proper error handling and logging of operations.\n\n## Technology Stack\n\n- **Scala** for the backend logic.\n- **Oracle Database** for storing processed transactions.\n- **SBT** for project build and dependency management.\n\n## Features\n\n- **Dynamic Discount Calculation:** Applies various discounts based on product expiry, sales category (cheese, wine), special sale dates, quantity, application usage, and Visa payments.\n- **Functional Programming:** Adheres strictly to functional programming principles with immutable data structures and pure functions, ensuring predictable and side-effect-free operations.\n- **Comprehensive Logging:** Logs detailed operational data to a file, which helps in monitoring and troubleshooting the application.\n\n\n\n## Flow Chart\n\nThe following flow chart visualizes the sequence of operations from data input to processing and output:\n\n![FlowChart](https://github.com/al-ghaly/RuleEngineUsingScala/assets/61648960/492e9da6-7cae-4729-bb95-abaaeacef2cc)\n\n\n## Technical Details\n\n### Code Structure\n\n- **Transaction Processing**: Each transaction is parsed and processed through various discount rules.\n- **Discount Qualification**: Discounts are determined based on set rules, including product type, expiry, special dates, and quantity thresholds.\n- **Database Operations**: After calculating discounts, the transaction data, along with computed discounts, are stored in a database.\n- **Logging**: Events and errors are logged in a file, following a specific format that includes a timestamp, log level, and message.\n\n### Key Components\n\n- **Transaction Classes**: Define the structure for transaction data and processed transaction data.\n- **Rule Functions**: A set of functions that determine the eligibility for discounts based on different criteria.\n- **Data Handling**: Functions to read from and write to CSV files and the Oracle database.\n- **Logger Utility**: A utility to handle logging across the system uniformly.\n\n### Core Functionality\n\n- **Read Data:** The engine starts by reading transaction data from a CSV file. Each transaction includes details such as the timestamp of the sale, product name, expiry date, quantity sold, and payment method.\n\n- **Apply Discount Rules:** Based on the transaction details, the engine applies several discount rules:\n  - **Product Expiry:** Discounts are offered based on how soon a product is expiring.\n  - **Product Type:** Special discounts for specific products like cheese and wine.\n  - **Special Dates:** A substantial discount is applied to all products sold on the 23rd of March.\n  - **Quantity Discounts:** Discounts increase with the quantity of the product purchased.\n  - **App Usage:** Encourages use of the store's app by applying discounts based on the transaction channel.\n  - **Payment Method:** Promotes the use of Visa cards by providing a discount for transactions using Visa.\n\n- **Calculate Final Price:** After applying the relevant discounts, the engine calculates the final price for each transaction.\n\n- **Write Results:** The processed transactions, along with the discounts applied and the final calculated prices, are then written to a database for persistence.\n\n- **Logging:** Throughout its operation, the engine logs various events such as the start and end of data processing, errors, and other significant occurrences in the system.\n\n\n## Getting Started\n\n### Prerequisites\n\n- Scala 2.12.x\n- Java 8+\n- SBT (Scala Build Tool)\n- Oracle Database or another relational database with JDBC support\n\n### Setup and Installation\n\n1. **Clone the repository**:\n   ```sh\n   git clone \u003crepository-url\u003e\n   ```\n2. **Navigate to the project directory**:\n   ```sh\n   cd \u003cproject-directory\u003e\n   ```\n3. **Compile the project using SBT**:\n   ```sh\n   sbt compile\n   ```\n\n### Running the Application\n\nRun the application using SBT:\n```sh\nsbt run\n```\n\n## Configuration\n\n- **Database Connection**: Set up the database connection parameters in the application to point to your Oracle database instance.\n- **CSV File Path**: Ensure the path to the CSV file containing transaction data is correctly set in the application.\n\n\n## Acknowledgements\n\nThis project was developed as part of the ITI 44 curriculum, leveraging functional programming techniques to solve practical problems in retail operations.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fal-ghaly%2Fruleengineusingscala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fal-ghaly%2Fruleengineusingscala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fal-ghaly%2Fruleengineusingscala/lists"}