System Architecture - griffingilreath/Punch-Card-Project GitHub Wiki
Punch Card Project: System Architecture
This page provides comprehensive diagrams and explanations of the Punch Card Project's architecture.
Overall System Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Punch Card Project β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββ¬β΄β¬ββββββββββββββββββ
β β β β
βββββββββββΌββββββββββ β β ββββββββββββΌββββββββββββ
β GUI β β β β Terminal Mode β
β Interface β β β β Interface β
βββββββββββ¬ββββββββββ β β ββββββββββββ¬ββββββββββββ
β β β β
β ββββββββΌβββΌββββββββ β
β β β β
ββββββββββΊβ Core Engine βββββββββββ
β β
ββββββββββ¬βββββββββ
β
ββββββββββββββ¬βββββββββββΌβββββββββββ¬βββββββββββββ
β β β β β
ββββββββββΌββββββ ββΌβββββββββββββ ββββΌβββββ βββΌβββββββββββ
β LED State β β Punch Card β β API β β Hardware β
β Manager β β Encoder β β Clientβ β Controller β
ββββββββββββββββ βββββββββββββββ βββββββββ ββββββββββββββ
β
ββββββββ΄ββββββββ
β Physical or β
β Simulated β
β Hardware β
ββββββββββββββββ
Component Interactions
UI Components
The Punch Card Project offers two primary user interfaces:
-
GUI Interface - Interactive graphical interface with:
- Punch card visualization
- Input options and controls
- Status display and feedback
- Interactive card editing
-
Terminal Interface - Text-based interface with:
- ASCII representation of punch cards
- Command-line options
- Test modes and diagnostics
- Hardware integration tools
Both interfaces communicate with the Core Engine, which manages all project functionality.
Core Components
-
Core Engine
- Central coordinator of the system
- Manages application state
- Routes commands between components
- Handles configuration settings
- Manages error handling and logging
-
LED State Manager
- Maintains the state of all LEDs in memory
- Provides APIs for manipulating LED states
- Handles transitions and animations
- Ensures consistent state representation
-
Punch Card Encoder
- Converts text to punch card patterns
- Implements IBM 026, IBM 029, and UNIVAC encoding standards
- Handles character validation
- Manages encoding/decoding operations
-
API Client
- Communicates with external APIs (OpenAI)
- Handles authentication and key management
- Manages rate limiting and error recovery
- Processes API responses
-
Hardware Controller
- Abstracts physical hardware details
- Supports Raspberry Pi GPIO for physical LEDs
- Provides simulation mode for testing
- Handles hardware initialization and shutdown
Data Flow
βββββββββββββββ βββββββββββββ ββββββββββββββββ βββββββββββββββ
β User Input βββββΊβ Interface βββββΊβ Core Engine βββββΊβ Encoder β
βββββββββββββββ βββββββββββββ ββββββββββββββββ ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ βββββββββββββ ββββββββββββββββ βββββββββββββββ
β Output ββββββ Hardware ββββββ LED Manager ββββββ Card Data β
βββββββββββββββ βββββββββββββ ββββββββββββββββ βββββββββββββββ
-
Input Processing Flow:
- User provides input via GUI or Terminal
- Interface passes commands to Core Engine
- Core Engine validates and processes input
- Input is encoded into punch card patterns
- LED states are updated based on patterns
- Hardware controller updates physical or simulated hardware
-
External API Flow:
- Core Engine requests external data (if needed)
- API Client handles authentication and requests
- Response is processed by Core Engine
- Results are encoded and displayed
Module Structure
The codebase is organized into logical modules:
src/
βββ core/ # Core functionality
β βββ engine.py # Central coordination
β βββ config.py # Configuration management
β βββ utils.py # Core utilities
βββ display/ # Display components
β βββ gui/ # GUI interface
β β βββ main_window.py
β β βββ widgets.py
β β βββ controllers.py
β βββ terminal/ # Terminal interface
β βββ ui.py
β βββ console.py
β βββ formatters.py
βββ hardware/ # Hardware abstraction
β βββ controller.py # Hardware controller base
β βββ led_manager.py # LED state management
β βββ simulator.py # Hardware simulation
β βββ rpi.py # Raspberry Pi implementation
βββ encoding/ # Card encoding
β βββ ibm026.py # IBM 026 encoding
β βββ ibm029.py # IBM 029 encoding
β βββ univac.py # UNIVAC encoding
β βββ custom.py # Custom encoding support
βββ api/ # External API integration
βββ client.py # API client base
βββ openai.py # OpenAI integration
βββ key_manager.py # API key management
Testing Architecture
The project includes a comprehensive testing infrastructure:
tests/
βββ unit/ # Unit tests
β βββ core/ # Core component tests
β βββ display/ # Display component tests
β βββ hardware/ # Hardware component tests
β βββ encoding/ # Encoding component tests
βββ integration/ # Integration tests
β βββ gui_tests.py # GUI integration
β βββ terminal_tests.py # Terminal integration
β βββ api_tests.py # API integration
βββ e2e/ # End-to-end tests
βββ scenarios/ # Test scenarios
βββ fixtures/ # Test data
Configuration Management
Configuration is managed through a hierarchical system:
- Command Line Arguments - Highest priority
- Environment Variables - Second priority
- Configuration Files - Third priority
- Default Settings - Lowest priority
This architecture document will be updated as the system evolves.