Project Guide: File-Based Transaction Management System
Overview
You are required to build a minimal Transaction Management application that simulates, records, and processes
financial transactions efficiently. The system must be designed to handle large transaction files without loading them
entirely into memory.
Core Objective
Design a class-based Python application that generates random transactions, persists them to a file, processes
them lazily using generators, and ensures safe file handling using a custom context manager.
Application Structure
Create a TransactionManager class that encapsulates all transaction-related operations including balance
management, transaction generation, persistence, and processing.
Transaction Generation
1 Each transaction must include a transaction ID, type (CREDIT or DEBIT), amount, and resulting balance.
2 Transaction amounts must be generated randomly within a dynamic range based on the current balance.
3 Debit transactions must not exceed the available balance.
4 All transactions must be written to a file in a structured, comma-separated format.
File Handling (Custom Context Manager)
1 Implement a custom context manager to open and close the transaction file safely.
2 Ensure the file is always closed, even if an exception occurs.
3 Log file open and close operations using the logging module.
Transaction Processing (Generator)
1 Implement a generator function to read and yield one transaction at a time.
2 Convert raw file lines into structured data such as tuples or dictionaries.
3 Skip invalid records gracefully and log parsing errors.
Transaction Summary
1 Compute the total number of valid transactions.
2 Compute total credited and debited amounts.
3 Compute the final account balance after processing.
Error Handling and Logging
1 Use Python’s logging module to record errors and key events.
2 Handle malformed records using exception handling without stopping execution.
Constraints
1 The entire transaction file must not be loaded into memory.
2 File processing must be lazy using generators.
3 Do not use global variables.
4 Code must be modular, readable, and maintainable.