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:

  1. GUI Interface - Interactive graphical interface with:

    • Punch card visualization
    • Input options and controls
    • Status display and feedback
    • Interactive card editing
  2. 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

  1. Core Engine

    • Central coordinator of the system
    • Manages application state
    • Routes commands between components
    • Handles configuration settings
    • Manages error handling and logging
  2. 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
  3. 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
  4. API Client

    • Communicates with external APIs (OpenAI)
    • Handles authentication and key management
    • Manages rate limiting and error recovery
    • Processes API responses
  5. 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  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. 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
  2. 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:

  1. Command Line Arguments - Highest priority
  2. Environment Variables - Second priority
  3. Configuration Files - Third priority
  4. Default Settings - Lowest priority

This architecture document will be updated as the system evolves.