# thlorenz/deoptigate architecture

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

- Interactive diagram: https://gitdiagram.com/thlorenz/deoptigate
- Repository: https://github.com/thlorenz/deoptigate

## Overview

1. **What the repository is**
   - `deoptigate` is a Node.js CLI plus a browser-based report viewer for V8 performance logs.
   - Its core job is to take either an app entrypoint or an existing `*-v8.log`, parse optimization/deoptimization data, and present it grouped by source file and code location.

2. **Primary execution paths**
   - The CLI can start from source code: `deoptigate app.js`.
   - Or it can start from preexisting logs in the current directory.
   - In the “app.js” flow, the tool launches Node with V8 logging enabled, produces a log, then analyzes it.

3. **CLI / process boundary**
   - The `bin/` scripts are the user-facing entrypoints:
     - `deoptigate` is the main command.
     - `deoptigate.create-log.js`, `deoptigate.find-log.js`, and `deoptigate.open-log.js` support log creation, discovery, and opening.
   - This is the boundary where filesystem access and subprocess execution happen; everything after that is log analysis and UI generation.

4. **Log ingestion and parsing**
   - `lib/line-reader.js` suggests streaming log processing rather than loading the whole file at once.
   - `lib/log-processing/` contains the typed record parsers and models for the V8 log stream:
     - `code-entry.js`
     - `deopt-entry.js`
     - `ic-entry.js`
     - `ic-state.js`
     - `optimization-state.js`
   - These modules turn raw log lines into structured events the rest of the system can aggregate.

5. **Analysis and severity classification**
   - `lib/severities.js` likely maps parsed events into user-facing importance levels.
   - The optimization and IC state modules indicate the tool distinguishes deoptimizations, inline cache transitions, and code/optimization lifecycle events rather than treating the log as a single generic event stream.

6. **Source-file and location grouping**
   - `lib/grouping/` is the main analysis layer that turns event streams into reportable units:
     - `resolve-files.js` binds log references back to actual source files.
     - `location.js` represents a file/line/column-style location boundary.
     - `group-by-file.js` and `group-by-file-and-location.js` aggregate events at different granularities.
     - `summarize-file.js` builds file-level rollups.
   - This is the key data-model transformation: raw V8 events → grouped per file/location summaries.

7. **Rendering and code annotation**
   - `lib/rendering/` handles how source code is visually marked in the report.
   - `marker-resolver.js` and `mark-only.js` suggest a separation between deciding what to highlight and actually applying highlight/marker output.
   - The output is an annotated code view tied to the grouped analysis results.

8. **Browser application**
   - `app/` is the front-end report UI.
   - `app/components/` contains the main panels:
     - `files.js` for file navigation,
     - `summary.js` for aggregate results,
     - `file-details.js` for per-file inspection,
     - `code.js` for source display,
     - `toolbar.js` for filtering/navigation controls.
   - `app/lib/` contains browser-specific support such as:
     - `query-state.js` for URL/state synchronization,
     - `create-page.js` for assembling the report page,
     - `save-parts.js` for packaging/splitting report artifacts.

9. **Generated frontend artifacts**
   - `app/build/` contains built assets (`deoptigate.js`, `deoptigate.css`) that are shipped to render the report.
   - This implies the browser UI is compiled separately from the Node analysis pipeline.

10. **Overall data flow**
   - Input is either a Node program or an existing V8 log file.
   - The CLI acquires or finds the log, parses it into typed entries, groups and summarizes those entries by file and location, then feeds that data into the browser UI.
   - The browser side renders summaries and code annotations, with URL/query state preserving selection and filters.

11. **Repo testing and fixtures**
   - Tests live under `test/` and use real log fixtures in `test/logs/` such as `adders.v8.log` and `two-modules.v8.log`.
   - This indicates the analysis pipeline is validated against representative V8 output, not mocked abstractions.

12. **Important architectural boundary to draw**
   - The clearest split is:
     - **Node/CLI + log processing + grouping** on one side,
     - **browser report rendering** on the other.
   - The only shared contract between them is the structured analysis result derived from V8 logs and source-file resolution.

Main entry points: [`app/lib/create-page.js`](https://github.com/thlorenz/deoptigate/blob/master/app/lib/create-page.js) (create page), [`lib/log-processing`](https://github.com/thlorenz/deoptigate/tree/master/lib/log-processing) (log parsing), [`lib/grouping`](https://github.com/thlorenz/deoptigate/tree/master/lib/grouping) (grouping), [`deoptigate.log.js`](https://github.com/thlorenz/deoptigate/blob/master/deoptigate.log.js) (log model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI + analysis"]
  node_bin_main["deoptigate<br/>CLI entrypoint"]
  node_bin_create_log["create log<br/>CLI helper"]
  node_bin_find_log["find log<br/>CLI helper"]
  node_bin_open_log["open log<br/>CLI helper"]
  node_log_root["log model<br/>analysis core<br/>[deoptigate.log.js]"]
  node_line_reader["line reader<br/>stream parser<br/>[line-reader.js]"]
  node_log_processing[("log parsing<br/>typed records")]
  node_code_entry["code entry<br/>record type<br/>[code-entry.js]"]
  node_deopt_entry["deopt entry<br/>record type<br/>[deopt-entry.js]"]
  node_ic_entry["IC entry<br/>record type<br/>[ic-entry.js]"]
  node_grouping[("grouping<br/>analysis layer")]
  node_resolve_files["resolve files<br/>source resolution<br/>[resolve-files.js]"]
  node_group_file_loc["file + location<br/>aggregation"]
  node_summarize_file["file summary<br/>rollup<br/>[summarize-file.js]"]
  node_rendering[("rendering<br/>annotation layer")]
  node_marker_resolver["marker resolver<br/>annotation logic<br/>[marker-resolver.js]"]
end

subgraph group_ui["Browser report"]
  node_app_main["app shell<br/>browser entry<br/>[main.js]"]
  node_create_page["create page<br/>page assembly<br/>[create-page.js]"]
  node_query_state["query state<br/>ui state<br/>[query-state.js]"]
  node_files_comp["files<br/>[files.js]"]
  node_summary_comp["summary<br/>[summary.js]"]
  node_details_comp["details<br/>[file-details.js]"]
  node_code_comp["code view<br/>[code.js]"]
  node_toolbar_comp["toolbar<br/>[toolbar.js]"]
  node_ui_bundle["built UI<br/>browser assets<br/>[deoptigate.js]"]
end

subgraph group_samples["Examples + tests"]
  node_example_adders["adders example<br/>sample app<br/>[adders.js]"]
  node_example_two_modules["two modules<br/>sample app<br/>[adders.js]"]
  node_test_logs["log fixtures<br/>test data<br/>[adders.v8.log]"]
end

node_bin_main -->|"creates log"| node_bin_create_log
node_bin_main -->|"discovers log"| node_bin_find_log
node_bin_main -->|"opens log"| node_bin_open_log
node_bin_create_log -->|"produces input"| node_log_root
node_bin_find_log -->|"selects input"| node_log_root
node_bin_open_log -->|"loads analysis"| node_log_root
node_log_root -->|"streams"| node_line_reader
node_line_reader -->|"feeds lines"| node_log_processing
node_log_processing -->|"parses"| node_code_entry
node_log_processing -->|"parses"| node_deopt_entry
node_log_processing -->|"parses"| node_ic_entry
node_log_processing -->|"aggregates into"| node_grouping
node_grouping -->|"resolves"| node_resolve_files
node_grouping -->|"groups by"| node_group_file_loc
node_group_file_loc -->|"rolls up"| node_summarize_file
node_grouping -->|"supplies markers"| node_rendering
node_rendering -->|"decides highlights"| node_marker_resolver
node_app_main -->|"assembles"| node_create_page
node_create_page -->|"syncs state"| node_query_state
node_create_page -->|"renders"| node_files_comp
node_create_page -->|"renders"| node_summary_comp
node_create_page -->|"renders"| node_details_comp
node_create_page -->|"renders"| node_code_comp
node_create_page -->|"renders"| node_toolbar_comp
node_app_main -->|"uses build"| node_ui_bundle
node_test_logs -.->|"validates"| node_log_processing
node_example_adders -.->|"exercises"| node_bin_create_log
node_example_two_modules -.->|"exercises"| node_grouping

click node_bin_main "https://github.com/thlorenz/deoptigate/tree/master/bin/deoptigate"
click node_bin_create_log "https://github.com/thlorenz/deoptigate/blob/master/bin/deoptigate.create-log.js"
click node_bin_find_log "https://github.com/thlorenz/deoptigate/blob/master/bin/deoptigate.find-log.js"
click node_bin_open_log "https://github.com/thlorenz/deoptigate/blob/master/bin/deoptigate.open-log.js"
click node_log_root "https://github.com/thlorenz/deoptigate/blob/master/deoptigate.log.js"
click node_line_reader "https://github.com/thlorenz/deoptigate/blob/master/lib/line-reader.js"
click node_log_processing "https://github.com/thlorenz/deoptigate/tree/master/lib/log-processing"
click node_code_entry "https://github.com/thlorenz/deoptigate/blob/master/lib/log-processing/code-entry.js"
click node_deopt_entry "https://github.com/thlorenz/deoptigate/blob/master/lib/log-processing/deopt-entry.js"
click node_ic_entry "https://github.com/thlorenz/deoptigate/blob/master/lib/log-processing/ic-entry.js"
click node_grouping "https://github.com/thlorenz/deoptigate/tree/master/lib/grouping"
click node_resolve_files "https://github.com/thlorenz/deoptigate/blob/master/lib/grouping/resolve-files.js"
click node_group_file_loc "https://github.com/thlorenz/deoptigate/blob/master/lib/grouping/group-by-file-and-location.js"
click node_summarize_file "https://github.com/thlorenz/deoptigate/blob/master/lib/grouping/summarize-file.js"
click node_rendering "https://github.com/thlorenz/deoptigate/tree/master/lib/rendering"
click node_marker_resolver "https://github.com/thlorenz/deoptigate/blob/master/lib/rendering/marker-resolver.js"
click node_app_main "https://github.com/thlorenz/deoptigate/blob/master/app/main.js"
click node_create_page "https://github.com/thlorenz/deoptigate/blob/master/app/lib/create-page.js"
click node_query_state "https://github.com/thlorenz/deoptigate/blob/master/app/lib/query-state.js"
click node_files_comp "https://github.com/thlorenz/deoptigate/blob/master/app/components/files.js"
click node_summary_comp "https://github.com/thlorenz/deoptigate/blob/master/app/components/summary.js"
click node_details_comp "https://github.com/thlorenz/deoptigate/blob/master/app/components/file-details.js"
click node_code_comp "https://github.com/thlorenz/deoptigate/blob/master/app/components/code.js"
click node_toolbar_comp "https://github.com/thlorenz/deoptigate/blob/master/app/components/toolbar.js"
click node_ui_bundle "https://github.com/thlorenz/deoptigate/blob/master/app/build/deoptigate.js"
click node_example_adders "https://github.com/thlorenz/deoptigate/blob/master/examples/simple/adders.js"
click node_example_two_modules "https://github.com/thlorenz/deoptigate/blob/master/examples/two-modules/adders.js"
click node_test_logs "https://github.com/thlorenz/deoptigate/blob/master/test/logs/adders.v8.log"

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_bin_main,node_bin_create_log,node_bin_find_log,node_bin_open_log,node_log_root,node_line_reader,node_log_processing,node_code_entry,node_deopt_entry,node_ic_entry,node_grouping,node_resolve_files,node_group_file_loc,node_summarize_file,node_rendering,node_marker_resolver toneBlue
class node_app_main,node_create_page,node_query_state,node_files_comp,node_summary_comp,node_details_comp,node_code_comp,node_toolbar_comp,node_ui_bundle toneAmber
class node_example_adders,node_example_two_modules,node_test_logs toneMint
```

## Components

### CLI + analysis

Node entrypoints, log acquisition, parsing, grouping, and report generation.

- [deoptigate](https://github.com/thlorenz/deoptigate/tree/master/bin/deoptigate): CLI entrypoint · Main command for launching analysis from an app or an existing V8 log. · `bin/deoptigate`
- [create log](https://github.com/thlorenz/deoptigate/blob/master/bin/deoptigate.create-log.js): CLI helper · Starts Node with V8 logging enabled to generate a fresh log. · `bin/deoptigate.create-log.js`
- [find log](https://github.com/thlorenz/deoptigate/blob/master/bin/deoptigate.find-log.js): CLI helper · Discovers existing V8 log files in the working directory. · `bin/deoptigate.find-log.js`
- [open log](https://github.com/thlorenz/deoptigate/blob/master/bin/deoptigate.open-log.js): CLI helper · Opens a generated or discovered log for analysis/reporting. · `bin/deoptigate.open-log.js`
- [log model](https://github.com/thlorenz/deoptigate/blob/master/deoptigate.log.js): analysis core · Top-level log analysis and orchestration contract. · `deoptigate.log.js`
- [line reader](https://github.com/thlorenz/deoptigate/blob/master/lib/line-reader.js): stream parser · Streaming reader for V8 log ingestion. · `lib/line-reader.js`
- [log parsing](https://github.com/thlorenz/deoptigate/tree/master/lib/log-processing): typed records · Parses raw V8 log lines into structured optimization, IC, and deopt records. · `lib/log-processing`
- [code entry](https://github.com/thlorenz/deoptigate/blob/master/lib/log-processing/code-entry.js): record type · Represents code-related log records. · `lib/log-processing/code-entry.js`
- [deopt entry](https://github.com/thlorenz/deoptigate/blob/master/lib/log-processing/deopt-entry.js): record type · Represents deoptimization events. · `lib/log-processing/deopt-entry.js`
- [IC entry](https://github.com/thlorenz/deoptigate/blob/master/lib/log-processing/ic-entry.js): record type · Represents inline-cache events. · `lib/log-processing/ic-entry.js`
- [grouping](https://github.com/thlorenz/deoptigate/tree/master/lib/grouping): analysis layer · Resolves source files and aggregates events by file and location. · `lib/grouping`
- [resolve files](https://github.com/thlorenz/deoptigate/blob/master/lib/grouping/resolve-files.js): source resolution · Maps log references back to concrete source files. · `lib/grouping/resolve-files.js`
- [file + location](https://github.com/thlorenz/deoptigate/blob/master/lib/grouping/group-by-file-and-location.js): aggregation · Groups events by file and code location. · `lib/grouping/group-by-file-and-location.js`
- [file summary](https://github.com/thlorenz/deoptigate/blob/master/lib/grouping/summarize-file.js): rollup · Builds per-file summaries from grouped events. · `lib/grouping/summarize-file.js`
- [rendering](https://github.com/thlorenz/deoptigate/tree/master/lib/rendering): annotation layer · Turns grouped analysis into highlighted source annotations. · `lib/rendering`
- [marker resolver](https://github.com/thlorenz/deoptigate/blob/master/lib/rendering/marker-resolver.js): annotation logic · Decides what should be highlighted in source output. · `lib/rendering/marker-resolver.js`

### Browser report

Front-end components and browser-side report assembly.

- [app shell](https://github.com/thlorenz/deoptigate/blob/master/app/main.js): browser entry · Browser application bootstrap for the report UI. · `app/main.js`
- [create page](https://github.com/thlorenz/deoptigate/blob/master/app/lib/create-page.js): page assembly · Assembles the browser report page from analysis results. · `app/lib/create-page.js`
- [query state](https://github.com/thlorenz/deoptigate/blob/master/app/lib/query-state.js): ui state · Synchronizes selection and filters with the URL/state. · `app/lib/query-state.js`
- [files](https://github.com/thlorenz/deoptigate/blob/master/app/components/files.js): File navigation panel. · `app/components/files.js`
- [summary](https://github.com/thlorenz/deoptigate/blob/master/app/components/summary.js): Aggregate results panel. · `app/components/summary.js`
- [details](https://github.com/thlorenz/deoptigate/blob/master/app/components/file-details.js): Per-file inspection view. · `app/components/file-details.js`
- [code view](https://github.com/thlorenz/deoptigate/blob/master/app/components/code.js): Annotated source display. · `app/components/code.js`
- [toolbar](https://github.com/thlorenz/deoptigate/blob/master/app/components/toolbar.js): Filtering and navigation controls. · `app/components/toolbar.js`
- [built UI](https://github.com/thlorenz/deoptigate/blob/master/app/build/deoptigate.js): browser assets · Compiled browser JavaScript and CSS shipped with the report. · `app/build/deoptigate.js`

### Examples + tests

Representative inputs and validation fixtures.

- [adders example](https://github.com/thlorenz/deoptigate/blob/master/examples/simple/adders.js): sample app · Minimal V8 logging example used to exercise the pipeline. · `examples/simple/adders.js`
- [two modules](https://github.com/thlorenz/deoptigate/blob/master/examples/two-modules/adders.js): sample app · Multi-file example for cross-file grouping behavior. · `examples/two-modules/adders.js`
- [log fixtures](https://github.com/thlorenz/deoptigate/blob/master/test/logs/adders.v8.log): test data · Real V8 log fixtures used to validate parsing and grouping. · `test/logs/adders.v8.log`

## Connections

- deoptigate → create log: creates log · Starts a logged Node run when given an app entrypoint.
- deoptigate → find log: discovers log · Locates existing V8 log files in the current directory.
- deoptigate → open log: opens log · Hands a chosen log off for analysis and viewing.
- create log → log model: produces input · Emits the log artifact consumed by analysis.
- find log → log model: selects input · Provides an existing log to the analysis pipeline.
- open log → log model: loads analysis · Connects the chosen log to the shared analysis flow.
- log model → line reader: streams · Reads log contents incrementally.
- line reader → log parsing: feeds lines · Supplies raw log lines to typed parsers.
- log parsing → code entry: parses · Creates code-related records.
- log parsing → deopt entry: parses · Creates deoptimization records.
- log parsing → IC entry: parses · Creates inline-cache records.
- log parsing → grouping: aggregates into · Hands structured records to the grouping layer.
- grouping → resolve files: resolves · Maps log references to real source files.
- grouping → file + location: groups by · Aggregates events by file and location.
- file + location → file summary: rolls up · Produces file-level summaries.
- grouping → rendering: supplies markers · Passes grouped analysis to annotation generation.
- rendering → marker resolver: decides highlights · Determines source markers and emphasis.
- app shell → create page: assembles · Builds the report page from analysis output.
- create page → query state: syncs state · Keeps view selection and filters in the URL.
- create page → files: renders · Displays file navigation.
- create page → summary: renders · Displays the summary panel.
- create page → details: renders · Displays per-file details.
- create page → code view: renders · Displays annotated code.
- create page → toolbar: renders · Displays filtering controls.
- app shell → built UI: uses build · Loads compiled browser assets for the report UI.
- log fixtures → log parsing: validates · Fixture logs exercise the parser and grouping pipeline.
- adders example → create log: exercises · Simple app used to generate and analyze a log.
- two modules → grouping: exercises · Multi-module sample validates grouping across files.
