Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created April 28, 2025 06:22
Show Gist options
  • Save ehzawad/774d86e5242d6fb14dd8dc0d8f4f375d to your computer and use it in GitHub Desktop.
Save ehzawad/774d86e5242d6fb14dd8dc0d8f4f375d to your computer and use it in GitHub Desktop.
php to node

Understood. I will dig into GitHub repositories specifically, focusing on open-source tools, frameworks, and agentic workflows that assist or enable migrating, refactoring, or transpiling full PHP codebases into Node.js (JavaScript/TypeScript). I will prioritize actively maintained projects, note their adaptability, and include any AST parser, LLM-driven agent frameworks, or hybrid systems that are directly relevant. I'll synthesize the findings into a detailed, no-nonsense report with practical guidance on applicability and readiness levels.

Open-Source Tools and Frameworks for PHP→Node.js Migration

Migrating a large PHP codebase to Node.js is a complex task. No turnkey solution exists, but several open-source projects and frameworks can help automate pieces of the process. We categorize these into AST parsers and analyzers, code transpilers and generators, LLM-assisted migration tools, and agentic framework kits. For each, we note capabilities, limitations, and adaptation effort, focusing on tools updated within ~18 months.

AST Parsers and Static Analyzers

  • Glayzzle PHP-Parser (JavaScript) – A mature PHP parser written in JavaScript (npm package php-parser) that produces an ESTree-like AST. It can handle modern PHP syntax (PHP 7 and 8) and is actively maintained (latest version 3.2.3 released Apr 17, 2025 (GitHub - glayzzle/php-parser: 🌿 NodeJS PHP Parser - extract AST or tokens)). As a Node library, it lets you ingest PHP code and examine or transform its structure. Capability: reliably parse any PHP file into a manipulable AST. Limitation: It does not generate output code or migrate semantics on its own – you must write custom code-generation to emit JavaScript/TypeScript from the AST. Adaptation: Use as a building block for analyzers or custom refactoring. For production migration, you’d pair this with generators or translators. (No built‑in PHP runtime is provided, so dynamic features like include or global state must be handled manually.)

  • nikic/PHP-Parser (PHP) – The de facto PHP AST library, written in PHP. It supports parsing PHP 5.2–8.x (with full AST and location info) and can dump and regenerate PHP code (GitHub - nikic/PHP-Parser: A PHP parser written in PHP). It’s heavily used in linters/refactoring tools and has been updated as recently as Feb 26, 2025 (Commits · nikic/PHP-Parser · GitHub). Capability: Accurate, resilient parsing of legacy PHP. Limitation: As a PHP library, it cannot directly emit JavaScript – you’d have to traverse the PHP AST and manually map constructs to Node.js equivalents. Adaptation: Useful for large-scale analysis or identifying idioms (classes, functions, etc.) to port. Developers have built tools (e.g. Rector) on top of it, illustrating that writing automated transforms is feasible but nontrivial.

  • @rightcapital/php-parser (Node/TypeScript wrapper) – A TypeScript/JavaScript interface that uses the nikic/PHP-Parser via the PHP CLI. It provides typed ASTs in Node by shelling out to PHP, combining nikic’s power with JavaScript workflows. The npm package is actively published (v1.4.25 as of Apr 2025 (@rightcapital/php-parser - npm)). Capability: Full-fidelity PHP AST in Node.js environment, with TypeScript typings to ease development. Limitation: Requires a PHP installation and composer at runtime, so introduces external dependencies. Code migration logic still must be implemented by user code (the package does not auto-generate JS). Adaptation: Good for teams comfortable invoking PHP from Node. It simplifies AST handling and can interoperate with Node-based tools like ESLint/Prettier on the output side, but doesn’t itself output Node code.

Source-to-Source Transpilers and Generators

  • Uniter (asmblah/uniter) – A set of tools (parser + transpiler + runtime) to run PHP in JS. Uniter parses PHP into AST (phptoast), transpiles to JavaScript (phptojs), and provides a minimal PHP runtime library (phpcore/phpruntime). In effect, it compiles PHP code to an equivalent JS program. Its README touts “Run PHP client-side in the browser or in Node.js” (GitHub - asmblah/uniter: PHP in the browser and Node.js => Docs: https://phptojs.com/) (Uniter). It remains maintained (recent commit “Bump version” Apr 14, 2025 (Commits · asmblah/uniter · GitHub)). Capability: Converts many PHP scripts into JS that can execute under a JS engine. Limitation: The transpiled code still depends on a PHP-like runtime library, and not all PHP constructs are supported. Complex features (extensions, certain builtins) may be missing or behave differently. The output is not idiomatic Node.js: it emulates PHP behavior rather than refactoring logic into asynchronous JS patterns. Adaptation: Useful for running legacy libraries in Node with minimal change, but converting an entire web application would require heavy tweaking. You’d still need to replace framework-specific code (e.g. request handling) with Node equivalents. In short, Uniter can bootstrap basic scripts but is not a plug‑and‑play migration.

  • Spatie TypeScript Transformer – A PHP library (spatie/typescript-transformer) that turns PHP class and type declarations into TypeScript types (GitHub - spatie/typescript-transformer: Transform PHP types to TypeScript). It is maintained by Spatie (a popular PHP vendor) and updated regularly. Capability: Automates generation of TypeScript definitions from PHP docblocks or typed properties. Useful for data models and constants (for example, PHP DTO classes can become TS interfaces) (GitHub - spatie/typescript-transformer: Transform PHP types to TypeScript). Limitation: It handles static type structures only – no actual method or business-logic code migration. It doesn’t cover functions or procedural code. Adaptation: As part of a migration, it can preserve API types and enums, ensuring TypeScript side has matching shapes. It does not convert logic. Use it to reduce manual rewriting of model/schema classes, but you’ll still write the JavaScript/TypeScript implementation of methods.

  • Glayzzle/php-transpiler – An older project (by the Glayzzle team) intended to emit JavaScript from a PHP AST. It provided an API layer on top of the AST to generate JS. Capability: In theory, it aimed to run arbitrary PHP scripts under Node’s V8 by transpilation. Limitation: It appears abandoned (last commits in 2017) (Commits · glayzzle/php-transpiler · GitHub) and incomplete. The current README notes “project is still under development, so you can’t use it yet” (GitHub - glayzzle/glayzzle: 🚀 CLI library - PHP transpiler to NodeJS / Javascript). Adaptation: Not suitable for production. It serves more as a proof of concept. Any serious migration should rely on more mature tools or write custom transforms.

  • Babel PHP Preset (kornelski/babel-preset-php) – A community effort to let Babel parse and translate PHP syntax to JS. It has not been active (2017) and doesn’t support modern PHP. Capability: Theoretically, could be used with Babel toolchain. Limitation: Outdated and very limited; we list it only for completeness.

LLM-Assisted Migration Tools

  • GPT-Migrate (joshpxyne/gpt-migrate) – A Python-based framework that uses GPT-4 (or other LLMs) to rewrite entire codebases. It orchestrates a Docker-based migration pipeline: spinning up containers, applying model-driven code transformations starting from the entry point, and iteratively debugging via generated unit tests. It has gained popularity (6.9K stars as of 2025) and is actively maintained (GitHub - joshpxyne/gpt-migrate: Easily migrate your codebase from one framework or language to another.). Capability: Automates much of the grunt work of rewriting code: it can handle one-language to another migrations (including Python/Flask→Node as shown) and can be pointed at PHP source via --sourcelang php --targetlang nodejs. The README advertises “easily migrate your codebase from one framework or language to another” (GitHub - joshpxyne/gpt-migrate: Easily migrate your codebase from one framework or language to another.). Limitation: Being LLM-based, output is not 100% reliable. The quality depends on prompt engineering and the size of the model. Mistakes, missing edge cases, and style inconsistencies are common. It also incurs heavy cost (GPT-4-32K tokens is recommended) and potentially long runtimes. Adaptation: To migrate PHP, you must structure appropriate prompts and tests. GPT-Migrate is designed for customization (see its --guidelines option for style rules) and can test against existing unit tests. However, significant review is needed: expect to fix parts of the generated code, especially integrations (databases, file I/O, or use of PHP-specific libraries). GPT-Migrate can bootstrap the process, but final code must be audited and optimized manually.

  • Universal Migration Agent (eben-vranken/universal-migration-agent) – A recently introduced LLM-agent (Python) that attempts to automate generic code migration tasks. It lets you define a migration_config.json describing source and target, then runs an agent that “automates the process of migrating existing codebases” (GitHub - eben-vranken/universal-migration-agent: LLM-powered agent which automates codebase migrations). Capability: A proof-of-concept for LLM-driven migration agents. Limitation: It is immature (very few stars and limited documentation), and last saw commits around mid-2023 (Commits · eben-vranken/universal-migration-agent · GitHub). There’s no evidence of real-world use, and it’s not tuned specifically for PHP-to-Node. Adaptation: It may serve as a template or starting point (the code is MIT-licensed), but substantial work would be needed to handle PHP/Node specifics. Given its experimental status, we caution that it’s not yet a production-ready solution.

Agentic Frameworks and LLM Toolkits

  • AutoGen (microsoft/autogen) – A general-purpose Python framework for building multi-agent LLM applications. Microsoft’s AutoGen (v0.4) supports deploying “assistant” agents and tool-based agents that can call APIs or scripts. The README states “AutoGen is a framework for creating multi-agent AI applications” (GitHub - microsoft/autogen: A programming framework for agentic AI PyPi: autogen-agentchat Discord: https://aka.ms/autogen-discord Office Hour: https://aka.ms/autogen-officehour). Capability: Not a migration tool per se, but it provides an extensible agent architecture. One could implement agents for code analysis (using AST libraries), agents that invoke GPT to translate code snippets, and loop managers that iteratively fix errors. Limitation: Requires custom development. There is no out-of-the-box PHP-to-Node agent. You’d use AutoGen to glue together components (LLMs, parsers, test runners), but need to program the logic and error-handling yourself. Adaptation: For an enterprise migration, AutoGen could underlie a workflow: for example, an agent could parse a PHP class and ask an LLM to suggest equivalent TypeScript code, then run JS tests. However, building and debugging such multi-agent pipelines is complex. The framework is flexible and maintained, but substantial engineering is needed to turn it into a migration product.

  • LangChain (and LangChain.js) – A widely-used LLM orchestration library (Python and JS) for chaining prompts, memory, and tools. The project bills itself as “a framework for building LLM-powered applications” (GitHub - langchain-ai/langchain: Build context-aware reasoning applications), and is kept up to date. Capability: LangChain is not specific to code, but it can be used to structure an LLM-based migration. For instance, you could use LangChain’s chains or agents to manage multi-step transformations: one step might generate TS interfaces from PHP classes, another refactors business logic. It has many integrations (vector stores, code interpreters, etc.) that might assist. Limitation: Like AutoGen, it’s a general toolkit. You must engineer the prompts and retrieval flows yourself. There’s no built-in “translate my PHP repository” chain. Also, as with all LLM systems, the output must be validated. Adaptation: Suitable for prototypes or custom pipelines. Its JS version (LangChain.js) could run in Node if desired, keeping everything in one ecosystem. In practice, a LangChain solution might act as the “engine” behind a migration assistant, but expect a nontrivial implementation effort.

Summary

No single open-source tool fully automates PHP→Node migration. In practice, teams combine approaches: AST parsers (Glayzzle or nikic) to analyze code, transpilers (Uniter or custom scripts) to convert syntax, and LLM assistance (GPT-Migrate or agent frameworks) to handle higher-level reasoning. For example, one might use a PHP parser to extract class definitions, run Spatie’s transformer to get TypeScript types, then employ GPT-Migrate (with PHP as source language) to rewrite method bodies into JavaScript async functions. Throughout, constant review is required: PHP idioms (namespaces, runtime constructs, templates, global state) often have no direct Node equivalent.

In summary, actively maintained tools include AST libraries (Glayzzle PHP-Parser, nikic/PHP-Parser, RightCapital’s wrapper) for code analysis, Uniter for basic transpilation, Spatie’s type converter for model translation, and LLM pipelines like GPT-Migrate for bulk rewriting. Emerging agent frameworks (AutoGen, LangChain) can orchestrate LLM steps. Each has clear limits: most generate semi-auto code that still needs human refinement. A realistic production workflow will blend these tools with manual effort, extensive testing, and possibly incremental migration (module by module).

Sources: Official project READMEs and documentation (GitHub - glayzzle/php-parser: 🌿 NodeJS PHP Parser - extract AST or tokens) (GitHub - asmblah/uniter: PHP in the browser and Node.js => Docs: https://phptojs.com/) (GitHub - spatie/typescript-transformer: Transform PHP types to TypeScript) (GitHub - joshpxyne/gpt-migrate: Easily migrate your codebase from one framework or language to another.) (GitHub - eben-vranken/universal-migration-agent: LLM-powered agent which automates codebase migrations) (GitHub - microsoft/autogen: A programming framework for agentic AI PyPi: autogen-agentchat Discord: https://aka.ms/autogen-discord Office Hour: https://aka.ms/autogen-officehour) (GitHub - langchain-ai/langchain: Build context-aware reasoning applications) provide details on features and recency. Each cited project’s repo confirms update dates and capabilities as noted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment