System Overview¶
This foundational Python application framework provides comprehensive infrastructure components for building robust Python applications. The architecture emphasizes async-first patterns, immutable data structures, and cross-platform compatibility.
System Architecture¶
Core Components¶
- Application Foundation
preparationmodule: Single-point async initializationstatemodule: Immutable global state management throughGlobalsdataclassapplicationmodule: Application metadata and platform directory integration
- Configuration Management
configurationmodule: Hierarchical TOML configuration with extensible acquirer protocoldicteditsmodule: Configuration editing and merging utilitiesenvironmentmodule: Environment variable processing and integration
- CLI Framework
climodule: Command and application base classes with rich output controlintrospectionmodule: Self-inspection commands demonstrating CLI patternsinscriptionmodule: Integrated logging and diagnostic output
- Platform Integration
distributionmodule: Development vs production deployment detectioniomodule: Cross-platform I/O utilitiesasyncfmodule: Async utilities and patterns
- Infrastructure
exceptionsmodule: Comprehensive exception hierarchy with chaining supportgenericsmodule: Result types and generic utilities
Component Relationships¶
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Application │───▶│ Configuration │───▶│ Environment │
│ Foundation │ │ Management │ │ Integration │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ State Manager │◀───│ CLI Framework │───▶│ Platform │
│ (Globals) │ │ (Commands) │ │ Detection │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Exceptions │ │ Inscription │ │ Infrastructure │
│ & Results │ │ & Logging │ │ Utilities │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Data Flow¶
- Initialization Flow
prepare()function coordinates async initializationDistribution detection determines deployment mode
Platform directories discovered and created
Configuration loaded with hierarchical merging
Globalsdataclass created with immutable application stateLogging configured based on deployment mode and preferences
- CLI Application Flow
Application.prepare()extends foundation initializationCommand routing via
isinstance()type guardsDisplay options control output format and routing
Rich terminal detection enables automatic format adaptation
Stream routing directs output to stdout, stderr, or files
- Configuration Flow
AcquirerAbcprotocol enables pluggable configuration sourcesTOML files loaded with include processing and template variables
Environment overrides applied with precedence rules
Configuration edits merged into final immutable dictionary
Architectural Patterns¶
Async-First Design¶
All initialization and resource management uses async patterns to enable concurrent initialization of external dependencies while maintaining sequential library setup.
Key Benefits:
- Applications can initialize other resources during framework preparation
- Proper resource cleanup through AsyncExitStack integration
- Future-ready for async-heavy applications
Immutable Data Architecture¶
All application state uses immutable dataclasses to ensure thread safety and prevent accidental mutation.
Implementation:
- Globals dataclass contains all framework state
- Configuration stored as accretive dictionary objects (immutable after assignment)
- State updates create new instances rather than modifying existing ones
Metaclass-Based Application Factories¶
The CLI framework uses sophisticated metaclass patterns from the classcore
library to enable declarative application definition.
Capabilities: - Automatic command discovery and routing - Type-safe argument parsing integration - Consistent error handling across commands
Extensible Configuration System¶
Configuration management supports multiple sources through the AcquirerAbc
protocol while maintaining consistent merging behavior.
Design Features: - Pluggable configuration sources (TOML, database, API, etc.) - Hierarchical loading with include support - Template variable processing - Environment variable overrides
Quality Attributes¶
- Type Safety
100% type annotation coverage for all public APIs
Generic types for customizable components
Protocol-based interfaces for extensibility
- Cross-Platform Compatibility
Automatic platform detection and adaptation
Consistent behavior across Windows, macOS, Linux
PyPy compatibility through careful metaclass handling
- Maintainability
Clear separation of concerns between modules
Immutable data prevents state-related bugs
Comprehensive exception hierarchy with proper chaining
- Testability
100% test coverage with edge case handling
Dependency injection through constructor parameters
Clear interfaces enable easy mocking and testing
Deployment Architecture¶
- Development Mode
Automatic detection based on package installation method
Enhanced logging and debugging capabilities
Configuration loading from development directories
- Production Mode
Optimized for deployed applications
Platform-standard directory usage
Streamlined logging configuration
- Cross-Platform Distribution
Single codebase works across all supported platforms
Automatic adaptation to platform conventions
Consistent CLI behavior regardless of environment