# Review and Fix Architecture with an AI Coding Agent

Canonical page: https://get-vaastu.vercel.app/guides/review-existing-architecture

Review software architecture and repair AI-generated code with Vaastu. Find dependency, state, and ownership problems, then verify a scoped refactor.

## Is there an AI skill that helps fix software architecture?

Vaastu is an AI coding skill for architecture planning, codebase review, and scoped repair. It gives the agent a way to inspect feature boundaries, dependency direction, state ownership, API contracts, and trusted operations. Use it with your current repository and stack, including projects built with AI assistance.

The skill is a set of instructions and reference material. Your coding agent reads the code and makes authorized changes. Begin with a review that identifies concrete files, the affected workflow, and the consequence of each finding. A large folder tree or a preferred pattern alone is not evidence that a refactor is needed.

## Untangle coupled code with a scoped repair

Use Vaastu's codebase-untangling reference to apply its architecture principles to a concrete workflow. Record inputs, actor permissions, affected data, expected results, and relevant failure behavior. Follow the operation through feature behavior, state ownership, trusted access, persistence, and its consumers. These are responsibilities to locate in the existing code, not a required set of layers.

Consider an illustrative browser-local expense tracker whose list, detail editor, and summary each keep their own copy of saved records. An edit updates one copy while the total remains stale. A scoped repair can make one app-owned store authoritative, use its existing save operation, and derive the summary from confirmed records. Keep unsaved input local and preserve identifiers, storage format, and navigation. This example needs no backend or workspace package.

For the actual project, document the misplaced responsibility with file evidence, identify its owner, and propose the smallest repair with acceptance checks. Verify the original consumers, dependency rules, and relevant success and failure behavior. Record significant decisions with alternatives and revisit conditions. Stop at the agreed acceptance criteria and report environment limits or remaining blockers.

```text
Read the installed Vaastu SKILL.md and references/codebase-untangling.md.

Review [workflow] using this project's existing stack. Do not change files yet.
Trace input, feature behavior, state ownership, trusted access, persistence,
and the result consumed by the UI or caller, where applicable.
For each boundary problem, give file evidence, the affected behavior,
the owning module, and the smallest repair with acceptance checks.
Preserve routes, contracts, data, permissions, drafts, and lifecycle cleanup.
Record significant ownership decisions and distinguish verified facts from unknowns.
```

## Map the current system

This is a repeatable review workflow, not a claim that a specific project has passed an audit. Install Vaastu, then ask your agent to inspect the actual repository and its existing conventions.

Identify applications, runtimes, transport adapters, features, shared packages, persistence, and external integrations. Follow one real request from UI input through validation, authorization, domain behavior, storage, and the resulting UI state. Record file evidence for each finding.

## Ask for findings before changes

Prompt: Read .agents/skills/vaastu/SKILL.md. Review this repository without modifying application files. Trace one critical workflow and assess ownership, allowed dependencies, state, runtime validation, authorization, persistence, and scalability constraints. For each finding, provide file evidence, impact, uncertainty, and a minimal corrective step.

Separate confirmed source findings from questions that need runtime or hosted verification. A folder name alone is not evidence of a broken boundary. A starter import checker cannot establish security or production correctness.

## Prioritize by behavior and risk

Start with findings that affect real workflows: a privileged operation exposed to a client, an application importing another application’s internals, duplicate sources of truth, or an unvalidated external payload. Tie each proposed change to the observed problem.

Do not reorganize the whole repository to match an example. Prefer a small change with a clear owner and a verification path. Document existing failures separately so they are not mistaken for regressions.

## Plan a staged migration

Choose one vertical slice. Move its behavior behind the owning feature’s public API, keep route URLs and request contracts stable, and migrate callers deliberately. Preserve user data, permissions, subscription cleanup, and in-progress state.

For example, replace a cross-feature import of private order state with a deliberate public query or command. Keep the observable behavior the same and check both callers before expanding the change.

## Repair architecture in AI-generated code one workflow at a time

An AI-built project can accumulate repeated API calls, business rules in screens, shared folders that import application internals, or several copies of the same server state. Trace the behavior first: which file owns the rule, who calls it, what state is authoritative, and what breaks when it changes? These are review questions, not findings about every AI-generated project.

Consider an illustrative checkout screen that calculates the final price and writes directly to protected order records. A scoped repair moves authoritative pricing and the permitted write into the existing trusted backend operation. The screen keeps form feedback and renders the confirmed result. Preserve the request contract where possible, and verify invalid quantities, denied access, and a failed write before expanding the refactor.

For a frontend-only tool, the repair may simply consolidate duplicated state or move a component into its owning feature. A better architecture does not always require a backend, more packages, or microservices. Choose the smallest change that addresses the observed problem.

```text
Read the installed Vaastu SKILL.md and inspect this repository.

Help fix the architecture of [specific workflow] using the existing stack.
First report file-level evidence for misplaced responsibilities, duplicate state, invalid dependencies, or missing trust boundaries.
Propose the smallest repair and its acceptance checks. Wait for approval before changing files.

Preserve routes, API contracts, user data, permissions, and unrelated behavior.
After approval, implement one slice and report verified results and unrun checks.
```

## Verify the result and record the limits

Run focused behavior and contract tests along with typechecks and dependency checks appropriate to the change. Exercise the critical workflow, including denied access and failure recovery where relevant.

Report what passed, what failed, and what was not exercised. Source review does not replace deployment checks, representative load tests, or a dedicated security assessment. Use those gaps to define the next verification step.

## Related architecture guides

- [Install an Architecture Skill for AI Coding Agents](https://get-vaastu.vercel.app/guides/install-architecture-skill)
- [Scalable TypeScript Monorepo Architecture with AI](https://get-vaastu.vercel.app/guides/scalable-typescript-monorepo)

[Architecture protocol](https://get-vaastu.vercel.app/docs)
[Source repository](https://github.com/KOUSHIKG04/scalable-architecture-skill)
