[PR #6] [MERGED] Add service layer with caching, circuit breakers, and Cloudflare Worker proxy #10

Closed
opened 2026-03-16 12:11:32 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hipcityreg/situation-monitor/pull/6
Author: @xaelophone
Created: 1/10/2026
Status: Merged
Merged: 1/10/2026
Merged by: @xaelophone

Base: mainHead: feature/service-layer-optimization


📝 Commits (10+)

  • a230a8f Add custom error classes for service layer
  • 3dec087 Add CacheManager with two-tier caching
  • 79d2bde Add CircuitBreaker for service failure management
  • 5708653 Add RequestDeduplicator to prevent duplicate requests
  • 59e6fd3 Add ServiceRegistry with per-service configurations
  • 1850ce8 Add ServiceClient as unified fetch wrapper
  • b9411bf Add barrel export for service layer
  • f12faee Migrate data.js to use ServiceClient
  • e369e21 Add Cloudflare Worker CORS proxy (optional)
  • cf62b35 Fix broken RSS feeds and deploy Cloudflare Worker proxy

📊 Changes

12 files changed (+1530 additions, -241 deletions)

View changed files

📝 js/constants.js (+5 -6)
📝 js/data.js (+194 -197)
📝 js/renderers.js (+30 -38)
js/services/CacheManager.js (+231 -0)
js/services/CircuitBreaker.js (+178 -0)
js/services/RequestDeduplicator.js (+71 -0)
js/services/ServiceClient.js (+281 -0)
js/services/ServiceRegistry.js (+121 -0)
js/services/errors.js (+34 -0)
js/services/index.js (+8 -0)
workers/proxy/index.js (+354 -0)
workers/proxy/wrangler.toml (+23 -0)

📄 Description

Summary

  • Service Layer Architecture: Add unified fetch client with two-tier caching (memory + localStorage), circuit breaker pattern for failing services, and request deduplication for concurrent calls
  • Cloudflare Worker Proxy: Deploy custom CORS proxy with built-in RSS-to-JSON parsing, eliminating dependency on rate-limited third-party services (rss2json)
  • Code Quality: Simplify and refactor data fetching code for clarity and maintainability

Key Features

Service Layer (js/services/)

  • CacheManager - Two-tier caching with TTL and stale-while-revalidate
  • CircuitBreaker - Prevents cascading failures with automatic recovery
  • RequestDeduplicator - Deduplicates concurrent identical requests
  • ServiceRegistry - Per-service configuration (timeout, retries, cache TTL)
  • ServiceClient - Unified fetch wrapper with exponential backoff

Cloudflare Worker (workers/proxy/)

  • CORS proxy for 45+ allowed domains
  • Built-in RSS/Atom to JSON parsing (?format=json)
  • Edge caching with content-type-aware TTLs
  • No rate limits - self-hosted infrastructure

Bug Fixes

  • Fix broken RSS feed URLs (Reuters, Treasury, State Dept)
  • Fix formatVolume TypeError for pre-formatted strings
  • Replace rate-limited rss2json with Worker-based parsing

Test plan

  • Verify page loads without console errors
  • Confirm RSS feeds load via Cloudflare Worker
  • Check cache HIT/MISS headers in network tab
  • Run getServiceHealth() in console to verify circuit breakers
  • Test on production after merge

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hipcityreg/situation-monitor/pull/6 **Author:** [@xaelophone](https://github.com/xaelophone) **Created:** 1/10/2026 **Status:** ✅ Merged **Merged:** 1/10/2026 **Merged by:** [@xaelophone](https://github.com/xaelophone) **Base:** `main` ← **Head:** `feature/service-layer-optimization` --- ### 📝 Commits (10+) - [`a230a8f`](https://github.com/hipcityreg/situation-monitor/commit/a230a8f1708a5c4f4f85d9315132a7b1aa3240d6) Add custom error classes for service layer - [`3dec087`](https://github.com/hipcityreg/situation-monitor/commit/3dec0871cb0ebae052f9ceabf0bfdcc87663e09b) Add CacheManager with two-tier caching - [`79d2bde`](https://github.com/hipcityreg/situation-monitor/commit/79d2bdeaac4655c078a23087046ec926c365cb51) Add CircuitBreaker for service failure management - [`5708653`](https://github.com/hipcityreg/situation-monitor/commit/57086532ef66ad54f9fd561668ba76387bd93301) Add RequestDeduplicator to prevent duplicate requests - [`59e6fd3`](https://github.com/hipcityreg/situation-monitor/commit/59e6fd3b81603aa4d7388c8e850b06865d125c42) Add ServiceRegistry with per-service configurations - [`1850ce8`](https://github.com/hipcityreg/situation-monitor/commit/1850ce8bd52b59b31ffe0bcb11420b53bfe8d0e8) Add ServiceClient as unified fetch wrapper - [`b9411bf`](https://github.com/hipcityreg/situation-monitor/commit/b9411bf38176d7e3ec48eefab6a8aa0bea023d63) Add barrel export for service layer - [`f12faee`](https://github.com/hipcityreg/situation-monitor/commit/f12faeedb068c0fe251d37264dbd7be07a13e9a2) Migrate data.js to use ServiceClient - [`e369e21`](https://github.com/hipcityreg/situation-monitor/commit/e369e21f5b963d67b7de1d59e4188d45df5503f8) Add Cloudflare Worker CORS proxy (optional) - [`cf62b35`](https://github.com/hipcityreg/situation-monitor/commit/cf62b35fa1f2a336c0165733fd7bbbc6b78ba673) Fix broken RSS feeds and deploy Cloudflare Worker proxy ### 📊 Changes **12 files changed** (+1530 additions, -241 deletions) <details> <summary>View changed files</summary> 📝 `js/constants.js` (+5 -6) 📝 `js/data.js` (+194 -197) 📝 `js/renderers.js` (+30 -38) ➕ `js/services/CacheManager.js` (+231 -0) ➕ `js/services/CircuitBreaker.js` (+178 -0) ➕ `js/services/RequestDeduplicator.js` (+71 -0) ➕ `js/services/ServiceClient.js` (+281 -0) ➕ `js/services/ServiceRegistry.js` (+121 -0) ➕ `js/services/errors.js` (+34 -0) ➕ `js/services/index.js` (+8 -0) ➕ `workers/proxy/index.js` (+354 -0) ➕ `workers/proxy/wrangler.toml` (+23 -0) </details> ### 📄 Description ## Summary - **Service Layer Architecture**: Add unified fetch client with two-tier caching (memory + localStorage), circuit breaker pattern for failing services, and request deduplication for concurrent calls - **Cloudflare Worker Proxy**: Deploy custom CORS proxy with built-in RSS-to-JSON parsing, eliminating dependency on rate-limited third-party services (rss2json) - **Code Quality**: Simplify and refactor data fetching code for clarity and maintainability ## Key Features ### Service Layer (`js/services/`) - `CacheManager` - Two-tier caching with TTL and stale-while-revalidate - `CircuitBreaker` - Prevents cascading failures with automatic recovery - `RequestDeduplicator` - Deduplicates concurrent identical requests - `ServiceRegistry` - Per-service configuration (timeout, retries, cache TTL) - `ServiceClient` - Unified fetch wrapper with exponential backoff ### Cloudflare Worker (`workers/proxy/`) - CORS proxy for 45+ allowed domains - Built-in RSS/Atom to JSON parsing (`?format=json`) - Edge caching with content-type-aware TTLs - No rate limits - self-hosted infrastructure ### Bug Fixes - Fix broken RSS feed URLs (Reuters, Treasury, State Dept) - Fix `formatVolume` TypeError for pre-formatted strings - Replace rate-limited rss2json with Worker-based parsing ## Test plan - [x] Verify page loads without console errors - [x] Confirm RSS feeds load via Cloudflare Worker - [x] Check cache HIT/MISS headers in network tab - [x] Run `getServiceHealth()` in console to verify circuit breakers - [ ] Test on production after merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-16 12:11:32 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/situation-monitor#10
No description provided.