Page Fault/
├── constants.py # Constants, enums, configuration (~35 lines)
├── models.py # Data classes (~20 lines)
├── algorithms.py # Algorithm implementations (~200 lines)
├── controllers.py # Animation controller (~60 lines)
├── windows.py # Visualization windows (~530 lines)
├── app.py # Main application class (~280 lines)
├── main.py # Entry point (~30 lines)
└── page.py # Original monolithic file (backup)
Total: ~1,155 lines split into 7 focused modules
Purpose: Centralized configuration and constants
Contains:
AnimationSpeedenum (SLOW, MEDIUM, FAST, INSTANT)COLORSdictionary (color scheme)FONT_FAMILYconfigurationMAX_FRAMESandMAX_PAGESlimits
Dependencies: None
Used by: All modules
Purpose: Data structures
Contains:
PageFaultResultdataclass
Dependencies: None
Used by: algorithms.py, windows.py
Purpose: Page replacement algorithm implementations
Contains:
PageReplacementAlgorithm(base class)FIFOAlgorithmLRUAlgorithmOptimalAlgorithm
Dependencies:
- models.py (for PageFaultResult)
- time, collections.deque
Used by: app.py
Key Features:
- Pure algorithm logic, no GUI code
- Easy to add new algorithms
- Testable in isolation
Purpose: Animation state management
Contains:
AnimationControllerclass
Dependencies:
- constants.py (for AnimationSpeed)
- time
Used by: app.py, windows.py
Key Features:
- Pause/Resume/Stop/Restart
- Speed control
- State management
Purpose: Visualization user interfaces
Contains:
VisualizationWindow- Single algorithm visualizationComparisonWindow- Multi-algorithm comparison
Dependencies:
- constants.py (colors, fonts)
- models.py (PageFaultResult)
- controllers.py (AnimationController)
- tkinter, csv
Used by: app.py
Key Features:
- Scrollable animation
- Live metrics
- CSV export
- Bar charts
Purpose: Main application window and logic
Contains:
PageReplacementAppclass
Dependencies:
- All other modules
- tkinter
Used by: main.py
Key Features:
- Input validation
- Configuration UI
- Preset examples
- Algorithm execution
Purpose: Application entry point
Contains:
main()function- Documentation
Dependencies:
- app.py
Usage:
python main.pymain.py
└── app.py
├── constants.py
├── controllers.py
│ ├── constants.py
│ └── time
├── algorithms.py
│ ├── models.py
│ ├── time
│ └── collections
└── windows.py
├── constants.py
├── models.py
├── controllers.py
├── tkinter
└── csv
Core Dependencies:
- constants.py: No dependencies (base level)
- models.py: No dependencies (base level)
# Standard way
python main.py
# Or directly
python -m main# Use just the algorithms
from algorithms import FIFOAlgorithm, LRUAlgorithm
pages = [1, 2, 3, 1, 4, 2]
algo = FIFOAlgorithm(pages, num_frames=3)
result = algo.execute()
print(f"Faults: {result.total_faults}")# In algorithms.py
class LFUAlgorithm(PageReplacementAlgorithm):
"""Least Frequently Used algorithm"""
def execute(self) -> PageFaultResult:
# Your implementation
passThen update app.py algorithm dictionary:
algo_class = {
'FIFO': FIFOAlgorithm,
'LRU': LRUAlgorithm,
'Optimal': OptimalAlgorithm,
'LFU': LFUAlgorithm, # Add this
}

