$ show foru17/neko-master
Neko Master is a production-grade traffic analytics platform for Clash/Mihomo and Surge proxy gateways. It collects real-time connection data via WebSocket or HTTP polling, aggregates it in SQLite (always) and optionally ClickHouse, and serves a rich dashboard built with Next.js 16, React 19, and Tailwind CSS. The system supports both direct collector-to-gateway mode and a Go-based agent mode for remote or isolated networks. The backend is a Fastify 5 server with WebSocket push, repository-patterned database access, in-memory realtime store, and health-aware dual-write routing. The frontend provides per-domain, per-IP, per-proxy, per-rule, per-country, and per-device statistics with time-range filtering, pagination, charts, and interactive visualizations including a DAG rule-chain flow. The project is a monorepo with pnpm and Turborepo, including a shared TypeScript types package and extensive CI/CD. While primarily an application, it has strong data-engineering aspects: batch buffering, time-series aggregation, GeoIP enrichment, and ClickHouse integration for large-scale deployments.
The LLM identified 5 files worth highlighting for reuse:
A configurable batch buffer that accumulates traffic updates per composite key (backend+minute+dimension) and flushes to SQLite, ClickHouse, and in-memory store at intervals or on size thresholds. It demonstrates a clean observer pattern, idempotent aggregation, and health-aware fallback. Can be extracted as a standalone batch writer for any time-series or event-logging system.
An in-memory data store that holds per-backend traffic deltas (domains, IPs, proxies, rules, devices, countries, summary, minutes) with merge methods to combine with database results for real-time queries. Includes automatic eviction of low-traffic entries at a configurable cap. The pattern is reusable for any application requiring in-memory aggregation with periodic persistence and query-time delta merging.
A base class for SQLite repositories providing shared utilities: minute-range parsing, fact table resolution (minute vs hourly), split-range queries, chain expansion, and weight allocation. It encapsulates common time-series query patterns and can be reused across any project using SQLite for time-windowed analytics with pre-aggregation tables.
A shared TypeScript package defining interfaces for StatsSummary, Connection, WebSocket events, Surge types, and utility functions for gateway data normalization and GeoIP. It enforces a consistent data contract between the Go agent, TypeScript collector, and React frontend. This pattern of a shared types package is directly reusable for any monorepo with multiple runtime environments.
A shell script for installing the Go agent binary on multiple platforms (Linux, macOS, OpenWrt). It supports multi-instance configuration, checksum verification, auto-start via systemd/procd/launchd, and version detection. The script is self-contained and demonstrates a robust pattern for deploying a binary agent across diverse environments, reusable for any similar agent-based architecture.