This directory contains example migrations demonstrating the capabilities of the Forge code migration engine. Each example includes before and after code samples showing real-world migration scenarios.
examples/
├── README.md # This file
├── <migration-name>/
│ ├── README.md # Example-specific documentation
│ ├── before/ # Original source code
│ │ └── ...
│ ├── after/ # Migrated code
│ │ └── ...
│ ├── forge.config.toml # Migration configuration
│ └── migration-report.md # Generated migration report
| Example | Description | Complexity |
|---|---|---|
| java8-spring-to-java21 | Spring Boot app from Java 8 to Java 21 | Medium |
| java11-to-java21 | Incremental update from Java 11 LTS | Low |
| javax-to-jakarta | Jakarta EE namespace migration | Low |
| Example | Description | Complexity |
|---|---|---|
| php-laravel-to-typescript | Laravel app to TypeScript/Express | High |
| python-flask-to-typescript | Flask app to TypeScript/Express | High |
| ruby-rails-to-typescript | Rails app to TypeScript/NestJS | Very High |
| Example | Description | Complexity |
|---|---|---|
| angular-to-react | Angular 12+ to React 18 | Very High |
| vue2-to-vue3 | Vue 2 Options API to Vue 3 Composition API | Medium |
| javascript-to-typescript | Plain JS to TypeScript | Medium |
# Navigate to an example
cd examples/java8-spring-to-java21
# Run the migration in dry-run mode
forge migrate --config forge.config.toml --dry-run
# View the diff
forge migrate --config forge.config.toml --diff
# Execute the migration
forge migrate --config forge.config.toml --output ./output# Compare your migration output with the expected 'after' directory
forge compare ./output ./after
# Generate a detailed diff report
forge compare ./output ./after --report migration-diff.htmlThis example demonstrates modernizing a Spring Boot application:
Before (Java 8):
public List<User> findActiveUsers(List<User> users) {
List<User> result = new ArrayList<>();
for (User user : users) {
if (user.isActive()) {
result.add(user);
}
}
return result;
}After (Java 21):
public List<User> findActiveUsers(List<User> users) {
return users.stream()
.filter(User::isActive)
.toList();
}Key transformations:
- ✅ Loops → Stream API
- ✅ Anonymous classes → Lambdas
- ✅
Date/Calendar→java.time - ✅ Data classes → Records
- ✅
instanceofchecks → Pattern matching - ✅ String concatenation → Text blocks
- ✅ Switch statements → Switch expressions
This example demonstrates converting a Laravel REST API:
Before (PHP/Laravel):
public function index(Request $request): JsonResponse
{
$users = User::where('active', true)
->orderBy('created_at', 'desc')
->paginate(15);
return response()->json($users);
}After (TypeScript/Express):
async index(req: Request, res: Response): Promise<void> {
const users = await prisma.user.findMany({
where: { active: true },
orderBy: { createdAt: 'desc' },
take: 15,
skip: (req.query.page as number - 1) * 15,
});
res.json(users);
}Key transformations:
- ✅ PHP types → TypeScript types
- ✅ Eloquent ORM → Prisma ORM
- ✅ Laravel routing → Express routes
- ✅ Form requests → Zod validators
- ✅ Blade templates → React components (optional)
- ✅ PHPUnit tests → Vitest tests
- Create a new directory under
examples/ - Add a
README.mddescribing the migration - Place original code in
before/ - Run Forge to generate
after/ - Create
forge.config.tomlwith your settings - Submit a PR to share with the community
Each example includes a forge.config.toml:
[migration]
rule = "java8-to-java21"
source = "./before"
output = "./after"
[options]
# Rule-specific options
var_keyword_strategy = "moderate"
aggressive_record_conversion = false
[verification]
compile_check = true
test_execution = true- Start Simple: Begin with the java11-to-java21 example
- Use Dry Run: Always preview changes with
--dry-run - Read Reports: Check migration-report.md for insights
- Compare Carefully: Use
forge compareto understand changes - Customize: Modify options to see different migration strategies
We welcome new examples! Please:
- Choose a realistic, common migration scenario
- Include working, compilable code
- Document any prerequisites
- Explain key transformation decisions
- Include tests that pass before and after
See CONTRIBUTING.md for detailed guidelines.