# dkssvp/day13_hourly_focus_metrics_sync_to_firebase architecture

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

- Interactive diagram: https://gitdiagram.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase
- Repository: https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase

## Overview

This repository contains two Python workflows for tracking developer application time from ActivityWatch: one prints and saves a 24-hour focus summary, while the other periodically syncs hourly metrics to Firestore. Both identify window and AFK events, filter applications, and exclude AFK intervals. The scheduled workflow adds retries and a local fallback log. Relationships below are supported by the two sampled source files; the README is empty, and no broader product capabilities are documented.

Main entry points: [`scheduled_focus_push.py`](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py) (Hourly sync), [`focus_tracker.py`](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py) (Focus report runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_analysis["Focus analysis"]
  node_focus_main["Focus report runner<br/>[focus_tracker.py]"]
  node_focus_fetch["ActivityWatch event fetch<br/>[focus_tracker.py]"]
  node_focus_intervals["AFK and window intervals<br/>[focus_tracker.py]"]
  node_focus_summary["Focus summary<br/>[focus_tracker.py]"]
  node_report_file["JSON report file"]
end

subgraph group_sync["Scheduled sync"]
  node_scheduler["Hourly scheduler"]
  node_sync_hour["Hourly sync"]
  node_aggregate["Hourly aggregation"]
  node_sync_fetch["ActivityWatch event fetch"]
  node_sync_intervals["AFK and window intervals"]
  node_firestore_init["Firestore initialization"]
  node_write_retry["Retried document writes"]
  node_fallback["Fallback logging"]
end

subgraph group_services["External services"]
  node_activitywatch["ActivityWatch API"]
  node_firestore[("Firestore")]
end

node_user(("User"))

node_user -->|"runs report"| node_focus_main
node_focus_main -->|"requests events"| node_focus_fetch
node_focus_fetch -->|"fetches events"| node_activitywatch
node_focus_main -->|"processes events"| node_focus_intervals
node_focus_intervals -->|"calculates totals"| node_focus_summary
node_focus_main -->|"writes JSON"| node_report_file
node_user -->|"starts scheduler"| node_scheduler
node_scheduler -->|"runs hourly sync"| node_sync_hour
node_sync_hour -->|"requests metrics"| node_aggregate
node_aggregate -->|"fetches events"| node_sync_fetch
node_sync_fetch -->|"fetches events"| node_activitywatch
node_aggregate -->|"filters and totals"| node_sync_intervals
node_sync_hour -->|"initializes client"| node_firestore_init
node_sync_hour -->|"writes metrics"| node_write_retry
node_firestore_init -->|"creates client"| node_firestore
node_write_retry -->|"sets documents"| node_firestore
node_write_retry -->|"logs failed writes"| node_fallback
node_sync_hour -->|"logs sync errors"| node_fallback

click node_scheduler "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"
click node_focus_main "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py"
click node_focus_fetch "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py"
click node_focus_intervals "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py"
click node_focus_summary "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py"
click node_sync_hour "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"
click node_aggregate "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"
click node_sync_fetch "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"
click node_sync_intervals "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"
click node_firestore_init "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"
click node_write_retry "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"
click node_fallback "https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py"

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_focus_main,node_focus_fetch,node_focus_intervals,node_focus_summary,node_report_file,node_user toneBlue
class node_scheduler,node_sync_hour,node_aggregate,node_sync_fetch,node_sync_intervals,node_firestore_init,node_write_retry,node_fallback toneAmber
class node_activitywatch,node_firestore toneMint
```

## Components

### Focus analysis

- [Focus report runner](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py): `focus_tracker.py`
- [ActivityWatch event fetch](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py): `focus_tracker.py`
- [AFK and window intervals](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py): `focus_tracker.py`
- [Focus summary](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/focus_tracker.py): `focus_tracker.py`
- **JSON report file**

### Scheduled sync

- [Hourly scheduler](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`
- [Hourly sync](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`
- [Hourly aggregation](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`
- [ActivityWatch event fetch](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`
- [AFK and window intervals](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`
- [Firestore initialization](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`
- [Retried document writes](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`
- [Fallback logging](https://github.com/dkssvp/day13_hourly_focus_metrics_sync_to_firebase/blob/feature/day13-hourly-focus-firebase-sync/scheduled_focus_push.py): `scheduled_focus_push.py`

### External services

- **ActivityWatch API**
- **Firestore**

### Other components

- **User**

## Connections

- User → Focus report runner: runs report (evidence: `focus_tracker.py`)
- Focus report runner → ActivityWatch event fetch: requests events (evidence: `focus_tracker.py`)
- ActivityWatch event fetch → ActivityWatch API: fetches events (evidence: `focus_tracker.py`)
- Focus report runner → AFK and window intervals: processes events (evidence: `focus_tracker.py`)
- AFK and window intervals → Focus summary: calculates totals (evidence: `focus_tracker.py`)
- Focus report runner → JSON report file: writes JSON (evidence: `focus_tracker.py`)
- User → Hourly scheduler: starts scheduler (evidence: `scheduled_focus_push.py`)
- Hourly scheduler → Hourly sync: runs hourly sync (evidence: `scheduled_focus_push.py`)
- Hourly sync → Hourly aggregation: requests metrics (evidence: `scheduled_focus_push.py`)
- Hourly aggregation → ActivityWatch event fetch: fetches events (evidence: `scheduled_focus_push.py`)
- ActivityWatch event fetch → ActivityWatch API: fetches events (evidence: `scheduled_focus_push.py`)
- Hourly aggregation → AFK and window intervals: filters and totals (evidence: `scheduled_focus_push.py`)
- Hourly sync → Firestore initialization: initializes client (evidence: `scheduled_focus_push.py`)
- Hourly sync → Retried document writes: writes metrics (evidence: `scheduled_focus_push.py`)
- Firestore initialization → Firestore: creates client (evidence: `scheduled_focus_push.py`)
- Retried document writes → Firestore: sets documents (evidence: `scheduled_focus_push.py`)
- Retried document writes → Fallback logging: logs failed writes (evidence: `scheduled_focus_push.py`)
- Hourly sync → Fallback logging: logs sync errors (evidence: `scheduled_focus_push.py`)
