# 92gthrbg88-eng/faction-stat-logger architecture

> Architecture diagram of the GitHub repository 92gthrbg88-eng/faction-stat-logger, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/92gthrbg88-eng/faction-stat-logger
- Repository: https://github.com/92gthrbg88-eng/faction-stat-logger

## Overview

This single-file Torn userscript detects profile pages, reads a stored API key, fetches profile statistics, and displays them in a persistent panel; when live data is unavailable, it falls back to battle history. The sampled excerpts show the page observer refreshing the panel and the live-fetch failure path invoking the fallback. Internal details of the fallback request are partly omitted, so its API connection is shown as documented rather than inferred from an unseen call.

Main entry points: [`faction-stat-logger.user.js`](https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js) (Profile data fetch)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_torn_profile(("Torn profile page"))
node_userscript["Userscript runtime"]
node_settings["API key settings"]
node_profile_data["Profile data fetch"]
node_history["Battle history fallback"]
node_torn_api["Torn API"]
node_panel["Faction intel panel"]

node_torn_profile -->|"matches page"| node_userscript
node_userscript -->|"reads key"| node_settings
node_userscript -->|"refreshes panel"| node_panel
node_profile_data -->|"fetches profile"| node_torn_api
node_profile_data -->|"falls back"| node_history
node_history -.->|"requests history"| node_torn_api
node_profile_data -->|"writes stats"| node_panel
node_history -->|"writes fallback"| node_panel

click node_userscript "https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js"
click node_settings "https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js"
click node_profile_data "https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js"
click node_history "https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js"
click node_panel "https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js"

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_torn_profile toneIndigo
class node_userscript toneBlue
class node_settings,node_torn_api toneMint
class node_profile_data,node_history,node_panel toneTeal
```

## Components

### Other components

- **Torn profile page**
- [Userscript runtime](https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js): `faction-stat-logger.user.js`
- [API key settings](https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js): `faction-stat-logger.user.js`
- [Profile data fetch](https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js): `faction-stat-logger.user.js`
- [Battle history fallback](https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js): `faction-stat-logger.user.js`
- **Torn API**
- [Faction intel panel](https://github.com/92gthrbg88-eng/faction-stat-logger/blob/main/faction-stat-logger.user.js): `faction-stat-logger.user.js`

## Connections

- Torn profile page → Userscript runtime: matches page (evidence: `faction-stat-logger.user.js`)
- Userscript runtime → API key settings: reads key (evidence: `faction-stat-logger.user.js`)
- Userscript runtime → Faction intel panel: refreshes panel (evidence: `faction-stat-logger.user.js`)
- Profile data fetch → Torn API: fetches profile (evidence: `faction-stat-logger.user.js`)
- Profile data fetch → Battle history fallback: falls back (evidence: `faction-stat-logger.user.js`)
- Battle history fallback → Torn API: requests history
- Profile data fetch → Faction intel panel: writes stats (evidence: `faction-stat-logger.user.js`)
- Battle history fallback → Faction intel panel: writes fallback (evidence: `faction-stat-logger.user.js`)
