# Explain the Architecture of a Rails Codebase

An agent maps rubygems.org into a 282-line architecture.md with three Mermaid diagrams and a traced GET /gems/rubygem0 that ran 23 SQL queries.

[Run this on Rush](https://cloud.getrush.ai/run/architecture-overview/rails/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads `config/routes.rb`, where line 205 maps `resources :rubygems` to `path: 'gems'`, the `before_action` chain in `RubygemsController`, `Rubygem.find_by_name` at `app/controllers/application_controller.rb:126` and the 58 tables in `db/schema.rb`. It checks configuration instead of assuming: production caches in memcached (`config/environments/production.rb:113`), `config/initializers/good_job.rb` configures GoodJob, `lib/shoryuken/sqs_worker.rb` reads S3 events from SQS, and `config/deploy/versions-list-update-monthly.yaml.erb` runs on `0 0 1 * *`.

Then it starts the development stack natively, since the sandbox has no Docker, seeds the database, requests `GET /gems/rubygem0` and reads its SQL from `log/development.log`. Each claim in `architecture.md` is labelled `[Static]` or `[Runtime]`.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Inspect the attached Rails repository and write architecture.md with the commit, component ownership, database layout, domain relationships, one request traced from route through controller/concerns/models to storage and rendering, plus queued and recurring work. Include Mermaid component and request-flow diagrams; support factual claims with file:line citations and short source quotes. Check actual configuration rather than assuming conventional Rails services. Try the documented development setup only with disposable local data and no external delivery; label runtime observations and static conclusions separately. Respect repository contribution rules: do not modify app code, push, submit a PR or contact production.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on rubygems/rubygems.org at 96a4bd1f7: 1 file changed, 282 insertions(+), a new `architecture.md` with Mermaid component, ER and request-flow diagrams. The traced `GET /gems/rubygem0` issued 23 SQL queries plus 2 cache hits, all against PostgreSQL. The baseline `bin/rails test` on the untouched clone exited 1 with `5627 runs, 17216 assertions, 1 failures, 0 errors, 214 skips`; that failure predates the change. That took Ruby 4.0.9 from mise, PostgreSQL 15 with `trust` auth (compose pins 18.6), memcached, OpenSearch 2.13.0, libmagic and libvips headers for `bundle install`, `bin/rails tailwindcss:build` and an OpenSearch restart; before the Tailwind build there were 752 errors. After the change, a 70-run subset exited 0: `70 runs, 168 assertions, 0 failures, 0 errors, 0 skips`.

For the reviewer: the Mermaid diagrams were not rendered, so their syntax is unchecked, and a few points are marked inferred, such as the `searchkick` and `mailers` queues being library defaults. Gem push, search and the SQS worker were not run, and Fastly, S3 and SQS behaviour comes from code only.

## Run it on every new maintainer

Your onboarding tool calls `POST /o/{org}/sessions` with this input and the repository in `resources`, then waits on the event stream or a webhook. The run copied `architecture.md` to `/workspace/.rush/artifacts/`, so it comes back as a session artifact the tool downloads by name.

## Why run it on Rush?

Configuration decided the map: memcached in production, GoodJob for queued work, gem files on S3 through `RubygemFs`, an SQS worker for S3 events. The local development trace of the gem page touched only PostgreSQL, so the report says which paths it saw run and which it only read.

## Frequently asked questions

### Which test failure was there before the change?

`StoreVersionContentsJobTest` "a valid gem should record file mode" failed on the untouched clone, expecting `"600"` and getting `"644"`. The agent suspects the sandbox's file-mode settings but did not investigate.

### Why not the full suite after the change?

The change is one Markdown file, so the agent ran `bin/rails test test/functional/rubygems_controller_test.rb test/jobs/upload_versions_file_job_test.rb`, which exited 0. `bundle install` had modified `Gemfile.lock`; the agent reverted it.

## More Rails jobs

- [Audit a Rails Repository per Customer Request](https://getrush.ai/run/audit-customer-repos/rails/)
- [Build an Admin Page in a Rails App](https://getrush.ai/run/build-admin-page/rails/)
- [Fix a Rails App Bug From a Datadog Monitor Alert](https://getrush.ai/run/fix-datadog-alerts/rails/)

## The same job on other stacks

- [Explain the Architecture of a Spring Boot Codebase](https://getrush.ai/run/architecture-overview/spring-boot/)
- [Explain the Architecture of an ASP.NET Core Solution](https://getrush.ai/run/architecture-overview/aspnet-core/)
- [Explain the Architecture of a Django Codebase](https://getrush.ai/run/architecture-overview/django/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
