source_monitor 0.7.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/release.md +18 -6
  3. data/.claude/skills/sm-configure/SKILL.md +10 -1
  4. data/.claude/skills/sm-configure/reference/configuration-reference.md +44 -0
  5. data/.claude/skills/sm-host-setup/reference/initializer-template.md +17 -0
  6. data/.claude/skills/sm-host-setup/reference/setup-checklist.md +2 -0
  7. data/.claude/skills/sm-job/reference/job-conventions.md +26 -0
  8. data/.claude/skills/sm-upgrade/reference/version-history.md +22 -0
  9. data/.gitignore +10 -0
  10. data/AGENTS.md +1 -1
  11. data/CHANGELOG.md +45 -0
  12. data/CLAUDE.md +24 -3
  13. data/Gemfile.lock +1 -1
  14. data/README.md +6 -4
  15. data/Rakefile +0 -2
  16. data/VERSION +1 -1
  17. data/app/assets/builds/source_monitor/application.css +43 -0
  18. data/app/assets/builds/source_monitor/application.js +127 -0
  19. data/app/assets/builds/source_monitor/application.js.map +3 -3
  20. data/app/assets/javascripts/source_monitor/application.js +2 -0
  21. data/app/assets/javascripts/source_monitor/controllers/notification_container_controller.js +138 -0
  22. data/app/assets/javascripts/source_monitor/controllers/notification_controller.js +11 -0
  23. data/app/controllers/source_monitor/source_favicon_fetches_controller.rb +38 -0
  24. data/app/controllers/source_monitor/sources_controller.rb +11 -0
  25. data/app/helpers/source_monitor/application_helper.rb +51 -0
  26. data/app/jobs/source_monitor/favicon_fetch_job.rb +71 -0
  27. data/app/jobs/source_monitor/import_opml_job.rb +9 -0
  28. data/app/jobs/source_monitor/source_health_check_job.rb +10 -0
  29. data/app/models/source_monitor/source.rb +2 -0
  30. data/app/views/layouts/source_monitor/application.html.erb +23 -2
  31. data/app/views/source_monitor/import_sessions/steps/_preview.html.erb +7 -2
  32. data/app/views/source_monitor/shared/_toast.html.erb +1 -0
  33. data/app/views/source_monitor/sources/_details.html.erb +34 -5
  34. data/app/views/source_monitor/sources/_row.html.erb +11 -6
  35. data/config/routes.rb +1 -0
  36. data/docs/configuration.md +1 -1
  37. data/docs/upgrade.md +22 -0
  38. data/lib/generators/source_monitor/install/templates/source_monitor.rb.tt +15 -1
  39. data/lib/source_monitor/configuration/favicons_settings.rb +42 -0
  40. data/lib/source_monitor/configuration/http_settings.rb +1 -1
  41. data/lib/source_monitor/configuration/scraping_settings.rb +1 -1
  42. data/lib/source_monitor/configuration.rb +3 -1
  43. data/lib/source_monitor/favicons/discoverer.rb +196 -0
  44. data/lib/source_monitor/fetching/feed_fetcher/source_updater.rb +21 -0
  45. data/lib/source_monitor/fetching/feed_fetcher.rb +1 -0
  46. data/lib/source_monitor/http.rb +5 -3
  47. data/lib/source_monitor/version.rb +1 -1
  48. data/lib/source_monitor.rb +4 -0
  49. data/source_monitor.gemspec +1 -1
  50. metadata +6 -106
  51. data/.vbw-planning/PROJECT.md +0 -51
  52. data/.vbw-planning/ROADMAP.md +0 -53
  53. data/.vbw-planning/SHIPPED.md +0 -63
  54. data/.vbw-planning/STATE.md +0 -27
  55. data/.vbw-planning/codebase/ARCHITECTURE.md +0 -147
  56. data/.vbw-planning/codebase/CONCERNS.md +0 -99
  57. data/.vbw-planning/codebase/CONVENTIONS.md +0 -97
  58. data/.vbw-planning/codebase/DEPENDENCIES.md +0 -100
  59. data/.vbw-planning/codebase/INDEX.md +0 -86
  60. data/.vbw-planning/codebase/META.md +0 -42
  61. data/.vbw-planning/codebase/PATTERNS.md +0 -262
  62. data/.vbw-planning/codebase/STACK.md +0 -101
  63. data/.vbw-planning/codebase/STRUCTURE.md +0 -324
  64. data/.vbw-planning/codebase/TESTING.md +0 -154
  65. data/.vbw-planning/config.json +0 -53
  66. data/.vbw-planning/discovery.json +0 -26
  67. data/.vbw-planning/milestones/default/ROADMAP.md +0 -115
  68. data/.vbw-planning/milestones/default/STATE.md +0 -82
  69. data/.vbw-planning/milestones/default/phases/01-coverage-analysis-quick-wins/PLAN-01-SUMMARY.md +0 -56
  70. data/.vbw-planning/milestones/default/phases/01-coverage-analysis-quick-wins/PLAN-01.md +0 -187
  71. data/.vbw-planning/milestones/default/phases/01-coverage-analysis-quick-wins/PLAN-02-SUMMARY.md +0 -64
  72. data/.vbw-planning/milestones/default/phases/01-coverage-analysis-quick-wins/PLAN-02.md +0 -137
  73. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-01-SUMMARY.md +0 -67
  74. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-01.md +0 -142
  75. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-02-SUMMARY.md +0 -64
  76. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-02.md +0 -138
  77. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-03-SUMMARY.md +0 -85
  78. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-03.md +0 -147
  79. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-04-SUMMARY.md +0 -63
  80. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-04.md +0 -129
  81. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-05-SUMMARY.md +0 -74
  82. data/.vbw-planning/milestones/default/phases/02-critical-path-test-coverage/PLAN-05.md +0 -154
  83. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/03-VERIFICATION-wave1.md +0 -303
  84. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/03-VERIFICATION.md +0 -510
  85. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-01-SUMMARY.md +0 -61
  86. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-01.md +0 -161
  87. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-02-SUMMARY.md +0 -66
  88. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-02.md +0 -132
  89. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-03-SUMMARY.md +0 -59
  90. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-03.md +0 -171
  91. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-04-SUMMARY.md +0 -56
  92. data/.vbw-planning/milestones/default/phases/03-large-file-refactoring/PLAN-04.md +0 -152
  93. data/.vbw-planning/milestones/default/phases/04-code-quality-conventions-cleanup/04-CONTEXT.md +0 -33
  94. data/.vbw-planning/milestones/default/phases/04-code-quality-conventions-cleanup/PLAN-01-SUMMARY.md +0 -42
  95. data/.vbw-planning/milestones/default/phases/04-code-quality-conventions-cleanup/PLAN-01.md +0 -119
  96. data/.vbw-planning/milestones/default/phases/04-code-quality-conventions-cleanup/PLAN-02-SUMMARY.md +0 -52
  97. data/.vbw-planning/milestones/default/phases/04-code-quality-conventions-cleanup/PLAN-02.md +0 -195
  98. data/.vbw-planning/milestones/default/phases/04-code-quality-conventions-cleanup/PLAN-03-SUMMARY.md +0 -79
  99. data/.vbw-planning/milestones/default/phases/04-code-quality-conventions-cleanup/PLAN-03.md +0 -130
  100. data/.vbw-planning/milestones/generator-enhancements/REQUIREMENTS.md +0 -72
  101. data/.vbw-planning/milestones/generator-enhancements/ROADMAP.md +0 -125
  102. data/.vbw-planning/milestones/generator-enhancements/SHIPPED.md +0 -40
  103. data/.vbw-planning/milestones/generator-enhancements/STATE.md +0 -43
  104. data/.vbw-planning/milestones/generator-enhancements/phases/01-generator-steps/01-CONTEXT.md +0 -33
  105. data/.vbw-planning/milestones/generator-enhancements/phases/01-generator-steps/01-VERIFICATION.md +0 -86
  106. data/.vbw-planning/milestones/generator-enhancements/phases/01-generator-steps/PLAN-01-SUMMARY.md +0 -61
  107. data/.vbw-planning/milestones/generator-enhancements/phases/01-generator-steps/PLAN-01.md +0 -380
  108. data/.vbw-planning/milestones/generator-enhancements/phases/02-verification/02-VERIFICATION.md +0 -78
  109. data/.vbw-planning/milestones/generator-enhancements/phases/02-verification/PLAN-01-SUMMARY.md +0 -46
  110. data/.vbw-planning/milestones/generator-enhancements/phases/02-verification/PLAN-01.md +0 -500
  111. data/.vbw-planning/milestones/generator-enhancements/phases/03-docs-alignment/03-VERIFICATION.md +0 -89
  112. data/.vbw-planning/milestones/generator-enhancements/phases/03-docs-alignment/PLAN-01-SUMMARY.md +0 -48
  113. data/.vbw-planning/milestones/generator-enhancements/phases/03-docs-alignment/PLAN-01.md +0 -456
  114. data/.vbw-planning/milestones/generator-enhancements/phases/04-dashboard-ux/04-VERIFICATION.md +0 -129
  115. data/.vbw-planning/milestones/generator-enhancements/phases/04-dashboard-ux/PLAN-01-SUMMARY.md +0 -70
  116. data/.vbw-planning/milestones/generator-enhancements/phases/04-dashboard-ux/PLAN-01.md +0 -747
  117. data/.vbw-planning/milestones/generator-enhancements/phases/05-active-storage-images/05-VERIFICATION.md +0 -156
  118. data/.vbw-planning/milestones/generator-enhancements/phases/05-active-storage-images/PLAN-01-SUMMARY.md +0 -69
  119. data/.vbw-planning/milestones/generator-enhancements/phases/05-active-storage-images/PLAN-01.md +0 -455
  120. data/.vbw-planning/milestones/generator-enhancements/phases/05-active-storage-images/PLAN-02-SUMMARY.md +0 -39
  121. data/.vbw-planning/milestones/generator-enhancements/phases/05-active-storage-images/PLAN-02.md +0 -488
  122. data/.vbw-planning/milestones/generator-enhancements/phases/06-netflix-feed-fix/06-VERIFICATION.md +0 -100
  123. data/.vbw-planning/milestones/generator-enhancements/phases/06-netflix-feed-fix/PLAN-01-SUMMARY.md +0 -37
  124. data/.vbw-planning/milestones/generator-enhancements/phases/06-netflix-feed-fix/PLAN-01.md +0 -345
  125. data/.vbw-planning/milestones/upgrade-assurance/REQUIREMENTS.md +0 -80
  126. data/.vbw-planning/milestones/upgrade-assurance/ROADMAP.md +0 -75
  127. data/.vbw-planning/milestones/upgrade-assurance/STATE.md +0 -29
  128. data/.vbw-planning/milestones/upgrade-assurance/phases/01-upgrade-command/01-VERIFICATION.md +0 -144
  129. data/.vbw-planning/milestones/upgrade-assurance/phases/01-upgrade-command/PLAN-01-SUMMARY.md +0 -43
  130. data/.vbw-planning/milestones/upgrade-assurance/phases/01-upgrade-command/PLAN-01.md +0 -405
  131. data/.vbw-planning/milestones/upgrade-assurance/phases/02-config-deprecation/PLAN-01-SUMMARY.md +0 -27
  132. data/.vbw-planning/milestones/upgrade-assurance/phases/02-config-deprecation/PLAN-01.md +0 -303
  133. data/.vbw-planning/milestones/upgrade-assurance/phases/03-upgrade-skill-docs/03-VERIFICATION.md +0 -380
  134. data/.vbw-planning/milestones/upgrade-assurance/phases/03-upgrade-skill-docs/PLAN-01-SUMMARY.md +0 -36
  135. data/.vbw-planning/milestones/upgrade-assurance/phases/03-upgrade-skill-docs/PLAN-01.md +0 -652
  136. data/.vbw-planning/phases/01-aia-certificate-resolution/.context-dev.md +0 -17
  137. data/.vbw-planning/phases/01-aia-certificate-resolution/PLAN-01-SUMMARY.md +0 -26
  138. data/.vbw-planning/phases/01-aia-certificate-resolution/PLAN-01.md +0 -71
  139. data/.vbw-planning/phases/01-aia-certificate-resolution/PLAN-02-SUMMARY.md +0 -16
  140. data/.vbw-planning/phases/01-aia-certificate-resolution/PLAN-02.md +0 -56
  141. data/.vbw-planning/phases/01-aia-certificate-resolution/PLAN-03-SUMMARY.md +0 -17
  142. data/.vbw-planning/phases/01-aia-certificate-resolution/PLAN-03.md +0 -98
  143. data/.vbw-planning/phases/02-test-performance/.context-dev.md +0 -75
  144. data/.vbw-planning/phases/02-test-performance/.context-lead.md +0 -89
  145. data/.vbw-planning/phases/02-test-performance/.context-qa.md +0 -23
  146. data/.vbw-planning/phases/02-test-performance/02-RESEARCH.md +0 -56
  147. data/.vbw-planning/phases/02-test-performance/02-VERIFICATION.md +0 -51
  148. data/.vbw-planning/phases/02-test-performance/PLAN-01-SUMMARY.md +0 -37
  149. data/.vbw-planning/phases/02-test-performance/PLAN-01.md +0 -156
  150. data/.vbw-planning/phases/02-test-performance/PLAN-02-SUMMARY.md +0 -33
  151. data/.vbw-planning/phases/02-test-performance/PLAN-02.md +0 -120
  152. data/.vbw-planning/phases/02-test-performance/PLAN-03-SUMMARY.md +0 -30
  153. data/.vbw-planning/phases/02-test-performance/PLAN-03.md +0 -154
  154. data/.vbw-planning/phases/02-test-performance/PLAN-04-SUMMARY.md +0 -28
  155. data/.vbw-planning/phases/02-test-performance/PLAN-04.md +0 -133
@@ -1,86 +0,0 @@
1
- # Index
2
-
3
- Cross-referenced index of key findings across all mapping documents.
4
-
5
- ## Quick Reference
6
-
7
- | Document | Focus | Key Finding |
8
- |----------|-------|-------------|
9
- | [STACK.md](STACK.md) | Technology choices | Rails 8.1.1 engine, Ruby 3.4+, PostgreSQL, Solid Queue, Tailwind 3 |
10
- | [DEPENDENCIES.md](DEPENDENCIES.md) | Dependency analysis | 14 runtime gems, PG-only, optional deps loaded silently |
11
- | [ARCHITECTURE.md](ARCHITECTURE.md) | System design | 10 domain modules, event-driven, pluggable scrapers |
12
- | [STRUCTURE.md](STRUCTURE.md) | Directory layout | ~324 Ruby files, 124 tests, 24 migrations |
13
- | [CONVENTIONS.md](CONVENTIONS.md) | Code style | Rails omakase, frozen strings, Struct-based results |
14
- | [TESTING.md](TESTING.md) | Test infrastructure | Minitest, parallel, SimpleCov branch coverage, nightly profiling |
15
- | [CONCERNS.md](CONCERNS.md) | Risks & debt | Large files, PG lock-in, coverage gaps, no default auth |
16
- | [PATTERNS.md](PATTERNS.md) | Recurring patterns | Service objects, adapter pattern, event callbacks, Turbo Streams |
17
-
18
- ## Key Entry Points
19
-
20
- | Purpose | File | Notes |
21
- |---------|------|-------|
22
- | Gem entry point | `lib/source_monitor.rb` | 102+ require statements, module definition |
23
- | Engine definition | `lib/source_monitor/engine.rb` | Initializers, asset registration |
24
- | Configuration DSL | `lib/source_monitor/configuration.rb` | 12 nested settings classes |
25
- | Routes | `config/routes.rb` | 24 lines, RESTful resources |
26
- | Main model | `app/models/source_monitor/source.rb` | Core domain entity |
27
- | Dashboard | `app/controllers/source_monitor/dashboard_controller.rb` | Landing page |
28
- | Fetch pipeline | `lib/source_monitor/fetching/feed_fetcher.rb` | Core data ingestion |
29
- | Scrape pipeline | `lib/source_monitor/scraping/item_scraper.rb` | Content extraction orchestrator |
30
- | Scheduler | `lib/source_monitor/scheduler.rb` | Periodic fetch scheduling |
31
- | JS entry | `app/assets/javascripts/source_monitor/application.js` | Stimulus app setup |
32
- | CSS entry | `app/assets/stylesheets/source_monitor/application.tailwind.css` | Tailwind input |
33
- | Test entry | `test/test_helper.rb` | Test infrastructure setup |
34
-
35
- ## Data Model Reference
36
-
37
- | Model | Table | Key Relationships |
38
- |-------|-------|-------------------|
39
- | `Source` | `sourcemon_sources` | has_many: items, fetch_logs, scrape_logs, health_check_logs, log_entries |
40
- | `Item` | `sourcemon_items` | belongs_to: source; has_one: item_content; has_many: scrape_logs, log_entries |
41
- | `ItemContent` | `sourcemon_item_contents` | belongs_to: item (separate table for large scraped content) |
42
- | `FetchLog` | `sourcemon_fetch_logs` | belongs_to: source; has_one: log_entry (polymorphic) |
43
- | `ScrapeLog` | `sourcemon_scrape_logs` | belongs_to: item, source; has_one: log_entry (polymorphic) |
44
- | `HealthCheckLog` | `sourcemon_health_check_logs` | belongs_to: source; has_one: log_entry (polymorphic) |
45
- | `LogEntry` | `sourcemon_log_entries` | delegated_type: loggable (FetchLog/ScrapeLog/HealthCheckLog) |
46
- | `ImportSession` | `sourcemon_import_sessions` | JSONB state for wizard flow |
47
- | `ImportHistory` | `sourcemon_import_histories` | Records completed imports |
48
-
49
- ## Job Reference
50
-
51
- | Job Class | Queue | Schedule | Purpose |
52
- |-----------|-------|----------|---------|
53
- | `ScheduleFetchesJob` | fetch | Recurring | Triggers scheduler to find due sources |
54
- | `FetchFeedJob` | fetch | On-demand | Fetches one source's feed |
55
- | `ScrapeItemJob` | scrape | On-demand | Scrapes one item's content |
56
- | `SourceHealthCheckJob` | fetch | On-demand | Health check for one source |
57
- | `ImportSessionHealthCheckJob` | fetch | On-demand | Health check during OPML import |
58
- | `ImportOpmlJob` | fetch | On-demand | Bulk creates sources from OPML |
59
- | `LogCleanupJob` | fetch | Recurring | Prunes old log entries |
60
- | `ItemCleanupJob` | fetch | Recurring | Prunes items per retention policy |
61
-
62
- ## Configuration Surface Area
63
-
64
- | Section | Key Settings | Defaults |
65
- |---------|-------------|----------|
66
- | Queues | `fetch_queue_name`, `scrape_queue_name`, concurrency | `source_monitor_fetch`, `source_monitor_scrape`, 2 each |
67
- | HTTP | timeout, retries, user agent, proxy, headers | 15s/5s timeout, 4 retries |
68
- | Fetching | adaptive interval params, jitter | 5min-24hr, 1.25x increase, 0.75x decrease |
69
- | Health | window size, thresholds, auto-pause | 20 window, 0.8/0.5/0.2 thresholds |
70
- | Scraping | max_in_flight, max_bulk_batch | 25, 100 |
71
- | Retention | days, max_items, strategy | nil (no auto-cleanup), :destroy |
72
- | Realtime | adapter (solid_cable/redis/async) | solid_cable |
73
- | Authentication | handlers, current_user_method | nil (no auth by default) |
74
- | Models | table_name_prefix, concerns, validations | `sourcemon_` |
75
-
76
- ## Critical Cross-Cutting Concerns
77
-
78
- 1. **PG-only** (ARCHITECTURE + CONCERNS): `FOR UPDATE SKIP LOCKED` and `NULLS FIRST/LAST` SQL are PostgreSQL-specific. No other DB supported.
79
-
80
- 2. **No default auth** (ARCHITECTURE + CONCERNS): Engine mounts without authentication unless host app configures it. Import wizard has a `create_guest_user` fallback.
81
-
82
- 3. **Eager loading** (STRUCTURE + CONCERNS): All 102+ require statements in `lib/source_monitor.rb` load at boot time.
83
-
84
- 4. **Coverage debt** (TESTING + CONCERNS): `config/coverage_baseline.json` lists 2329 lines of known uncovered code, particularly in `FeedFetcher`, `ItemCreator`, `Configuration`, and `Dashboard::Queries`.
85
-
86
- 5. **Large files** (STRUCTURE + CONCERNS): `FeedFetcher` (627 lines), `Configuration` (655 lines), and `ImportSessionsController` (792 lines) are candidates for extraction.
@@ -1,42 +0,0 @@
1
- # META
2
-
3
- ## Mapping Metadata
4
-
5
- | Field | Value |
6
- |-------|-------|
7
- | mapped_at | 2026-02-09T00:00:00Z |
8
- | git_hash | 1fb781a35575c2d46bfb8cd96f90c64ddf6ed210 |
9
- | file_count | 530 |
10
- | mode | full |
11
- | monorepo | false |
12
- | mapping_tier | solo (inline) |
13
-
14
- ## Documents
15
-
16
- | File | Domain | Description |
17
- |------|--------|-------------|
18
- | `STACK.md` | Tech Stack | Technology choices, framework versions, build pipeline |
19
- | `DEPENDENCIES.md` | Tech Stack | Runtime, dev, and test dependency analysis with coupling assessment |
20
- | `ARCHITECTURE.md` | Architecture | System overview, domain modules, data model, job architecture |
21
- | `STRUCTURE.md` | Architecture | Full directory tree with file counts and organization |
22
- | `CONVENTIONS.md` | Quality | Naming conventions, code style, frontend patterns |
23
- | `TESTING.md` | Quality | Test framework, CI pipeline, coverage strategy, profiling |
24
- | `CONCERNS.md` | Concerns | Technical debt, security risks, performance, operational risks |
25
- | `INDEX.md` | Synthesis | Cross-referenced index with key findings and quick references |
26
- | `PATTERNS.md` | Synthesis | 14 recurring patterns across the codebase |
27
- | `META.md` | Meta | This file -- mapping metadata and document inventory |
28
-
29
- ## Language Breakdown
30
-
31
- | Language | File Count | Notes |
32
- |----------|-----------|-------|
33
- | Ruby (.rb) | ~324 | Models, controllers, jobs, lib modules, tests |
34
- | ERB (.erb) | ~48 | View templates |
35
- | Markdown (.md) | ~45 | Documentation |
36
- | YAML (.yml) | ~16 | Configuration files |
37
- | JavaScript (.js) | ~14 | Stimulus controllers, build entry points |
38
- | CSS (.css) | ~2 | Tailwind input and build output |
39
-
40
- ## Project Summary
41
-
42
- SourceMonitor is a mountable Rails 8 engine (v0.2.1) that ingests RSS/Atom/JSON feeds, scrapes full article content via pluggable adapters, and provides Solid Queue-powered dashboards for monitoring and remediation. It is distributed as a RubyGem, requires PostgreSQL and Ruby >= 3.4.0, and integrates with host Rails applications via the standard engine mounting pattern with an isolated namespace.
@@ -1,262 +0,0 @@
1
- # Patterns
2
-
3
- Recurring patterns observed across the SourceMonitor codebase.
4
-
5
- ## 1. Service Object Pattern
6
-
7
- **Where**: `lib/source_monitor/fetching/`, `lib/source_monitor/scraping/`, `lib/source_monitor/health/`, `lib/source_monitor/items/`
8
-
9
- Service objects encapsulate domain operations. They follow a consistent structure:
10
-
11
- ```ruby
12
- class SomeService
13
- def initialize(source:, **deps)
14
- @source = source
15
- end
16
-
17
- def call
18
- # orchestrate operation
19
- # return a Result struct
20
- end
21
- end
22
- ```
23
-
24
- **Examples**:
25
- - `Fetching::FeedFetcher` -- `#call` returns `Result` struct
26
- - `Scraping::ItemScraper` -- `#call` returns `Result` struct
27
- - `Health::SourceHealthMonitor` -- `#call` updates source health
28
- - `Health::SourceHealthCheck` -- `#call` probes source URL
29
- - `Items::RetentionPruner` -- `#call` prunes old items
30
- - `Items::ItemCreator` -- `.call(source:, entry:)` class method
31
-
32
- ## 2. Struct-Based Result Objects
33
-
34
- **Where**: Throughout all service objects
35
-
36
- Operations return typed `Struct` instances rather than raw hashes or arrays:
37
-
38
- ```ruby
39
- Result = Struct.new(:status, :item, :log, :message, :error, keyword_init: true) do
40
- def success?
41
- status.to_s != "failed"
42
- end
43
- end
44
- ```
45
-
46
- **Examples**:
47
- - `Scraping::ItemScraper::Result` -- `:status, :item, :log, :message, :error`
48
- - `Scrapers::Base::Result` -- `:status, :html, :content, :metadata`
49
- - `Fetching::FeedFetcher::Result` -- `:status, :feed, :response, :body, :error, :item_processing, :retry_decision`
50
- - `Fetching::FeedFetcher::EntryProcessingResult` -- `:created, :updated, :failed, :items, :errors`
51
- - `Events::ItemCreatedEvent`, `Events::ItemScrapedEvent`, `Events::FetchCompletedEvent`
52
- - `Setup::Verification::Result` -- verification outcome
53
-
54
- ## 3. Adapter/Strategy Pattern
55
-
56
- **Where**: `lib/source_monitor/scrapers/`, `lib/source_monitor/realtime/`, `lib/source_monitor/items/retention_strategies/`
57
-
58
- Pluggable behavior via abstract base class with `#call` contract:
59
-
60
- ```ruby
61
- class Scrapers::Base
62
- def call
63
- raise NotImplementedError
64
- end
65
- end
66
- ```
67
-
68
- **Instances**:
69
- - **Scraper adapters**: `Scrapers::Base` -> `Scrapers::Readability` (registered in `ScraperRegistry`)
70
- - **Realtime adapters**: `solid_cable`, `redis`, `async` (configured in `RealtimeSettings`)
71
- - **Retention strategies**: `:destroy`, `:soft_delete` (in `Items::RetentionStrategies/`)
72
-
73
- ## 4. Event/Callback System
74
-
75
- **Where**: `lib/source_monitor/events.rb`, `lib/source_monitor/configuration.rb`
76
-
77
- Event-driven communication between engine components:
78
-
79
- ```ruby
80
- # Registration
81
- SourceMonitor.config.events.after_item_created { |event| ... }
82
- SourceMonitor.config.events.after_item_scraped { |event| ... }
83
- SourceMonitor.config.events.after_fetch_completed { |event| ... }
84
-
85
- # Dispatch
86
- SourceMonitor::Events.after_item_created(item:, source:, entry:, result:)
87
- ```
88
-
89
- - Typed event structs carry context
90
- - Error isolation: each handler failure is logged, does not stop other handlers
91
- - Item processor pipeline: `Events.run_item_processors` runs all registered processors
92
- - Used by `Health` module to register fetch completion callback
93
-
94
- ## 5. Configuration DSL with Nested Settings Objects
95
-
96
- **Where**: `lib/source_monitor/configuration.rb`
97
-
98
- Deeply nested configuration with domain-specific settings classes:
99
-
100
- ```ruby
101
- SourceMonitor.configure do |config|
102
- config.http.timeout = 30
103
- config.fetching.min_interval_minutes = 10
104
- config.health.window_size = 50
105
- config.scrapers.register(:custom, MyCustomScraper)
106
- config.models.source.include_concern SomeConcern
107
- config.authentication.authenticate_with :authenticate_admin!
108
- end
109
- ```
110
-
111
- **Pattern traits**:
112
- - Each settings class has `reset!` for test isolation
113
- - Constants for defaults (e.g., `DEFAULT_QUEUE_NAMESPACE`)
114
- - Callable values supported (procs/lambdas) for dynamic resolution
115
- - Validation in setters (e.g., `RealtimeSettings#adapter=` checks `VALID_ADAPTERS`)
116
-
117
- ## 6. Model Extension System
118
-
119
- **Where**: `lib/source_monitor/model_extensions.rb`, `lib/source_monitor/configuration.rb`
120
-
121
- Host apps can dynamically inject concerns and validations into engine models:
122
-
123
- ```ruby
124
- config.models.source.include_concern "MyApp::SourceExtensions"
125
- config.models.source.validate :custom_validator
126
- config.models.source.validate { |record| record.errors.add(:base, "invalid") if ... }
127
- ```
128
-
129
- - `ModelExtensions.register(model_class, key)` called in each model class body
130
- - `ModelExtensions.reload!` re-applies all extensions on configuration change
131
- - Manages table name prefix assignment
132
- - Tracks applied concerns/validations to prevent duplicates
133
- - Removes old extension validations before re-applying
134
-
135
- ## 7. Turbo Stream Response Pattern
136
-
137
- **Where**: `lib/source_monitor/turbo_streams/stream_responder.rb`, controllers
138
-
139
- Controllers build Turbo Stream responses via a `StreamResponder` builder:
140
-
141
- ```ruby
142
- responder = SourceMonitor::TurboStreams::StreamResponder.new
143
- presenter = SourceMonitor::Sources::TurboStreamPresenter.new(source:, responder:)
144
- presenter.render_deletion(metrics:, query:, ...)
145
- responder.toast(message:, level: :success)
146
- render turbo_stream: responder.render(view_context)
147
- ```
148
-
149
- - Accumulates stream actions as an array
150
- - Supports toast notifications, redirects, and custom actions
151
- - Pairs with Stimulus controllers on the frontend
152
-
153
- ## 8. Defensive Logging Guard
154
-
155
- **Where**: All jobs and service objects
156
-
157
- Consistent pattern for safe logging:
158
-
159
- ```ruby
160
- def log(stage, **extra)
161
- return unless defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
162
- Rails.logger.info("[SourceMonitor::...] #{payload.to_json}")
163
- rescue StandardError
164
- nil
165
- end
166
- ```
167
-
168
- This three-part guard (`defined?`, `respond_to?`, truthy check) prevents errors when running outside Rails (e.g., in tests or standalone scripts).
169
-
170
- ## 9. ActiveSupport::Notifications Instrumentation
171
-
172
- **Where**: `lib/source_monitor/instrumentation.rb`, `lib/source_monitor/metrics.rb`
173
-
174
- Standard Rails instrumentation pattern:
175
-
176
- ```ruby
177
- # Emit events
178
- SourceMonitor::Instrumentation.fetch_start(payload)
179
- SourceMonitor::Instrumentation.fetch_finish(payload)
180
-
181
- # Subscribe to events
182
- ActiveSupport::Notifications.subscribe("source_monitor.fetch.finish") do |...|
183
- SourceMonitor::Metrics.increment(:fetch_finished_total)
184
- end
185
- ```
186
-
187
- - Events namespaced as `source_monitor.*`
188
- - Monotonic clock for duration measurement
189
- - Metrics module aggregates counters and gauges in memory
190
-
191
- ## 10. Search/Filter with Ransack
192
-
193
- **Where**: Models (`ransackable_attributes`, `ransackable_associations`), `SanitizesSearchParams` concern
194
-
195
- ```ruby
196
- class Source < ApplicationRecord
197
- def self.ransackable_attributes(_auth_object = nil)
198
- %w[name feed_url website_url created_at ...]
199
- end
200
- end
201
- ```
202
-
203
- - Explicit whitelisting of searchable attributes (required by Ransack 4+)
204
- - `SanitizesSearchParams` controller concern sanitizes search inputs
205
- - Used in `SourcesController#index` and `LogsController#index`
206
-
207
- ## 11. Circuit Breaker / Retry Policy
208
-
209
- **Where**: `lib/source_monitor/fetching/retry_policy.rb`, `lib/source_monitor/fetching/feed_fetcher.rb`, `app/jobs/source_monitor/fetch_feed_job.rb`
210
-
211
- Fetch failures trigger an escalating retry policy:
212
-
213
- 1. **Retry with backoff**: Exponential wait, up to N attempts
214
- 2. **Circuit open**: After exhausting retries, block fetches for a cooldown period
215
- 3. **Circuit close**: Scheduler recovers after cooldown expires
216
-
217
- State stored on `Source` model: `fetch_retry_attempt`, `fetch_circuit_opened_at`, `fetch_circuit_until`, `backoff_until`.
218
-
219
- ## 12. Wizard State Machine (OPML Import)
220
-
221
- **Where**: `app/models/source_monitor/import_session.rb`, `app/controllers/source_monitor/import_sessions_controller.rb`
222
-
223
- Multi-step wizard with explicit step ordering:
224
-
225
- ```ruby
226
- STEP_ORDER = %w[upload preview health_check configure confirm].freeze
227
- ```
228
-
229
- - State persisted in `ImportSession` model with JSONB columns
230
- - Each step has dedicated `handle_*_step` and `prepare_*_context` methods
231
- - Navigation via `next_step`/`previous_step` model methods
232
- - Step transitions guarded by validation (e.g., "select at least one source")
233
-
234
- ## 13. Soft Delete Pattern
235
-
236
- **Where**: `app/models/source_monitor/item.rb`
237
-
238
- Items use soft deletion via `deleted_at` timestamp rather than physical deletion:
239
-
240
- ```ruby
241
- scope :active, -> { where(deleted_at: nil) }
242
- scope :with_deleted, -> { unscope(where: :deleted_at) }
243
- scope :only_deleted, -> { where.not(deleted_at: nil) }
244
-
245
- def soft_delete!(timestamp: Time.current)
246
- update_columns(deleted_at: timestamp, updated_at: timestamp)
247
- Source.decrement_counter(:items_count, source_id)
248
- end
249
- ```
250
-
251
- No `default_scope` is used (explicitly noted as avoiding anti-pattern).
252
-
253
- ## 14. Separate Content Table
254
-
255
- **Where**: `app/models/source_monitor/item.rb`, `app/models/source_monitor/item_content.rb`
256
-
257
- Large scraped content is stored in a separate `ItemContent` model rather than on the `Item` directly:
258
-
259
- - Lazy-loaded via `has_one :item_content`
260
- - Auto-created when content is assigned, auto-destroyed when both fields become blank
261
- - Delegates `scraped_html` and `scraped_content` to `ItemContent`
262
- - Prevents bloating the items table with large text columns
@@ -1,101 +0,0 @@
1
- # Tech Stack
2
-
3
- ## Core Platform
4
-
5
- | Layer | Technology | Version |
6
- |-------|-----------|---------|
7
- | Language | Ruby | >= 3.4.0 (CI uses 3.4.4) |
8
- | Framework | Rails | >= 8.0.3, < 9.0 (locked at 8.1.1) |
9
- | Database | PostgreSQL | 15 (CI service image) |
10
- | Background Jobs | Solid Queue | >= 0.3, < 3.0 (locked at 1.2.4) |
11
- | WebSocket/Realtime | Solid Cable | >= 3.0, < 4.0 (locked at 3.0.12) |
12
- | Frontend Interactivity | Turbo Rails | ~> 2.0 (locked at 2.0.20) |
13
- | JS Framework | Stimulus (Hotwired) | ^3.2.2 |
14
- | CSS Framework | Tailwind CSS | ^3.4.10 |
15
- | Web Server | Puma | 7.1.0 |
16
- | Asset Pipeline | Propshaft | 1.3.1 |
17
-
18
- ## Project Type
19
-
20
- Mountable Rails 8 Engine gem (`source_monitor.gemspec`), distributed as a RubyGem. The engine uses `isolate_namespace SourceMonitor` and provides its own models, controllers, views, jobs, and frontend assets.
21
-
22
- - **Version**: 0.2.1
23
- - **Required Ruby**: >= 3.4.0
24
- - **License**: MIT
25
-
26
- ## Feed Parsing & HTTP
27
-
28
- | Purpose | Gem | Version |
29
- |---------|-----|---------|
30
- | RSS/Atom/JSON feed parsing | Feedjira | >= 3.2, < 5.0 (locked 4.0.1) |
31
- | HTTP client | Faraday | ~> 2.9 (locked 2.14.0) |
32
- | HTTP retry middleware | faraday-retry | ~> 2.2 |
33
- | HTTP redirect following | faraday-follow_redirects | ~> 0.4 |
34
- | HTTP gzip compression | faraday-gzip | ~> 3.0 |
35
-
36
- ## Content Scraping & Parsing
37
-
38
- | Purpose | Gem | Version |
39
- |---------|-----|---------|
40
- | HTML parsing (fast, C-based) | Nokolexbor | ~> 0.5 (locked 0.6.2) |
41
- | HTML parsing (standard) | Nokogiri | 1.18.10 (transitive) |
42
- | Article content extraction | ruby-readability | ~> 0.7 |
43
-
44
- ## Search & Querying
45
-
46
- | Purpose | Gem | Version |
47
- |---------|-----|---------|
48
- | Search/filter forms | Ransack | ~> 4.2 (locked 4.4.1) |
49
-
50
- ## Frontend Build Pipeline
51
-
52
- | Tool | Purpose | Version |
53
- |------|---------|---------|
54
- | esbuild | JS bundling | ^0.23.0 |
55
- | Tailwind CSS | Utility-first CSS | ^3.4.10 |
56
- | PostCSS | CSS processing | ^8.4.45 |
57
- | Autoprefixer | CSS vendor prefixes | ^10.4.20 |
58
- | ESLint | JS linting | ^9.11.0 |
59
- | Stylelint | CSS linting | ^16.8.0 |
60
-
61
- Build orchestration via `package.json` scripts:
62
- - `npm run build` -- builds both CSS (tailwindcss) and JS (esbuild)
63
- - `cssbundling-rails` (~> 1.4) and `jsbundling-rails` (~> 1.3) bridge npm builds into the Rails asset pipeline
64
-
65
- ## JS Dependencies (Runtime)
66
-
67
- | Package | Purpose |
68
- |---------|---------|
69
- | `@hotwired/stimulus` ^3.2.2 | Stimulus controllers for UI interactions |
70
- | `stimulus-use` ^0.52.0 | Stimulus composable behaviors library |
71
-
72
- ## Testing Stack
73
-
74
- | Tool | Purpose |
75
- |------|---------|
76
- | Minitest | Test framework (Rails default) |
77
- | Capybara | System/integration test driver |
78
- | Selenium WebDriver | Browser automation for system tests |
79
- | WebMock | HTTP request stubbing |
80
- | VCR | HTTP interaction recording/playback |
81
- | SimpleCov | Code coverage (branch coverage enabled) |
82
- | test-prof | Test profiling (TagProf, EventProf) |
83
- | StackProf | Sampling profiler for performance analysis |
84
-
85
- ## Code Quality & Security
86
-
87
- | Tool | Purpose |
88
- |------|---------|
89
- | RuboCop (rails-omakase) | Ruby/Rails linting (omakase style) |
90
- | Brakeman | Static security analysis |
91
- | ESLint | JavaScript linting |
92
- | Stylelint | CSS linting |
93
-
94
- ## CI/CD
95
-
96
- - **GitHub Actions** with 5 jobs: `lint`, `security`, `test`, `release_verification`, `profiling` (scheduled nightly)
97
- - Ruby 3.4.4, Node 20
98
- - PostgreSQL 15 as service container
99
- - Diff coverage enforcement via custom `bin/check-diff-coverage`
100
- - Test profiling guardrails via `bin/check-test-prof-metrics`
101
- - Parallel test execution (configurable via `SOURCE_MONITOR_TEST_WORKERS`)