- mokoconsulting-tech → MokoConsulting across all docs - github.com → git.mokoconsulting.tech - CLI examples updated with new org name Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
12 KiB
MokoStandards Scripts Architecture
Version: 2.0 Last Updated: 2026-01-19 Status: Comprehensive rebuild in progress
Overview
This document defines the top-down architecture for all MokoStandards scripts and workflows.
Design Principles
- Separation of Concerns: Each module has a single, well-defined responsibility
- Type Safety: Full type hints on all public interfaces
- Error Handling: Comprehensive error messages with actionable guidance
- Documentation: Docstrings following Google style guide
- Testability: All modules designed for unit testing with clear interfaces
- Logging: Structured logging with consistent levels and formats
- Configuration: Centralized configuration management
- Dependencies: Minimal external dependencies, clear dependency tree
Module Hierarchy
scripts/
├── lib/ # Core libraries (no external script dependencies)
│ ├── common.py # Foundation: constants, utilities, decorators
│ ├── validation_framework.py # Base classes for validators
│ ├── config_manager.py # Configuration handling
│ ├── github_client.py # GitHub API wrapper
│ ├── audit_logger.py # Structured logging
│ ├── extension_utils.py # Extension/package utilities
│ ├── joomla_manifest.py # Joomla-specific manifest handling
│ └── gui_utils.py # GUI utilities (optional)
│
├── validate/ # Validation scripts (depend on lib/)
│ ├── auto_detect_platform.php # Platform detection (core)
│ ├── validate_structure_v2.py # Structure validation
│ ├── validate_repo_health.py # Repository health
│ ├── schema_aware_health_check.py # Schema-based validation
│ ├── check_repo_health.py # Health checker
│ ├── validate_codeql_config.py # CodeQL validation
│ ├── manifest.py # Manifest validation
│ ├── workflows.py # Workflow validation
│ ├── php_syntax.py # PHP syntax checking
│ ├── xml_wellformed.py # XML validation
│ ├── no_secrets.py # Secret detection
│ ├── tabs.py # Tab/whitespace checking
│ ├── paths.py # Path validation
│ └── generate_stubs.py # Stub generation
│
├── automation/ # Automation scripts (depend on lib/, validate/)
│ ├── bulk_update_repos.php (v2) # Bulk repository sync
│ ├── auto_create_org_projects.py # Organization project automation
│ ├── sync_dolibarr_changelog.py # Dolibarr changelog sync
│ ├── sync_file_to_project.py # File sync to projects
│ ├── create_repo_project.py # Repository project creation
│ └── file-distributor.py # File distribution
│
├── release/ # Release management (depend on lib/, validate/)
│ ├── detect_platform.py # Platform detection for releases
│ ├── package_extension.py # Extension packaging
│ └── dolibarr_release.py # Dolibarr release management
│
├── maintenance/ # Maintenance scripts (depend on lib/)
│ ├── release_version.py # Version management
│ ├── update_changelog.py # Changelog updates
│ ├── validate_file_headers.py # Header validation
│ └── flush_actions_cache.py # GitHub Actions cache management
│
├── analysis/ # Analysis tools (depend on lib/)
│ ├── analyze_pr_conflicts.py # PR conflict analysis
│ └── generate_canonical_config.py # Canonical configuration
│
├── build/ # Build scripts (depend on lib/)
│ └── resolve_makefile.py # Makefile resolution
│
├── docs/ # Documentation generation (depend on lib/)
│ └── rebuild_indexes.py # Index rebuilding
│
├── run/ # Runtime scripts (depend on lib/, automation/)
│ └── setup_github_project_v2.py # GitHub Project v2 setup
│
└── tests/ # Test scripts
├── test_bulk_update_repos.php # Bulk update tests
└── test_dry_run.py # Dry run tests
Core Library Modules (lib/)
common.py
Purpose: Foundation module with core utilities Exports:
- Constants (VERSION dynamically read from README.md, REPO_URL, EXIT codes)
- File header generation
- Logging utilities
- Error handling decorators
- Path utilities
- Version extraction from README.md title line
validation_framework.py
Purpose: Base classes and interfaces for validation Exports:
Validatorbase classValidationResultdata classValidationRuleinterface- Common validation patterns
config_manager.py
Purpose: Centralized configuration management Exports:
ConfigManagerclass- Configuration schema validation
- Environment variable handling
- Default configuration
github_client.py
Purpose: GitHub API wrapper with authentication Exports:
GitHubClientclass- API request handling with retries
- Rate limit management
- Common GitHub operations
audit_logger.py
Purpose: Structured logging framework Exports:
AuditLoggerclass- Log level management
- Structured log formatting
- Log file handling
Validation Modules (validate/)
All validation modules follow the pattern:
- Import from
lib/ - Define validation rules
- Implement
Validatorinterface - Return
ValidationResultobjects - Provide CLI interface
auto_detect_platform.php
Critical Module: Platform detection for all automation
Dependencies: lib/common, lib/validation_framework
Exports: detect_platform(), PlatformType enum
Automation Modules (automation/)
bulk_update_repos.php (v2)
Status: ✅ Rebuilt (2026-01-19)
Purpose: Schema-driven bulk repository synchronization
Dependencies: lib/, validate/auto_detect_platform
auto_create_org_projects.py
Purpose: Automated organization project creation
Dependencies: lib/github_client, lib/config_manager
Workflows (.github/workflows/)
Reusable Workflows
All reusable workflows follow the pattern:
- Clear input parameters with descriptions
- Minimal dependencies
- Comprehensive error handling
- Status reporting
Workflow Categories
- CI/CD: Build, test, deploy workflows
- Quality: Code quality, linting, validation
- Automation: Bulk updates, project management
- Security: Secret scanning, CodeQL, confidentiality
- Maintenance: Cache management, changelog updates
Coding Standards
Python
- Style: PEP 8 compliant
- Type Hints: Required for all public functions
- Docstrings: Google style, required for all public functions
- Error Handling: Use specific exception types
- Logging: Use
audit_loggerfor all logging - Testing: Unit tests for all public functions
YAML (Workflows)
- Naming:
kebab-casefor file names - Indentation: 2 spaces
- Comments: Document all non-obvious steps
- Secrets: Use repository/organization secrets, never hardcode
- Permissions: Minimal required permissions only
File Header Standard
All files must include:
#!/usr/bin/env python3
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# This file is part of a Moko Consulting project.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# [License text...]
#
# FILE INFORMATION
# DEFGROUP: [Group]
# INGROUP: [Parent Group]
# REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoStandards-API
# PATH: [Relative path from repo root]
# VERSION: [X.Y.Z] # Version is dynamically read from README.md title line
# BRIEF: [One-line description]
Note: The VERSION constant in common.py and MOKO_VERSION in common.sh are now dynamically extracted from the README.md title line, which follows the format:
# README - MokoStandards (VERSION: XX.YY.ZZ)
This ensures a single source of truth for the repository version.
Error Handling Strategy
Exit Codes
0: Success1: General error2: Invalid arguments3: File/resource not found4: Permission error5: Validation failed6: External dependency error
Error Messages
Format: [LEVEL] Component: Message (Context)
- ERROR: Unrecoverable errors
- WARNING: Non-fatal issues
- INFO: Informational messages
- DEBUG: Detailed diagnostic information
Testing Strategy
Unit Tests
- Located in
scripts/tests/ - Use
pytestframework - Mock external dependencies
- 80%+ code coverage target
Integration Tests
- Test workflows end-to-end
- Use test repositories
- Validate against schemas
Validation Tests
- All validators must have test cases
- Test both valid and invalid inputs
- Test edge cases
Configuration Management
Configuration Hierarchy
- Command-line arguments (highest priority)
- Environment variables
- Configuration files (
MokoStandards.override.xml) - Default values (lowest priority)
Configuration Schema
Validated against schemas/unified-repository-schema.json
Logging Strategy
Log Levels
- DEBUG: Detailed diagnostic for development
- INFO: General informational messages
- WARNING: Warning messages, recoverable issues
- ERROR: Error messages, unrecoverable issues
- CRITICAL: Critical failures requiring immediate attention
Log Format
[TIMESTAMP] [LEVEL] [COMPONENT] Message (context_key=value)
Dependency Management
Python Dependencies
Minimal external dependencies:
- Required: None (stdlib only for core modules)
- Optional:
requestsfor GitHub API (fallback tosubprocess+ghCLI)PyYAMLfor YAML parsing (fallback tojson)pytestfor testing (dev only)
Dependency Installation
pip install -r requirements.txt # Production
pip install -r requirements-dev.txt # Development
Migration Guide
From v1 to v2
- Update imports to use
lib/modules - Replace ad-hoc validation with
validation_framework - Use
ConfigManagerinstead of manual config parsing - Replace print statements with
audit_logger - Add type hints to all functions
- Add docstrings to all public functions
Performance Considerations
Caching
- Platform detection results
- GitHub API responses (with expiry)
- Validation results for unchanged files
Parallelization
- Repository operations can run in parallel
- Use
concurrent.futuresfor I/O-bound tasks - Respect GitHub API rate limits
Security Considerations
- No Hardcoded Secrets: Use GitHub secrets
- Input Validation: Validate all user inputs
- Path Traversal Prevention: Validate all file paths
- Command Injection Prevention: Use
subprocesssafely - Least Privilege: Minimal permissions in workflows
Maintenance
Version Numbering
- Major: Breaking changes (expected in v2 rebuild)
- Minor: New features
- Patch: Bug fixes
Changelog
All changes documented in CHANGELOG.md following Keep a Changelog format.
Review Process
- All changes require pull request
- Automated validation must pass
- Manual review required
- Tests must pass
Future Enhancements
- Plugin System: Allow custom validators
- Web Dashboard: UI for health monitoring
- Metrics Collection: Track validation trends
- AI Integration: Automated issue detection
- Multi-language Support: Beyond Python
References
- PEP 8 Style Guide
- Google Python Style Guide
- GitHub Actions Documentation
- Keep a Changelog
- Semantic Versioning
Maintained by: Moko Consulting Questions: hello@mokoconsulting.tech Repository: https://github.com/MokoConsulting/MokoStandards