{"slug": "refactoring-with-ai", "title": "Refactoring with AI?", "summary": "A developer has added migration and refactoring skills to the Polylith tooling for Python, enabling AI agents to convert legacy single-repo projects into an agent-friendly Polylith Monorepo. The skills automate steps such as extracting application code, restructuring, and splitting large components, and have been tested with Claude and Mistral models. The developer argues that code simplicity is crucial for AI agents, similar to humans, and that the Polylith Architecture supports both human and agentic development.", "body_md": "With Agentic Engineering there's an opportunity to refactor legacy code, but this aspect of AI isn't that that much talked about and seems to be overlooked by teams out there. So far, the main thing with AI and agents has been to build new things in a fast pace.\n\nAfter several months of practicing Agentic Engineering, I've realized that code quality - or code health - is more important than ever. Agents get confused by complexity, just like humans. You've probably seen it (I have too) and now there is also [research](https://codescene.com/resources/research-and-insights) backing it up. Keeping code simple is a good guideline also in the agentic era.\n\nThis is where I believe the *Polylith Architecture* is a good fit, for both humans and agents. The original idea of Polylith was to keep things simple and great Developer Experience for Humans. As a nice side effect, Agents will probably like this setup too. An agent will have the context it needs to build new features from the existing well-organized code in the Monorepo.\n\nSince before, the Polylith tool for Python includes a set of agent skills about the commands and about Polylith in general. But what about migrating an entire existing single-repo project into a Polylith Monorepo? With AI, many steps could be automated here.\n\nI recently [added additional skills](https://github.com/DavidVujic/python-polylith/discussions/449) to the Polylith tooling that are focused on migrating and refactoring an existing Python project into an Agent friendly Monorepo. The migration skills handles the extracting of application code, restructuring and also refactoring of large components into smaller ones.\n\nThe agentic flow for the migration of a project is:\n\n- discover\n- analyze-imports\n- extract-to-base\n- update-imports\n- prepare-project\n- verify-stability\n- isolate-base-and-big-component\n- split-big-component\n- extract-standalone-modules\n- isolate-shared-and-project-logic\n- distribute-wiring\n- split-component-internals\n- refactor-tests\n- definition-of-done\n\nAlso, the project-specific tooling (such as Project & Dependency management, linting and type checking) is migrated and converted according to what’s already in the monorepo.\n\nExample: you use *uv* and *ruff* in the Polylith Monorepo, and migrate a project that uses *Poetry* and *flake8*. The migration will convert those to *uv* and *ruff*.\n\nI have tested the skills with Claude (Opus 4.7 and 4.8) and Mistral (mistral-large and devstral). One of the tests I ran was converting the FastAPI repo (just for fun and to test the skills out) into Polylith.\n\nBefore running the prompt, I copied the contents of the FastAPI repo into the Polylith projects folder. I also removed the existing *.git* folder in there, to avoid any confusion during the agentic work.\n\n**Hint**: the more unit tests the project to migrate has, the better!\n\nThe skills are part of the polylith-cli, and you can copy the contents of the *.agents* file or use a tool like *library-skills* to add them to your monorepo. Agents are unpredictable and different models behave differently. If you decide to try this thing out, please let me know how the skills works for you.\n\nYou'll find [info about Polylith for Python here](https://davidvujic.github.io/python-polylith-docs/).\n\nTop Photo by", "url": "https://wpnews.pro/news/refactoring-with-ai", "canonical_source": "https://davidvujic.blogspot.com/2026/06/refactoring-with-ai.html", "published_at": "2026-06-07 20:12:18+00:00", "updated_at": "2026-06-22 09:49:54.814394+00:00", "lang": "en", "topics": ["artificial-intelligence", "developer-tools", "ai-agents", "machine-learning", "large-language-models"], "entities": ["Polylith", "David Vujic", "Claude", "Mistral", "FastAPI", "Python", "uv", "ruff"], "alternates": {"html": "https://wpnews.pro/news/refactoring-with-ai", "markdown": "https://wpnews.pro/news/refactoring-with-ai.md", "text": "https://wpnews.pro/news/refactoring-with-ai.txt", "jsonld": "https://wpnews.pro/news/refactoring-with-ai.jsonld"}}