# sungbinlee/tk-incidentreporter architecture

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

- Interactive diagram: https://gitdiagram.com/sungbinlee/tk-incidentreporter
- Repository: https://github.com/sungbinlee/tk-incidentreporter

## Overview

1. **What this repository is**
   - `tk-incidentreporter` is a small Python desktop app for the FPTR Toolkit (`sgtk`) environment.
   - Its purpose is to watch client-side `tk-*.log` files, detect incident-like lines, and create a Ticket with the log attached.

2. **Top-level runtime shape**
   - The app is packaged as a Toolkit app, not a standalone service.
   - `app.py` is the visible entry point, while the real behavior lives under `python/tk_incident/`.
   - `info.yml` likely provides Toolkit app metadata used by the SGTK loader.

3. **Main control boundary**
   - `python/tk_incident/bootstrap.py` is the startup/orchestration layer.
   - It likely wires together configuration, the long-running log tailing worker, the matching logic, and the upload/Ticket creation path.
   - This is the boundary between the desktop app host and the incident-reporting pipeline.

4. **Log monitoring subsystem**
   - `python/tk_incident/tail_worker.py` is the file-watching/streaming component.
   - It is responsible for following active log files and emitting new lines or log events as they arrive.
   - The readme indicates it targets `tk-*.log` files on the local machine.

5. **Incident detection subsystem**
   - `python/tk_incident/matcher.py` contains the pattern-detection logic.
   - The MVP uses regex-based matching for `ERROR|CRITICAL`.
   - This layer converts raw log lines into “incident candidates” with the information needed to create a Ticket.

6. **Ticket creation / upload subsystem**
   - `python/tk_incident/uploader.py` is the integration boundary to FPTR/ShotGrid-style backend services.
   - It appears to create Tickets, attach the relevant log file, and likely send metadata such as the matched line, timestamp, user, and byte offset.
   - This is the only subsystem that should know about remote API details.

7. **De-duplication and flood control**
   - The app uses title-signature de-duplication to avoid creating repeated Tickets.
   - The readme defines the title as `"<user_login> - <ErrorName or short message>"`; if that title already exists, the report is skipped.
   - That logic likely sits in the upload path or a closely related coordination layer, because it depends on candidate details plus existing remote state.

8. **Process-wide lifecycle / singleton behavior**
   - `python/tk_incident/singleton.py` suggests the app enforces a single running instance.
   - In a desktop log-watcher, this is important to prevent multiple watchers from creating duplicate Tickets from the same incidents.
   - This is a host/process boundary rather than a business-logic layer.

9. **Agent abstraction**
   - `python/tk_incident/agent.py` likely represents the main application agent or controller object.
   - It probably owns the coordination between the bootstrap code, the worker, the matcher, and the uploader.
   - In an architecture diagram, this is the central orchestration node inside the app process.

10. **End-to-end data flow**
   - Local `tk-*.log` files are tailed.
   - New lines are passed through regex matching.
   - Matching incidents are enriched with context like user, timestamp, path, and offset.
   - The uploader creates a Ticket in the backend and attaches the log file.
   - Duplicate titles short-circuit the creation path.

11. **External boundaries**
   - The main external system is the FPTR/ShotGrid backend where Tickets are created.
   - The app also depends on the local filesystem and log files generated by the client desktop environment.
   - The surrounding host is the SGTK/Tk Desktop runtime, which provides the app execution context.

12. **Architectural summary**
   - This repo is a small event-driven desktop integration: filesystem input, pattern matching, remote ticket creation.
   - The important boundaries for a diagram are: desktop host/bootstrap, singleton process guard, log tailing, incident matcher, and backend uploader/de-duplication.

Main entry points: [`python/tk_incident/uploader.py`](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/uploader.py) (Uploader), [`app.py`](https://github.com/sungbinlee/tk-incidentreporter/blob/main/app.py) (app.py), [`python/tk_incident/bootstrap.py`](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/bootstrap.py) (Bootstrap), [`python/tk_incident/agent.py`](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/agent.py) (Agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["Toolkit host"]
  node_app_py["app.py<br/>entrypoint<br/>[app.py]"]
  node_info_yml["info.yml<br/>metadata<br/>[info.yml]"]
  node_bootstrap["Bootstrap<br/>orchestrator<br/>[bootstrap.py]"]
  node_singleton{{"Singleton<br/>process guard<br/>[singleton.py]"}}
  node_agent["Agent<br/>controller<br/>[agent.py]"]
  node_metadata_loader["App config<br/>package config<br/>[info.yml]"]
end

subgraph group_group_core["Incident pipeline"]
  node_tail_worker["Tail worker<br/>file watcher<br/>[tail_worker.py]"]
  node_matcher["Matcher<br/>pattern engine<br/>[matcher.py]"]
  node_uploader["Uploader<br/>ticket bridge<br/>[uploader.py]"]
  node_dedupe(("Dedupe<br/>flood control<br/>[uploader.py]"))
  node_candidate["Candidate<br/>incident record"]
end

subgraph group_group_external["External boundaries"]
  node_log_files[("tk logs<br/>local files")]
  node_filesystem[("Filesystem<br/>local storage")]
  node_backend[("FPTR backend<br/>remote api")]
  node_tk_runtime{{"Tk Desktop<br/>host runtime"}}
end

node_tk_runtime -->|"launches"| node_app_py
node_app_py -->|"reads"| node_metadata_loader
node_app_py -->|"starts"| node_bootstrap
node_bootstrap -->|"guards"| node_singleton
node_bootstrap -->|"creates"| node_agent
node_agent -->|"owns"| node_tail_worker
node_tail_worker -->|"reads"| node_filesystem
node_filesystem -->|"contains"| node_log_files
node_tail_worker -->|"emits lines"| node_matcher
node_matcher -->|"builds"| node_candidate
node_agent -->|"routes"| node_uploader
node_candidate -->|"submits"| node_uploader
node_uploader -->|"checks"| node_dedupe
node_dedupe -->|"queries"| node_backend
node_uploader -->|"creates"| node_backend
node_uploader -->|"attaches"| node_log_files

click node_app_py "https://github.com/sungbinlee/tk-incidentreporter/blob/main/app.py"
click node_info_yml "https://github.com/sungbinlee/tk-incidentreporter/blob/main/info.yml"
click node_bootstrap "https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/bootstrap.py"
click node_singleton "https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/singleton.py"
click node_agent "https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/agent.py"
click node_tail_worker "https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/tail_worker.py"
click node_matcher "https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/matcher.py"
click node_uploader "https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/uploader.py"
click node_dedupe "https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/uploader.py"
click node_metadata_loader "https://github.com/sungbinlee/tk-incidentreporter/blob/main/info.yml"

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_app_py,node_info_yml,node_bootstrap,node_singleton,node_agent,node_metadata_loader toneBlue
class node_tail_worker,node_matcher,node_uploader,node_dedupe,node_candidate toneAmber
class node_log_files,node_filesystem,node_backend,node_tk_runtime toneMint
```

## Components

### Toolkit host

Desktop app entry and process control within the Toolkit runtime.

- [app.py](https://github.com/sungbinlee/tk-incidentreporter/blob/main/app.py): entrypoint · Toolkit app entry module. · `app.py`
- [info.yml](https://github.com/sungbinlee/tk-incidentreporter/blob/main/info.yml): metadata · Toolkit app metadata loaded by the host. · `info.yml`
- [Bootstrap](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/bootstrap.py): orchestrator · Wires together startup, configuration, and runtime services. · `python/tk_incident/bootstrap.py`
- [Singleton](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/singleton.py): process guard · Ensures only one watcher instance runs at a time. · `python/tk_incident/singleton.py`
- [Agent](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/agent.py): controller · Main in-process controller for the incident reporter. · `python/tk_incident/agent.py`
- [App config](https://github.com/sungbinlee/tk-incidentreporter/blob/main/info.yml): package config · App package metadata consumed by the Toolkit loader. · `info.yml`

### Incident pipeline

Core log-watching, matching, and ticket creation flow.

- [Tail worker](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/tail_worker.py): file watcher · Follows active tk-*.log files and emits new log lines. · `python/tk_incident/tail_worker.py`
- [Matcher](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/matcher.py): pattern engine · Detects incident-like lines using regex and builds candidates. · `python/tk_incident/matcher.py`
- [Uploader](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/uploader.py): ticket bridge · Creates tickets, attaches logs, and talks to the backend API. · `python/tk_incident/uploader.py`
- [Dedupe](https://github.com/sungbinlee/tk-incidentreporter/blob/main/python/tk_incident/uploader.py): flood control · Skips duplicate reports when a matching ticket title already exists. · `python/tk_incident/uploader.py`
- **Candidate**: incident record · Enriched incident data passed toward ticket creation.

### External boundaries

Filesystem and backend systems the app integrates with.

- **tk logs**: local files · Client-side tk-*.log files on the local machine.
- **Filesystem**: local storage · Local machine storage where log files are read from.
- **FPTR backend**: remote api · Remote ticketing system used to create incident tickets.
- **Tk Desktop**: host runtime · SGTK/Toolkit execution environment that hosts the app.

## Connections

- Tk Desktop → app.py: launches · Toolkit host starts the app entry point.
- app.py → App config: reads · App entry uses Toolkit metadata during loading.
- app.py → Bootstrap: starts · Entry module hands control to startup orchestration.
- Bootstrap → Singleton: guards · Startup checks that only one instance is active.
- Bootstrap → Agent: creates · Bootstrap instantiates the main controller.
- Agent → Tail worker: owns · Agent coordinates the log tailing worker.
- Tail worker → Filesystem: reads · Worker follows local log files from disk.
- Filesystem → tk logs: contains · The filesystem holds the tk log files.
- Tail worker → Matcher: emits lines · New log lines are forwarded for inspection.
- Matcher → Candidate: builds · Matching lines are converted into incident candidates.
- Agent → Uploader: routes · Agent sends incident candidates to the upload path.
- Candidate → Uploader: submits · Candidate details are consumed by ticket creation.
- Uploader → Dedupe: checks · Uploader suppresses repeated tickets by title signature.
- Dedupe → FPTR backend: queries · Duplicate detection depends on existing remote tickets.
- Uploader → FPTR backend: creates · Uploader opens tickets and attaches the log.
- Uploader → tk logs: attaches · Relevant log file is attached to the ticket.
