Skip to content

Feature Request: Automated Fixes and Refactoring Support #9

@qiuethan

Description

@qiuethan

Summary

Currently, archctl identifies architectural violations (e.g., "Layer 'domain' cannot import from 'infrastructure'"), but resolving them is a manual process. This feature aims to introduce "Auto-Fix" capabilities similar to eslint --fix to help developers resolve common architectural issues automatically.

Problem

When a developer introduces a violation, they often know what they did wrong but fixing it might involve tedious refactoring:

  • Moving a file to the correct layer.
  • Updating imports across the codebase after a move.
  • Creating a public re-export in an API barrel file to satisfy a context-visibility rule.

Proposed Solution

Add an --fix flag to archctl lint or a new archctl fix command.

Key Capabilities

  1. Public API Generation:

    • Scenario: A file imports billing/internal/helper.ts which is blocked by context visibility.
    • Fix: Automatically create (or update) billing/api/index.ts to export helper, and update the import path in the consuming file to billing/api.
  2. Layer Migration Helper:

    • Scenario: A file is placed in domain but imports infrastructure dependencies.
    • Fix: Prompt to move the file to application or infrastructure, and automatically rewrite all imports pointing to/from that file.
  3. Barrel File Maintenance:

    • Automatically manage index.ts files to ensure they strictly match the public patterns defined in archctl.config.json.

Implementation Details

  • Leverage ts-morph or similar AST transformation tools for safe refactoring.
  • Interactive mode (--interactive) to confirm changes before applying them.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions