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
-
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.
-
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.
-
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.
Summary
Currently,
archctlidentifies 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 toeslint --fixto 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:
context-visibilityrule.Proposed Solution
Add an
--fixflag toarchctl lintor a newarchctl fixcommand.Key Capabilities
Public API Generation:
billing/internal/helper.tswhich is blocked by context visibility.billing/api/index.tsto exporthelper, and update the import path in the consuming file tobilling/api.Layer Migration Helper:
domainbut importsinfrastructuredependencies.applicationorinfrastructure, and automatically rewrite all imports pointing to/from that file.Barrel File Maintenance:
index.tsfiles to ensure they strictly match thepublicpatterns defined inarchctl.config.json.Implementation Details
ts-morphor similar AST transformation tools for safe refactoring.--interactive) to confirm changes before applying them.