# Why AI-generated code can be messy at first and maintainable after refactoring

DevFeed: [Why AI-generated code can be messy at first and maintainable after refactoring](<https://devfeed.tech/articles/my-ai-wrote-garbage-code-and-that-was-exactly-what-i-needed-27207.md>)

Original publisher: [Read original article](<https://antonioleiva.com/my-ai-wrote-garbage-code-and-that-was-exactly-right>)

Published: 2026-03-02T00:00:00Z

Content type: article

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [Refactoring](<https://devfeed.tech/topics/refactoring.md>), [Artificial Intelligence](<https://devfeed.tech/topics/ai.md>), [OpenClaw](<https://devfeed.tech/topics/openclaw.md>), [Model Context Protocol](<https://devfeed.tech/topics/model-context-protocol.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [clean-code](<https://devfeed.tech/tags/clean-code.md>), [cli](<https://devfeed.tech/tags/cli.md>), [code](<https://devfeed.tech/tags/code.md>), [docker](<https://devfeed.tech/tags/docker.md>), [mcp](<https://devfeed.tech/tags/mcp.md>), [raspberry-pi](<https://devfeed.tech/tags/raspberry-pi.md>), [refactoring](<https://devfeed.tech/tags/refactoring.md>)

## AI overview

The author argues that AI-assisted exploratory projects do not need clean architecture and polished tests from the beginning. Initial code can be messy, but the work is complete only after successive refactoring makes it maintainable and scalable. The article illustrates this with a project whose expanding API, web interface, CLI, and MCP led to technical debt and very large files.

## Source excerpt

Everything Android, Kotlin and other random topics