# krystofwoldrich/pr-agent architecture

> Architecture diagram of the GitHub repository krystofwoldrich/pr-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krystofwoldrich/pr-agent
- Repository: https://github.com/krystofwoldrich/pr-agent

## Overview

PR Agent is a VS Code extension that inserts the current or next pull-request number, or a Markdown link, at the editor cursor. Commands are handled in the extension: it inspects the active file’s Git repository, obtains a number from GitHub, formats it, and edits the document. Current-number lookup follows the branch’s associated pull request; next-number lookup compares the latest issue, discussion, and pull-request numbers. The source excerpts show these calls directly; repository capabilities are documented in the README and command contributions in package.json.

Main entry points: [`src/extension.ts`](https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts) (Insert workflow), [`src/secrets.ts`](https://github.com/krystofwoldrich/pr-agent/blob/main/src/secrets.ts) (Token management), [`src/api.ts`](https://github.com/krystofwoldrich/pr-agent/blob/main/src/api.ts) (GitHub GraphQL client), [`src/git.ts`](https://github.com/krystofwoldrich/pr-agent/blob/main/src/git.ts) (Repository and branch context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["VS Code interaction"]
  node_commands["PR commands<br/>[extension.ts]"]
  node_request["Insert workflow<br/>[extension.ts]"]
  node_selection["Remote and PR selection<br/>[extension.ts]"]
  node_secrets["Token management<br/>[secrets.ts]"]
end

subgraph group_git["Git context"]
  node_gitcontext["Repository and branch context<br/>[git.ts]"]
  node_gitmetadata["Local Git metadata"]
end

subgraph group_github["GitHub lookup"]
  node_current["Current PR lookup<br/>[extension.ts]"]
  node_next["Next number lookup<br/>[extension.ts]"]
  node_api["GitHub GraphQL client<br/>[api.ts]"]
end

subgraph group_output["Formatting and output"]
  node_templates["Markdown templates<br/>[template.ts]"]
  node_editor["Active editor insertion<br/>[extension.ts]"]
end

node_user(("Extension user"))
node_githubservice{{"GitHub GraphQL API"}}
node_secretstore[("VS Code secret storage")]

node_user -->|"runs command"| node_commands
node_commands -->|"starts workflow"| node_request
node_request -->|"reads repository"| node_gitcontext
node_gitcontext -->|"reads metadata"| node_gitmetadata
node_request -->|"prompts choices"| node_selection
node_request -->|"gets token"| node_secrets
node_request -->|"clears token"| node_secrets
node_secrets -.->|"reads or clears"| node_secretstore
node_request -->|"resolves current"| node_current
node_request -->|"resolves next"| node_next
node_current -->|"fetches associated PRs"| node_api
node_next -->|"fetches latest numbers"| node_api
node_api -->|"sends GraphQL request"| node_githubservice
node_request -->|"formats result"| node_templates
node_request -->|"inserts content"| node_editor

click node_commands "https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts"
click node_request "https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts"
click node_selection "https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts"
click node_gitcontext "https://github.com/krystofwoldrich/pr-agent/blob/main/src/git.ts"
click node_current "https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts"
click node_next "https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts"
click node_api "https://github.com/krystofwoldrich/pr-agent/blob/main/src/api.ts"
click node_secrets "https://github.com/krystofwoldrich/pr-agent/blob/main/src/secrets.ts"
click node_templates "https://github.com/krystofwoldrich/pr-agent/blob/main/src/template.ts"
click node_editor "https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_commands,node_request,node_selection,node_secrets,node_user toneBlue
class node_gitcontext,node_gitmetadata,node_secretstore toneAmber
class node_current,node_next,node_api,node_githubservice toneMint
class node_templates,node_editor toneRose
```

## Components

### VS Code interaction

- [PR commands](https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts): `src/extension.ts`
- [Insert workflow](https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts): `src/extension.ts`
- [Remote and PR selection](https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts): `src/extension.ts`
- [Token management](https://github.com/krystofwoldrich/pr-agent/blob/main/src/secrets.ts): `src/secrets.ts`

### Git context

- [Repository and branch context](https://github.com/krystofwoldrich/pr-agent/blob/main/src/git.ts): `src/git.ts`
- **Local Git metadata**

### GitHub lookup

- [Current PR lookup](https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts): `src/extension.ts`
- [Next number lookup](https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts): `src/extension.ts`
- [GitHub GraphQL client](https://github.com/krystofwoldrich/pr-agent/blob/main/src/api.ts): `src/api.ts`

### Formatting and output

- [Markdown templates](https://github.com/krystofwoldrich/pr-agent/blob/main/src/template.ts): `src/template.ts`
- [Active editor insertion](https://github.com/krystofwoldrich/pr-agent/blob/main/src/extension.ts): `src/extension.ts`

### Other components

- **Extension user**
- **GitHub GraphQL API**
- **VS Code secret storage**

## Connections

- Extension user → PR commands: runs command
- PR commands → Insert workflow: starts workflow (evidence: `src/extension.ts`)
- Insert workflow → Repository and branch context: reads repository (evidence: `src/extension.ts`)
- Repository and branch context → Local Git metadata: reads metadata (evidence: `src/git.ts`)
- Insert workflow → Remote and PR selection: prompts choices (evidence: `src/extension.ts`)
- Insert workflow → Token management: gets token (evidence: `src/extension.ts`)
- Insert workflow → Token management: clears token (evidence: `src/extension.ts`)
- Token management → VS Code secret storage: reads or clears
- Insert workflow → Current PR lookup: resolves current (evidence: `src/extension.ts`)
- Insert workflow → Next number lookup: resolves next (evidence: `src/extension.ts`)
- Current PR lookup → GitHub GraphQL client: fetches associated PRs (evidence: `src/extension.ts`)
- Next number lookup → GitHub GraphQL client: fetches latest numbers (evidence: `src/extension.ts`)
- GitHub GraphQL client → GitHub GraphQL API: sends GraphQL request (evidence: `src/api.ts`)
- Insert workflow → Markdown templates: formats result (evidence: `src/extension.ts`)
- Insert workflow → Active editor insertion: inserts content (evidence: `src/extension.ts`)
