How francyfox/bunsqstat works
Project Type & Purpose
• This is a full-stack, monorepo application (built with Turbo) for real-time analysis of Squid proxy logs.
• It consists of:
• A Bun-based backend (“server”) that parses logs, indexes them in Redis, and serves APIs + WebSocket streams.
• A Vue 3 frontend (“web”) that renders dashboards, tables, and charts via HTTP + WS.
• A Redis Stack instance (with RediSearch) for full-text search and analytics.
• Docker configs & CI/CD workflows for containerized deployment.
File Structure Insights
• Top level:
• apps/server – Bun + TypeScript API & WS services, organized by modules (parser, access-logs, metrics, settings, watcher, ws).
• apps/web – Vue 3 SPA built with Vite, Composition API, Naive UI, UnoCSS, web workers, stores, pages, and components.
• packages – shared code (i18n, native-builder).
• docker & docker-compose files – config for Squid, Redis, Caddy, log rotation, multi‐container orchestration.
• docs – deployment, metrics, search syntax guides.
• CI/CD: GitHub Actions workflows for Docker image build & release.
Key Architectural Patterns
• Monorepo with Turbo for workspace builds.
• Modular backend: single process with clear service boundaries (parsing, metrics, settings, WS).
• Event-driven pipeline: watcher → parser → metrics → Redis → WS → UI.
• Pub/Sub via Redis and WebSocket for real-time updates.
• Frontend stores & workers isolate data fetching & heavy computations.
Main Components & Interactions
• Squid Proxy
• Generates access_log files (rotated by Squid).
• Log Watcher (apps/server/modules/watcher)
• Monitors log file changes, emits new lines.
• Parser (apps/server/modules/parser)
• Parses each log line into structured events.
• Metrics & Access-Logs Services (apps/server/modules/access-logs & metrics)
• Aggregate stats, compute hit ratios, top users/domains, RPS, durations.
• Redis Stack
• Stores raw events in streams or hashes, builds full-text indices via RediSearch for fast queries.
• WS Service (apps/server/modules/ws) & Elysia HTTP Routes
• Broadcasts real-time updates; serves REST endpoints (e.g., /api/search, /api/settings).
• Vue 3 Web UI
• Connects via HTTP to fetch historical/search data.
• Maintains a WebSocket for live updates.
• Uses Composition API, stores, and web workers (access.worker.ts) to offload processing.
• Shared Packages
• i18n: localization utilities.
• native-builder: custom build scripts.
• DevOps/CICD
• Dockerfiles for frontend, backend.
• docker-compose for all-in-one or prod.
• GitHub Actions for image build & release.