Skip to content

Conversation

@rmottanet
Copy link
Owner

@rmottanet rmottanet commented Nov 27, 2025

Monolithic to Layered Architecture

This PR implements a comprehensive architectural refactoring of the Branch Spawn GitHub Action, transitioning from a monolithic structure to a modular, layered architecture following SOLID principles and clean code practices.

Changes

🏗 Architectural Transformation

  • Before: Single monolithic index.ts handling configuration, business logic, and GitHub API operations
  • After: Clear separation of concerns with dedicated layers for configuration, services, and orchestration

📁 New Module Structure

src/
├── main.ts          # Pure orchestrator - workflow coordination only
├── config.ts        # Input validation and configuration management
└── services/
    └── github.service.ts  # GitHub API operations layer

🔧 Technical Improvements

1. Single Responsibility Principle (SRP)

  • ConfigManager: Exclusive responsibility for input validation and configuration
  • GitHubService: Dedicated to GitHub API operations with typed Octokit client
  • main.ts: Pure orchestration and error handling

2. Type Safety & Validation

// Immutable input interface
export interface ActionInputs {
  readonly owner: string;
  readonly repo: string;
  readonly baseBranch: string;
  readonly newBranch: string;
  readonly githubToken: string;
}

// Centralized validation
private static validate(inputs: ActionInputs): void

3. Dependency Injection & Testability

// Manual dependency injection for better testability
const gitService = new GitHubService(inputs.githubToken);

4. Clean Error Handling

  • Structured error classification with proper type checking
  • Early validation failures before API operations
  • Descriptive error messages for better debugging

🛡 Security & Robustness

  • Input sanitization and trimming
  • Branch naming validation with regex patterns
  • Duplicate branch name prevention
  • Token validation before API usage

📦 Build & Distribution

  • Updated build artifacts to reflect new architecture
  • Maintained backward compatibility with existing Action API
  • Updated package.json entry points

Benefits

🎯 Immediate Impact

  • Better Maintainability: Clear module boundaries and responsibilities
  • Enhanced Testability: Isolated components enable unit testing
  • Improved Debugging: Structured error handling and validation
  • Type Safety: Full TypeScript integration with Octokit SDK

🔮 Future Extensibility

  • Easy addition of new GitHub API operations
  • Simplified configuration expansion
  • Straightforward testing strategy implementation
  • Clean foundation for additional features

Migration Notes

Backward Compatibility

  • External Action interface remains unchanged
  • Input parameters and behavior preserved
  • Existing workflows continue working without modification

🔄 Code Quality Metrics

  • Reduced cyclomatic complexity through separation
  • Improved cohesion within each module
  • Reduced coupling between components
  • Enhanced code readability and documentation

This refactoring establishes a professional, enterprise-ready foundation for future development while maintaining full compatibility with existing implementations.

…ilities

- remove monolithic index.ts in favor of a modular structure
- implement config.ts for centralized configuration and types
- create a services/ layer for isolating business logic
- establish a dependency injection pattern for testability
- maintain core branch creation functionality with better separation
@rmottanet rmottanet self-assigned this Nov 27, 2025
@rmottanet rmottanet added the enhancement New feature or request label Nov 27, 2025
- updates package.json to reflect changes in the entry point
- generates compiled javascript corresponding to the new layered structure
- maintains compatibility with the github actions runtime environment
- preserves the action's external api while remaining internally modular
@rmottanet rmottanet merged commit 9c71fb5 into refactor Nov 27, 2025
@github-project-automation github-project-automation bot moved this to Done in @ws2git Nov 27, 2025
@rmottanet rmottanet deleted the dev branch November 27, 2025 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants