Real-world backends rarely start clean. Codebases accumulate years of legacy structure — controllers next to database clients, utilities mixed with business logic, configuration scattered across ad-hoc directories.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ronaldjdev/forge/llms.txt
Use this file to discover all available pages before exploring further.
relocate and reforge are Forge’s two migration and refactoring commands: relocate surgically moves existing code from a legacy location to its correct architectural layer, while reforge performs a broader restructuring that resolves violations, extracts use cases from controllers, fixes cyclic dependencies, and brings a project fully into compliance with Forge’s four-layer model.
relocate — Migrate Legacy Code
relocate is the targeted migration tool. It classifies code by its nature and moves it to the correct layer: Platform, Features, Shared, or Infrastructure.
Migration Targets
| Code Type | Target Layer | Example Destination |
|---|---|---|
| Config, server, logger, DI | Platform | src/platform/config/ |
| Business logic, entities, use cases | Features | src/features/<name>/ |
| Reusable pure code, utils, types | Shared | src/shared/utils/ |
| DB clients, external services, ORMs | Infra | src/infra/prisma/ |
How relocate Works
Backup
Forge automatically creates a backup checkpoint before making any changes. You can restore it at any time with
forge rollback.Classify
Identify the component and determine its correct layer based on its nature (see the table above). The critical rule: never place domain logic in
src/platform/. If a file contains entities, use cases, business rules, or imports from src/features/, it belongs in a feature — not in platform.Create target structure
Build the destination directory structure for the chosen layer according to Forge’s naming conventions.
Migrate files
Move the files, keeping the logic intact. Update all import paths in the rest of the codebase to point to the new locations.
Clean up legacy structure
This step is mandatory. After relocating, remove all artefacts that belonged to the old structure:
- Old files in legacy directories (
src/application/,src/domain/,src/adapters/,src/setting/, etc.) - Empty
index.tsbarrel files that only re-exported legacy code - Empty directories left over after the migration
Layer Classification Reference
| Component | Correct Layer |
|---|---|
| App config, environment variables | src/platform/config/ |
| HTTP middleware, router, guards | src/platform/http/ |
| DB connections, Redis client, mail client | src/infra/ |
| Pure utilities (no business rules) | src/shared/utils/ |
| Domain entities, value objects, events | src/features/<name>/domain/ |
| Use cases, application services | src/features/<name>/application/ |
| Controllers, persistence adapters, schemas | src/features/<name>/adapters/ |
If the migration introduces violations (R1–R9), Forge can restore your project automatically. Use
forge rollback list to see available checkpoints and forge rollback restore <id> to revert.reforge — Refactor Architecture
reforge is the comprehensive refactoring command. Where relocate moves a single component, reforge evaluates the entire project across all four layers and executes all the corrections needed to reach a clean architectural state.
What reforge Does
reforge operates across all four architectural layers in a single pass:
- Extracts business logic from controllers into properly structured use cases in
src/features/<name>/application/use-cases/ - Moves orphaned components to their correct layer based on their nature and dependency graph
- Resolves cyclic dependencies (R9) and any other active R1–R9 violations
- Migrates code between layers when a component has been placed in the wrong domain
- Auto-fixes naming violations (with user confirmation): renames files to match
<PascalCase>.<artefact>.tsconventions and updates all imports
Post-reforge Steps
Clean up legacy structure
After
reforge completes, remove any remaining legacy artefacts: old files at their original locations, barrel files (index.ts) that only exported migrated code, and empty directories. Do not leave orphans or broken imports.Verify ownership
Run
forge armorer to confirm the ownership report shows zero orphans, zero duplicates, and zero misplaced components.Single-File Rename Mode
reforge can also operate on a single file to rename it according to naming conventions without performing a full refactor:
forge quench to validate — without creating a backup or touching any other files.