# igorkasyanchuk/rails_performance architecture

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

- Interactive diagram: https://gitdiagram.com/igorkasyanchuk/rails_performance
- Repository: https://github.com/igorkasyanchuk/rails_performance

## Overview

Rails Performance is a self-hosted Rails APM dashboard. Rails requests are instrumented, collected into request-scoped state, and persisted by middleware; users then browse dashboard reports and widgets. Optional instrumentation covers Sidekiq, Delayed Job, Grape, Rake, custom events, and server resources. The controller excerpt shows dashboard assembly and the engine excerpt shows instrumentation registration, but data-source internals and several adapters/reports are not shown; their detailed links are therefore omitted.

Main entry points: [`lib/rails_performance/engine.rb`](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/engine.rb) (Engine registration), [`app/controllers/rails_performance/rails_performance_controller.rb`](https://github.com/igorkasyanchuk/rails_performance/blob/master/app/controllers/rails_performance/rails_performance_controller.rb) (Dashboard controller), [`lib/rails_performance/rails/middleware.rb`](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/rails/middleware.rb) (Request middleware), [`lib/rails_performance/instrument/metrics_collector.rb`](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/instrument/metrics_collector.rb) (Metrics collector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture and instrumentation"]
  node_middleware["Request middleware<br/>[middleware.rb]"]
  node_metrics_collector["Metrics collector"]
  node_engine["Engine registration<br/>[engine.rb]"]
  node_current_request["Request context<br/>[current_request.rb]"]
end

subgraph group_records["Telemetry records"]
  node_request_record["Request records<br/>[request_record.rb]"]
  node_event_record["Event records<br/>[record.rb]"]
  node_resource_monitor["Resource monitor"]
  node_resource_record["Resource records<br/>[resource_record.rb]"]
end

subgraph group_dashboard["Dashboard and reporting"]
  node_dashboard_routes["Dashboard routes<br/>[routes.rb]"]
  node_dashboard_controller["Dashboard controller"]
  node_access_controller["Access controls<br/>[base_controller.rb]"]
  node_query_builder["Query builder<br/>[query_builder.rb]"]
  node_data_source["Data source<br/>[data_source.rb]"]
  node_reports["Reports"]
  node_widgets["Dashboard widgets"]
  node_browser_assets["Dashboard interface<br/>[charts.js]"]
end

subgraph group_extensions["Optional integrations"]
  node_job_adapters["Job adapters<br/>[sidekiq_ext.rb]"]
  node_delayed_adapter["Delayed Job adapter<br/>[delayed_job_ext.rb]"]
  node_grape_adapter["Grape adapter<br/>[grape_ext.rb]"]
  node_rake_adapter["Rake adapter<br/>[rake_ext.rb]"]
  node_custom_adapter["Custom events<br/>[custom_ext.rb]"]
end

node_app_user(("Dashboard user"))
node_rails_runtime{{"Rails application"}}
node_redis[("Local Redis")]

node_app_user -.->|"opens dashboard"| node_dashboard_routes
node_dashboard_routes -.->|"routes requests"| node_dashboard_controller
node_dashboard_controller -->|"inherits access checks"| node_access_controller
node_dashboard_controller -->|"composes filters"| node_query_builder
node_dashboard_controller -->|"builds queries"| node_data_source
node_dashboard_controller -->|"builds reports"| node_reports
node_dashboard_controller -->|"assembles widgets"| node_widgets
node_widgets -.->|"renders charts"| node_browser_assets
node_rails_runtime -->|"dispatches requests"| node_middleware
node_engine -->|"registers middleware"| node_middleware
node_engine -->|"subscribes metrics"| node_metrics_collector
node_metrics_collector -->|"stores metrics"| node_current_request
node_middleware -->|"reads context"| node_current_request
node_middleware -->|"saves requests"| node_request_record
node_middleware -.->|"stores traces"| node_redis
node_request_record -->|"writes records"| node_redis
node_data_source -.->|"reads telemetry"| node_redis
node_resource_monitor -->|"saves measurements"| node_resource_record
node_resource_record -.->|"stores metrics"| node_redis
node_engine -->|"starts monitoring"| node_resource_monitor
node_engine -->|"registers adapter"| node_job_adapters
node_engine -->|"initializes adapter"| node_delayed_adapter
node_engine -->|"initializes adapter"| node_grape_adapter
node_engine -->|"initializes adapter"| node_rake_adapter
node_custom_adapter -.->|"records events"| node_event_record
node_job_adapters -.->|"records jobs"| node_redis
node_delayed_adapter -.->|"records jobs"| node_redis
node_grape_adapter -.->|"records API metrics"| node_redis
node_rake_adapter -.->|"records task metrics"| node_redis

click node_dashboard_routes "https://github.com/igorkasyanchuk/rails_performance/blob/master/config/routes.rb"
click node_dashboard_controller "https://github.com/igorkasyanchuk/rails_performance/blob/master/app/controllers/rails_performance/rails_performance_controller.rb"
click node_access_controller "https://github.com/igorkasyanchuk/rails_performance/blob/master/app/controllers/rails_performance/base_controller.rb"
click node_query_builder "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/rails/query_builder.rb"
click node_data_source "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/data_source.rb"
click node_reports "https://github.com/igorkasyanchuk/rails_performance/tree/master/lib/rails_performance/reports"
click node_widgets "https://github.com/igorkasyanchuk/rails_performance/tree/master/lib/rails_performance/widgets"
click node_browser_assets "https://github.com/igorkasyanchuk/rails_performance/blob/master/app/engine_assets/javascripts/charts.js"
click node_middleware "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/rails/middleware.rb"
click node_metrics_collector "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/instrument/metrics_collector.rb"
click node_engine "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/engine.rb"
click node_current_request "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/thread/current_request.rb"
click node_request_record "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/models/request_record.rb"
click node_event_record "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/events/record.rb"
click node_resource_monitor "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/system_monitor/resources_monitor.rb"
click node_resource_record "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/models/resource_record.rb"
click node_job_adapters "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/sidekiq_ext.rb"
click node_delayed_adapter "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/delayed_job_ext.rb"
click node_grape_adapter "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/grape_ext.rb"
click node_rake_adapter "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/rake_ext.rb"
click node_custom_adapter "https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/custom_ext.rb"

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_middleware,node_metrics_collector,node_engine,node_current_request,node_app_user toneBlue
class node_request_record,node_event_record,node_resource_monitor,node_resource_record,node_redis toneAmber
class node_dashboard_routes,node_dashboard_controller,node_access_controller,node_query_builder,node_data_source,node_reports,node_widgets,node_browser_assets toneMint
class node_job_adapters,node_delayed_adapter,node_grape_adapter,node_rake_adapter,node_custom_adapter toneRose
class node_rails_runtime toneIndigo
```

## Components

### Capture and instrumentation

- [Request middleware](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/rails/middleware.rb): `lib/rails_performance/rails/middleware.rb`
- [Metrics collector](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/instrument/metrics_collector.rb): `lib/rails_performance/instrument/metrics_collector.rb`
- [Engine registration](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/engine.rb): `lib/rails_performance/engine.rb`
- [Request context](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/thread/current_request.rb): `lib/rails_performance/thread/current_request.rb`

### Telemetry records

- [Request records](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/models/request_record.rb): `lib/rails_performance/models/request_record.rb`
- [Event records](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/events/record.rb): `lib/rails_performance/events/record.rb`
- [Resource monitor](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/system_monitor/resources_monitor.rb): `lib/rails_performance/system_monitor/resources_monitor.rb`
- [Resource records](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/models/resource_record.rb): `lib/rails_performance/models/resource_record.rb`

### Dashboard and reporting

- [Dashboard routes](https://github.com/igorkasyanchuk/rails_performance/blob/master/config/routes.rb): `config/routes.rb`
- [Dashboard controller](https://github.com/igorkasyanchuk/rails_performance/blob/master/app/controllers/rails_performance/rails_performance_controller.rb): `app/controllers/rails_performance/rails_performance_controller.rb`
- [Access controls](https://github.com/igorkasyanchuk/rails_performance/blob/master/app/controllers/rails_performance/base_controller.rb): `app/controllers/rails_performance/base_controller.rb`
- [Query builder](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/rails/query_builder.rb): `lib/rails_performance/rails/query_builder.rb`
- [Data source](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/data_source.rb): `lib/rails_performance/data_source.rb`
- [Reports](https://github.com/igorkasyanchuk/rails_performance/tree/master/lib/rails_performance/reports): `lib/rails_performance/reports`
- [Dashboard widgets](https://github.com/igorkasyanchuk/rails_performance/tree/master/lib/rails_performance/widgets): `lib/rails_performance/widgets`
- [Dashboard interface](https://github.com/igorkasyanchuk/rails_performance/blob/master/app/engine_assets/javascripts/charts.js): `app/engine_assets/javascripts/charts.js`

### Optional integrations

- [Job adapters](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/sidekiq_ext.rb): `lib/rails_performance/gems/sidekiq_ext.rb`
- [Delayed Job adapter](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/delayed_job_ext.rb): `lib/rails_performance/gems/delayed_job_ext.rb`
- [Grape adapter](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/grape_ext.rb): `lib/rails_performance/gems/grape_ext.rb`
- [Rake adapter](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/rake_ext.rb): `lib/rails_performance/gems/rake_ext.rb`
- [Custom events](https://github.com/igorkasyanchuk/rails_performance/blob/master/lib/rails_performance/gems/custom_ext.rb): `lib/rails_performance/gems/custom_ext.rb`

### Other components

- **Dashboard user**
- **Rails application**
- **Local Redis**

## Connections

- Dashboard user → Dashboard routes: opens dashboard
- Dashboard routes → Dashboard controller: routes requests
- Dashboard controller → Access controls: inherits access checks (evidence: `app/controllers/rails_performance/rails_performance_controller.rb`)
- Dashboard controller → Query builder: composes filters (evidence: `app/controllers/rails_performance/rails_performance_controller.rb`)
- Dashboard controller → Data source: builds queries (evidence: `app/controllers/rails_performance/rails_performance_controller.rb`)
- Dashboard controller → Reports: builds reports (evidence: `app/controllers/rails_performance/rails_performance_controller.rb`)
- Dashboard controller → Dashboard widgets: assembles widgets (evidence: `app/controllers/rails_performance/rails_performance_controller.rb`)
- Dashboard widgets → Dashboard interface: renders charts
- Rails application → Request middleware: dispatches requests
- Engine registration → Request middleware: registers middleware (evidence: `lib/rails_performance/engine.rb`)
- Engine registration → Metrics collector: subscribes metrics (evidence: `lib/rails_performance/engine.rb`)
- Metrics collector → Request context: stores metrics (evidence: `lib/rails_performance/instrument/metrics_collector.rb`)
- Request middleware → Request context: reads context (evidence: `lib/rails_performance/rails/middleware.rb`)
- Request middleware → Request records: saves requests (evidence: `lib/rails_performance/rails/middleware.rb`)
- Request middleware → Local Redis: stores traces
- Request records → Local Redis: writes records (evidence: `lib/rails_performance/models/request_record.rb`)
- Data source → Local Redis: reads telemetry
- Resource monitor → Resource records: saves measurements (evidence: `lib/rails_performance/system_monitor/resources_monitor.rb`)
- Resource records → Local Redis: stores metrics
- Engine registration → Resource monitor: starts monitoring (evidence: `lib/rails_performance/engine.rb`)
- Engine registration → Job adapters: registers adapter (evidence: `lib/rails_performance/engine.rb`)
- Engine registration → Delayed Job adapter: initializes adapter (evidence: `lib/rails_performance/engine.rb`)
- Engine registration → Grape adapter: initializes adapter (evidence: `lib/rails_performance/engine.rb`)
- Engine registration → Rake adapter: initializes adapter (evidence: `lib/rails_performance/engine.rb`)
- Custom events → Event records: records events
- Job adapters → Local Redis: records jobs
- Delayed Job adapter → Local Redis: records jobs
- Grape adapter → Local Redis: records API metrics
- Rake adapter → Local Redis: records task metrics
