Architecture¶
This document describes the architecture of Fast Craftsmanship, explaining how the components fit together and the design decisions behind them.
Overview¶
Fast Craftsmanship follows a modular, functional architecture with a clear separation of concerns:
┌─────────────────┐
│ CLI Layer │
└───────┬─────────┘
│
┌───────▼─────────┐
│ Command Layer │
└───────┬─────────┘
│
┌───────▼─────────┐
│ Domain Layer │
└───────┬─────────┘
│
┌───────▼─────────┐
│ Utility Layer │
└─────────────────┘
Layers¶
CLI Layer¶
The CLI layer handles user interaction through the command line interface. It:
- Parses command-line arguments
- Dispatches to the appropriate commands
- Formats output for display
- Handles command-line flags and options
Key files:
- fcship/cli.py: Main entry point and command registration
- fcship/tui/: Text UI components for display and interaction
Command Layer¶
The Command layer contains the implementation of all commands. Each command:
- Takes validated input from the CLI layer
- Implements the business logic for the command
- Returns a Result that may contain data or errors
- Is responsible for a specific domain of functionality
Key files:
- fcship/commands/*.py: Individual command modules
- fcship/commands/__init__.py: Command registration and organization
Domain Layer¶
The domain layer contains the core business logic and models. It:
- Defines data structures and validation rules
- Implements domain-specific operations
- Is independent of the command and CLI layers
- Uses Railway Oriented Programming for error handling
Key files: - Domain models in various command modules - Validation logic and business rules
Utility Layer¶
The utility layer provides common functions and tools used across the application:
- Error handling utilities
- File system operations
- Functional programming helpers
- Type utilities
Key files:
- fcship/utils/error_handling.py: Error utilities
- fcship/utils/file_utils.py: File system operations
- fcship/utils/functional.py: Functional programming utilities
- fcship/utils/type_utils.py: Type handling utilities
Key Design Principles¶
Functional Programming¶
Fast Craftsmanship is built on functional programming principles:
- Pure Functions: Functions have no side effects and return the same output for the same input
- Immutable Data: Data structures are immutable, using Pydantic models
- Railway Oriented Programming: Error handling using Result types
- Function Composition: Building complex operations by composing simple functions
Railway Oriented Programming (ROP)¶
ROP is a core pattern in Fast Craftsmanship:
- Functions return
Result[T, E]types representing success or failure - Errors propagate through pipelines of functions
- Effect functions (
@effect.result) for sequential operations - Explicit error handling without exceptions
Command Pattern¶
Commands follow a consistent pattern:
- Parse and validate input
- Execute the command logic
- Return a Result with the output or errors
- Format and display the result
Dependency Injection¶
The architecture uses a form of dependency injection:
- Functions receive their dependencies as parameters
- Higher-order functions compose behavior
- No global state or singletons
- Easy to test with mocks and stubs
File Organization¶
The project follows this file organization:
fcship/
├── __init__.py
├── cli.py # Main CLI entry point
├── commands/ # Command implementations
│ ├── __init__.py # Command registration
│ ├── github/ # GitHub commands
│ ├── project/ # Project commands
│ └── ...
├── templates/ # Templates for code generation
│ ├── __init__.py
│ └── ...
├── tui/ # Text UI components
│ ├── __init__.py
│ └── ...
└── utils/ # Utility functions
├── __init__.py
└── ...
Error Handling¶
Fast Craftsmanship uses a structured approach to error handling:
- Functions return
Result[T, E]types - Error types are well-defined and descriptive
- Errors propagate through function pipelines
- TUI layer formats errors for display
Testing Strategy¶
The testing strategy follows these principles:
- Unit Tests: Test individual functions in isolation
- Integration Tests: Test command execution end-to-end
- Mocks and Stubs: Use mocks for external dependencies
- Property Testing: Use property-based testing for invariants
- Coverage: Maintain high test coverage
Future Improvements¶
Areas for future architectural improvements:
- Plugin System: Allow for custom commands and extensions
- Event System: Implement an event system for loose coupling
- Caching: Add caching for expensive operations
- Parallelism: Add support for parallel execution of tasks
- Config Management: Enhance configuration management