Architectures Compared for AI-Assisted Coding (AI hACk-ing đ¤¨)
About
A comparison between the super simple Model View (MV) architecture and the more complex and opinionated The Composable Architecture (TCA) when performing AI-Assisted Coding to build a small SwiftUI iOS App.
â ď¸ Used NavigationView instead of NavigationStack (old syntax)
â ď¸ Needed prompting to use NavigationStack instead of a List
State Management
â as expected
â ď¸ Did not used Shared State, but the solution developed was still functional
Views
â as expected
â ď¸ Initially used old TCA syntax like âWithViewStoreâ, and not using macros
Key Takeaways
The AI Tool used in this test (Cursor) reached the solution faster and made less mistakes implementing the simpler Model View (MV) architecture than when implementing TCA.
(However I still believeâŚ) Your choice of architecture should primarily be driven by what you believe is the right architecture for maintaining the software you are building, and not by the AI tool youâre using. Both a flexible and simple architecture like MV, and a more opinionated and complex architecture like TCA can be built with an AI assistant. However, your ability to maintain the code going forward is still an important feature of your architecture, so if you believe the more complex structure will benefit you as the code evolves, you should still use that approach.
The quality of code is more determined by the knowledge you have acquired to direct the AI towards a good solution. Donât expect the combination of the right architecture + AI to mean you donât have to think through and research the best way to structure your solution.
Having the LLM tightly integrated into the IDE like it is in Cursor significantly improves the flow of building and iterating with an AI
The different syntax for old vs new versions of TCA caused the biggest misunderstanding from the AI in this test. The code was written 1st using the old TCA syntax, and without knowledge of the different versions of TCA, I wouldnât have known to ask the AI to update to the new syntax.
If you are using a more complex architecture pattern like TCA (complex meaning; has multiple published versions online, integrates with dependencies, uses non vanilla Swift constructs), and you are unfamiliar with the architecture that you are trying to implement, then you shouldnât rely on your LLM assistant to replace you having to put in effort reading and learning. Unless you know the right questions to ask, and are able to provide the right prompt to move the solution towards latest best practice, the result could be out of date, or broken.
Feature Implementation Test
To compare architecture patterns I have described a simple feature set that can be contained within less than 5 files. I have chosen 2 app features to allow the architecture patterns to expand into their different structures; navigation and shared state.
Architectures
The Composable Architecture (TCA)
The Composable Architecture (TCA) is a strongly opinionated Swift framework for building modular, testable, and predictable state management in iOS applications using a unidirectional data flow, combining state, actions, and side effects into a single cohesive structure.
TCA single view structure showing Unidirectional Data Flow (UDF)
Model-View (MV) is a flexible and fairly un-opinionated architecture pattern for iOS Swift applications separates the app into two main components: the Model, which handles data and business logic, and the View, which manages the UI.