Overview
This blog post is to share the current approach I am following for development of a React app at work. I created one agent skill called “implement” to which I give context to build, like a Jira story, a Figma design link, and any additional context if needed. I have Jira and Figma MCPs using which the agent can get context from them.
Splitting a feature into slices
The skill tries to split the things it needs to implement the full feature into slices. A slice is created in such a way that it’s something which I can test manually by running the app and clicking around to verify it’s working.
The skill also maintains a state file, which has the full details of all slices and the current progress of which slices are done and how far along they are. This allows me to start new agent sessions without the agent losing its context, as the state file acts as the context.
The skill starts working with the first slice and it asks if I want to create a subtask for this slice. I create subtasks to create small pull requests (PRs) so that PRs can be reviewed easily. For that, the skill calls a Jira skill which I created. It creates a subtask with two sections, overview (using language which can be understood by PMs) and acceptance criteria.
TDD
After creating the subtask, the skill proceeds with implementation. It calls a “react-tdd” skill which I created for test-driven development in a React codebase. I created this separate skill for the cases where I just need to implement some small thing or fix a bug instead of implementing a big feature. I just call the react-tdd skill for such cases.
The agent begins by writing a failing test for a class (which may not exist yet) and waits for me to review. I start with tests because they are easy to read and review and show exactly whether the features I want to implement are covered by tests. You may wonder - why classes in a React codebase when most React projects do not use classes? I create classes to have logic and state in them so that they can easily be tested without React.
These tests are written in a way that they don’t need any mocking. You may wonder - what about API calls? These classes will not have API calling logic. API calling logic lives in the Service layer which I will talk about next. We need mocking only for interacting with the outside world; all that logic is in the service layer which will need a different kind of tests.
My app uses Jest as the test runner. But for development I use Bun as the test runner as it’s very fast; it’s able to run such tests in milliseconds. The idea is to move all logic into the class so that React will have just wiring logic with the class. This keeps tests fast as they don’t need to render React components for testing.
I review the API of the class - it should have a good name and readable method names and method arguments should make sense. I know many devs don’t care about this anymore, they just care if something is working and proceed. I still care about readability of code. And by readability I mean if someone is looking at a block of code, they should understand it within seconds, instead of spending too much time to understand it.
After reviewing the test, I approve it and the agent writes the implementation class and moves on to write a failing test for another class and waits for me to review, and so on. A slice may need multiple classes, so this loop goes on for all the classes.
After that, the agent proceeds to do service layer changes.
Service layer
By Service layer I mean the layer responsible for interacting with the outside world like API calls. I keep all logic related to API calls in Service files, e.g. UserService will have methods like getUsers, createUser, which the app can use to interact with the API. The service layer will handle the serialization and deserialization needed to make this work and calling the correct APIs with correct query and route parameters.
For service files too, the agent first writes the tests and waits for me to review them. These tests will need mocking as they are interacting with the outside world, e.g. API calls will need mocking of the HTTP layer.
In these tests I mock the HTTP layer to mock the response of the API to test deserialization logic. These tests assert whether the API is called with the correct URL and with the correct query and route parameters and whether serialization and deserialization is working as expected.
I review these tests and after I approve, the agent writes the implementation of service classes and proceeds to the next step which is wiring the React components with classes.
Wiring React components with classes
For wiring components with classes, the agent uses React’s useState hook.
const [todoController] = useState(() => new TodoController())
And if the class has state, I use React’s useSyncExternalStore
hook to connect React to the class state.
const state = useSyncExternalStore(todoController.subscribe, todoController.getState)
I review the class code to make sure all the logic is moved to classes. I try to move all if conditions and loops to classes so I can write tests for them in class tests, so that I don’t need to render React components for testing them.
To make wiring code minimal and declarative I use a functional programming library called Ramda
. From this library I use pipe, andThen, tap. This library helps in writing point-free code
. Point-free coding avoids verbosity by hiding args of functions. One code block in my codebase looks like below.
return pipe(
tap(controller.clearErrors),
handler.handleVoid,
DocumentService.voidDocument,
andThen(handler.handleApiResult),
andThen(updateUI)
)
You can see this type of code doesn’t have the verbosity of specifying arguments and just declares what it’s doing.
After this the agent proceeds with mock server changes.
Mock server - Mirage
I use Mirage as a mock server for development. It allows development of the UI without depending on API changes. With it you can maintain a mock server which will serve all your API requests. It’s very easy to maintain this now with an AI agent as it can quickly do the mock server changes using which we can test if the UI feature is working.
I also created a “mirage” skill because I found that the agent is not following Mirage best practices and the agent does workarounds to get APIs working. The implement skill calls the mirage skill for doing mock server changes so that the APIs added in the service layer work in my dev environment.
After mock changes, the agent waits for me to manually test the changes. The agent also gives the steps for testing. I review the steps and test manually. Sometimes I tell the agent to test them using the Chrome DevTools MCP I installed. Using that MCP, the agent can open the browser and do the steps for testing. After manual testing, the agent marks the slice as done.
After this I can raise a pull request for changes done using a pull request skill I created. I also use my custom commit skill for commit format.
This is repeated for all slices till the entire feature is complete.
Integration tests
I also created a skill to write integration-style tests in Jest. These tests are slow, so I write them only for happy-path scenarios or critical paths. These tests mostly render the full page of the app using jsdom and click through the app like a real user and assert visible changes. Sometimes I also render a single component if rendering everything slows down the test too much. I try to have many assertions in such tests instead of writing multiple tests to cover all assertions, to keep the test suite fast.
With an AI agent it’s easy to bloat the codebase with this type of tests (which render React components or the entire page). For things which can be covered by class tests (unit tests), we can avoid writing integration tests. This keeps the test suite fast.
I also did integration test setup with Cypress in the app. These tests run in the browser instead of Node.js. These tests run the app in dev env keeping the mock server (Mirage) enabled. I use these tests only for things which cannot be tested using jsdom tests. These are browser-heavy interaction things like interacting with a complex dropdown. These tests are slower than Jest tests so I try to avoid them if possible.
Conclusion
I like this current process I am following. It allows the developer to review small changes (done by the agent) at a time instead of reviewing all changes at once. Reviewing too many files is awful. Also this process is test-first; tests are easier to review and to verify if they are covering all required features.
Agent skills (shared)
I’m not sharing all the skills mentioned in this post. Many of them are repo-specific so the agent can work more effectively in my codebase at work. Below are some generalized skills I created that you can reuse or adapt.
