# Explain the Architecture of a Go Codebase

An agent maps a Go server's packages and data models and traces one message from HTTP POST to websocket, with a file:line at each of 10 hops.

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

## What the agent does

The agent starts at `go.mod` (`github.com/gotify/server/v3`) and `app.go`, where `serve()` loads config, opens the database with `database.New`, builds the gin engine with `router.Create` and blocks in `runner.Run`. Before writing a line it runs `go build ./...` and `go test ./...` on the untouched clone, and both fail: `ui/serve.go` embeds the git-ignored `ui/build/`, and with no C compiler go-sqlite3 returns a stub error.

It installs `gcc`, runs `yarn build` in `ui/`, and changes no tracked file. Then it reads `router/router.go`, `auth/authentication.go`, `api/message.go`, `database/message.go`, `api/stream/stream.go`, `api/stream/client.go` and `plugin/manager.go`, and rechecks its cited lines with `grep -n`, fixing five that pointed at the wrong line.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Write architecture.md for this Go repository: the commit, the module and its executable entry point; the main components with the package that owns each; the data models and how they are stored; and one request traced end to end with file:line at each hop. Run go build ./... and go test ./... before and after, report any setup the clone needs to pass them, and verify every cited line against the source. Change no application code.",
  "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 gotify/server at dd06dc7: 1 file changed, 66 insertions(+), a new `architecture.md` with a 9-row component table, 5 data models (`User`, `Application`, `Client`, `Message`, `PluginConf`) and a 10-hop trace from `router/router.go:210` to `ui/src/message/WebSocketStore.ts:30`. After the setup, `go build ./...` exited 0 and `go test ./...` passed, ending `ok  	github.com/gotify/server/v3/test/testdb	0.026s`.

For the reviewer: whether `architecture.md` belongs at the root or under `docs/`. The trace is read from code; no server ran and no message was sent, though the `api` and `api/stream` tests pass. The UI's JavaScript tests were not run.

## Run it on every merged pull request touching storage or the stream

An automation with a `github` trigger on `pull_request.closed.merged`, `branch_patterns` set to `master` and `labels` set to `database` or `stream`, runs this prompt after the change lands. The new document's hop list, diffed against the last one, shows a moved handler or a new step in the path.

## Why run it on Rush?

The document records what a new contributor hits first: a fresh clone does not build, because the UI is embedded but never committed, and the tests need cgo for SQLite. It also found that migrations disable foreign keys, so relations between users, applications and messages are enforced in code, not by the database.

## Frequently asked questions

### Does the trace cover messages sent by plugins?

Yes, as a variant. A plugin's `SendMessage` pushes onto a channel, and the goroutine started in `NewManager` saves it with `db.CreateMessage` and calls `notifier.Notify`, joining the HTTP path at the stream registry.

### How does a sent message find the right sockets?

`stream.API` keeps `clients` keyed by user id. `Notify` takes a read lock, looks up that user's clients and writes the message to each one's channel, skipping closed ones; each socket's write goroutine sends it as JSON.

## More Go jobs

- [Find Dead Code in a Go Project](https://getrush.ai/run/find-dead-code/go/)
- [Fix a Go Service Bug From a Datadog Monitor Alert](https://getrush.ai/run/fix-datadog-alerts/go/)
- [Fix Failing GitHub Actions Checks in a Go Service](https://getrush.ai/run/fix-failing-ci/go/)

## The same job on other stacks

- [Explain the Architecture of a Rails Codebase](https://getrush.ai/run/architecture-overview/rails/)
- [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/)

## 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/)
