This document describes the modular architecture of curlpad.
curlpad/
├── src/
│ └── curlpad/ # Main package directory
│ ├── __init__.py # Package initialization and exports
│ ├── __main__.py # Entry point for `python -m curlpad`
│ ├── constants.py # Constants (version, colors, metadata)
│ ├── utils.py # Utility functions (debug, cleanup, temp files)
│ ├── output.py # Output formatting (print_error, print_warning, etc.)
│ ├── dependencies.py # Dependency management (check, install)
│ ├── templates.py # Template file creation
│ ├── editor.py # Editor configuration and launching
│ ├── commands.py # Command extraction, validation, execution
│ └── cli.py # Command-line interface and main flow
├── curlpad.py # Backward-compatible entry point
├── curlpad.spec # PyInstaller spec file
├── pyproject.toml # Python project configuration
├── requirements.txt # Python dependencies
├── scripts/ # Build and release scripts
└── README.md # User documentation
Purpose: Application-wide constants and configuration
Variables:
__version__: Application version string__author__: Author information__license__: License identifierColors: ANSI color codes for terminal output
Usage: Imported by all modules that need constants or colors.
Purpose: Utility functions and global state management
Global Variables:
temp_files: List[str]: Tracks temporary files for cleanupDEBUG: bool: Global debug flag (set via --debug CLI flag)
Functions:
debug_print(message: str): Print debug messages with timestampscleanup_temp_files(): Remove all tracked temporary filessignal_handler(signum, frame): Handle SIGINT/SIGTERM signals
Flow:
- Application starts →
temp_filesis empty,DEBUGis False - User runs with
--debug→DEBUGis set to True - Modules create temp files → added to
temp_fileslist - On exit →
cleanup_temp_files()removes all temp files
Purpose: User-facing output formatting
Functions:
print_error(message: str): Print error (red) and exitprint_warning(message: str): Print warning (yellow)print_success(message: str): Print success (green)print_info(message: str): Print info (blue)
Flow: All user messages go through these functions for consistent formatting.
Purpose: Dependency checking and installation
Functions:
check_command(command: str) -> bool: Check if command exists in PATHget_editor() -> str: Detect available editor (nvim/vim)check_dependencies() -> None: Verify curl is installedinstall_deps() -> None: Install vim/jq using package managers
Flow:
check_dependencies()verifies curl is installedget_editor()detects nvim or viminstall_deps()can install vim/jq if--installflag is used
Purpose: Template file creation
Functions:
create_template_file() -> str: Create shell script template with curl examplescreate_curl_dict() -> str: Create dictionary file for Vim autocomplete
Flow:
create_template_file()creates.shfile with commented curl examplescreate_curl_dict()creates.dictfile with curl options- Both files added to
temp_filesfor cleanup - File paths returned for use by editor module
Purpose: Editor configuration and launching
Functions:
create_editor_config(target_file: str) -> str: Create Vim/Neovim configopen_editor(tmpfile: str) -> None: Launch editor with template
Flow:
get_editor()detects editor (nvim preferred)create_editor_config()creates editor-specific config fileopen_editor()launches editor with config and template- User edits commands
- Editor closes, control returns to main flow
Purpose: Command extraction, validation, and execution
Functions:
extract_commands(tmpfile: str) -> List[str]: Parse template and extract curl commandsformat_json_with_jq(commands: List[str]) -> List[str]: Format JSON in commandsvalidate_command(command: str) -> bool: Validate curl command syntaxrun_command(command: str) -> None: Execute curl command and display results
Flow:
extract_commands()reads template and extracts curl commandsformat_json_with_jq()formats JSON (if jq available)validate_command()checks each command is validrun_command()executes each command and displays results
Purpose: Command-line interface and main orchestration
Functions:
confirm_execution(commands: List[str]) -> bool: Prompt for confirmationshow_help() -> None: Display help messageshow_version() -> None: Display versionmain() -> None: Main entry point
Flow:
- Parse command-line arguments
- Handle
--help,--version,--installflags - Check dependencies (curl)
- Create template file
- Open editor with autocomplete
- Extract commands from edited file
- Format JSON (if jq available)
- Validate commands
- Prompt for confirmation
- Execute commands
User runs: curlpad
↓
cli.main()
↓
check_dependencies() → verify curl installed
↓
create_template_file() → create .sh file with examples
↓
open_editor() → launch nvim/vim with autocomplete
↓
User edits commands in editor
↓
extract_commands() → parse file and extract curl commands
↓
format_json_with_jq() → format JSON (optional)
↓
validate_command() → check each command
↓
confirm_execution() → prompt user for confirmation
↓
run_command() → execute each curl command
↓
Display results
- Purpose: Track all temporary files for cleanup
- Modified by:
templates.py,editor.py - Cleaned by:
utils.cleanup_temp_files() - Lifecycle: Files added when created, removed on exit
- Purpose: Enable verbose logging
- Set by:
cli.pywhen--debugflag is provided - Used by: All modules via
debug_print() - Lifecycle: False by default, True when
--debugflag used
cli.py
├── constants.py (version)
├── utils.py (DEBUG, debug_print)
├── output.py (print_* functions)
├── dependencies.py (check_dependencies, install_deps)
├── templates.py (create_template_file)
├── editor.py (open_editor)
└── commands.py (extract_commands, format_json_with_jq, validate_command, run_command)
editor.py
├── dependencies.py (get_editor)
├── templates.py (create_curl_dict)
├── utils.py (temp_files, debug_print, DEBUG)
└── output.py (print_error)
commands.py
├── constants.py (Colors)
├── dependencies.py (check_command)
├── utils.py (debug_print)
└── output.py (print_error, print_warning)
templates.py
├── utils.py (temp_files, debug_print, DEBUG)
└── output.py (print_error)
dependencies.py
├── utils.py (debug_print)
└── output.py (print_error, print_info, print_success)
output.py
├── constants.py (Colors)
└── utils.py (cleanup_temp_files)
utils.py
└── constants.py (Colors)
-
curlpad.py: Backward-compatible entry point- Adds
src/to PYTHONPATH - Imports and calls
cli.main()
- Adds
-
src/curlpad/__main__.py: Module entry point- Allows
python -m curlpad - Imports and calls
cli.main()
- Allows
-
src/curlpad/cli.py: Main entry point- Contains
main()function - Orchestrates entire application flow
- Contains
- PyInstaller reads
curlpad.spec - Entry point is
curlpad.py(which imports fromsrc/curlpad) - PyInstaller auto-detects all imports from
src/curlpadpackage - Binary is created with all dependencies bundled
To test the modular structure:
# Test version
python curlpad.py --version
# Test help
python curlpad.py --help
# Test as module
python -m curlpad --version
# Test with debug
python curlpad.py --debugThe curlpad.py file maintains backward compatibility:
- Same command-line interface
- Same behavior
- Same entry point for PyInstaller
- Imports from new modular structure