Smart Network Controller (SNC) is a modular, framework-agnostic request management system built in TypeScript. It intelligently manages API calls in modern web applications by introducing priority-based queuing, in-memory and persistent caching, controlled concurrency, and smooth orchestration — all aimed at reducing network overhead and improving responsiveness.
- ✅ Priority-based global request queue (LOW → CRITICAL)
- ⚡ Concurrent request execution (configurable limit)
- 🔁 Retry and timeout support
- 🧠 Cache-first design using:
- LRU-style in-memory cache
- Persistent cache via IndexedDB
- 📡 Framework-agnostic: Works with any JS/TS frontend or backend
- 🧩 Modular components:
executor,queue,cache,orchestrator, etc. - 🔍 Unique ID → response mapping
- 🚀 Prefetch and fallback URL support
- 🧪 Built-in hooks for future extensions like telemetry and analytics
/src
├── orchestrator/ # Entry point for requests (snc.post, snc.get, etc.)
├── data-manager/ # In-memory and IndexedDB cache handlers
├── executor/ # Fetch-based request executor with concurrency handling
├── queue/ # Priority queue with subscriptions and triggers
├── mapping/ # Tracks active requests and their resolution
├── config.ts # Global config (timeouts, cache size, concurrency, etc.)
├── globaltypes.ts # Shared types across modules
├── utils.ts # Helper functions for hashing, keys, and transformation
snc.post(...)creates aSNCRequest.- The Orchestrator transforms it into a
NetworkRequest. - DataManager checks for cached response (Memory → IndexedDB).
- If not cached, it's enqueued in the GlobalQueue.
- The Executor listens for new queue items and executes them with concurrency logic.
- The result is returned to the caller via Mapping module.
- The result is optionally cached for future requests.
npm installIf using persistent storage:
npm install idbimport { snc } from './orchestrator';
const result = await snc.post('/api/user', {
body: { id: 123 },
priority: 8,
cache: true,
});export const CONFIG = {
MEMORY_CACHE_MAX_SIZE: 100, // Number of items
MAX_CONCURRENT_REQUESTS: 5, // Parallel requests
DEFAULT_TIMEOUT: 15000, // In ms
};export enum SNCRequestPriority {
LOW = 0,
NORMAL = 5,
HIGH = 8,
CRITICAL = 10
}Higher values are dequeued and executed first.
- Fast LRU cache
- Max size and
lastUsedmetadata support
- Long-term caching via
idb - Used for
prefetchand offline-first scenarios
| Module | Responsibility |
|---|---|
| Orchestrator | Converts request and manages full lifecycle |
| DataManager | Handles memory and persistent cache |
| MemoryCache | LRU in-memory wrapper around Cache API |
| Queue | Global request queue with priority |
| Executor | Executes requests with concurrency and retry logic |
| Mapping | Maps unique IDs to resolve/reject handlers |
| Utils | Shared helpers like hashing, key generation |
| Config | Limits, TTLs, size bounds, etc. |
- Prefetch support (
prefetch: true) - Retry on failure (
retry: 3) - Timeout control (
timeout: 5000) - Fallback URLs (
fallbackUrls: [...]) - Infinite scrolling support (
infiniteScroll: true) - Pagination hooks (
pagination: true)
- ⏹ Abortable requests via
AbortController - 📊 Telemetry hooks for performance tracking
- 👷♂️ Web worker support for background queue execution
- 🌐 Offline-first support with background sync
- 🧩 Devtools integration for real-time inspection
Got ideas to improve SNC? Fork the repo and open a PR!
This system is designed to be modular — easy to plug in your own executor, cache layer, or analytics.
👉 Read the CONTRIBUTING guide for setup, guidelines, and best practices.
MIT © Vishal Varshney
Vishal Varshney Java Backend Developer & Systems Engineer Crafting clean, smart, and scalable infrastructure 🚀