|
1 |
| -# fence-alert |
| 1 | +# 🚧 Fence Tracker |
| 2 | + |
| 3 | +## 📋 Overview |
| 4 | + |
| 5 | +Fence Tracker is a zone-based monitoring and alerting service that identifies when activity levels within specific geographic or logical zones exceed a configured threshold. It fetches data from a centralized Query Gateway, evaluates it against defined rules, and sends alerts when meaningful increases occur. |
| 6 | + |
| 7 | +To prevent redundant notifications, Fence Tracker persists the last triggered state for each zone in a MySQL database. When a new threshold multiple is crossed, it formats and dispatches a structured alert message via an external messaging system. |
| 8 | + |
| 9 | +### 🎯 Objectives |
| 10 | + |
| 11 | +- Fetch the latest fence activity data using a named query from the Query Gateway |
| 12 | +- Detect when the quantity per zone exceeds a defined threshold (e.g., 50) |
| 13 | +- Persist trigger states in a MySQL database using Prisma to track previously alerted values |
| 14 | +- Prevent duplicate alerts by only triggering when thresholds escalate beyond prior values |
| 15 | +- Generate structured alert messages containing relevant zone and account information |
| 16 | +- Send alerts to a configurable external messaging endpoint |
| 17 | +- Use Basic and Bearer authentication strategies for secure communication with the Query Gateway |
| 18 | +- Provide a scalable and maintainable alert pipeline for fence-based activity monitoring |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 📦 Quick Start |
| 23 | + |
| 24 | +### ⚠️ Prerequisites |
| 25 | + |
| 26 | +- [**Node.js**](https://nodejs.org/) ≥ `20.14.0` — _JavaScript runtime environment_ |
| 27 | +- [**MySQL**](https://www.mysql.com/) ≥ `8.0` — _Relational database_ |
| 28 | +- [**Query Gateway**](https://github.com/gabrielmendezsoares/query-gateway) ≥ `3.0.2` — _Configurable data query service_ |
| 29 | + |
| 30 | +### ⚙️ Setup |
| 31 | + |
| 32 | +```bash |
| 33 | +# Clone & navigate |
| 34 | +git clone <repository-url> && cd fence-tracker |
| 35 | + |
| 36 | +# Configure environment |
| 37 | +cp .env.example .env # Edit with your settings |
| 38 | + |
| 39 | +# Install dependencies (auto-runs database setup) |
| 40 | +npm install |
| 41 | +``` |
| 42 | + |
| 43 | +> **💡 Database:** Import `storage.sql.example` before running `npm install` |
| 44 | +
|
| 45 | +--- |
| 46 | + |
| 47 | +## ⚡ Usage |
| 48 | + |
| 49 | +### 🛠️ Development |
| 50 | + |
| 51 | +```bash |
| 52 | +npm run start:development |
| 53 | +``` |
| 54 | + |
| 55 | +### 🏗️ Production |
| 56 | + |
| 57 | +```bash |
| 58 | +npm run build && npm run start:production |
| 59 | +``` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## 📚 Command Reference |
| 64 | + |
| 65 | +### 🧰 Core |
| 66 | + |
| 67 | +| Command | Description | |
| 68 | +| ------- | ----------- | |
| 69 | +| `npm run start:development` | _Start the application in development_ | |
| 70 | +| `npm run start:production` | _Start the application in production_ | |
| 71 | +| `npm run build` | _Build the application for production_ | |
| 72 | +| `npm run build:watch` | _Build the application with watch mode_ | |
| 73 | +| `npm run clean` | _Clean application build artifacts_ | |
| 74 | + |
| 75 | +### 🛢️ Database |
| 76 | + |
| 77 | +| Command | Description | |
| 78 | +| ------- | ----------- | |
| 79 | +| `npm run db:pull` | _Pull database schema into Prisma across all schemas_ | |
| 80 | +| `npm run db:push` | _Push Prisma schema to the database across all schemas_ | |
| 81 | +| `npm run db:generate` | _Generate Prisma Client for all schemas_ | |
| 82 | +| `npm run db:migrate:dev` | _Run development migrations across all schemas_ | |
| 83 | +| `npm run db:migrate:deploy` | _Deploy migrations to production across all schemas_ | |
| 84 | +| `npm run db:studio` | _Open Prisma Studio (GUI) across all schemas_ | |
| 85 | +| `npm run db:reset` | _Reset database (pull + generate) for all schemas_ | |
| 86 | + |
| 87 | +### 🐳 Docker |
| 88 | + |
| 89 | +| Command | Description | |
| 90 | +| ------- | ----------- | |
| 91 | +| `npm run docker:build:development` | _Build Docker image for development_ | |
| 92 | +| `npm run docker:build:production` | _Build Docker image for production_ | |
| 93 | +| `npm run docker:run:development` | _Run development Docker container_ | |
| 94 | +| `npm run docker:run:production` | _Run production Docker container_ | |
| 95 | +| `npm run docker:compose:up:development` | _Start Docker Compose in development_ | |
| 96 | +| `npm run docker:compose:up:production` | _Start Docker Compose in production_ | |
| 97 | +| `npm run docker:compose:up:build:development` | _Start & rebuild Docker Compose in development_ | |
| 98 | +| `npm run docker:compose:up:build:production` | _Start & rebuild Docker Compose in production_ | |
| 99 | +| `npm run docker:compose:down` | _Stop Docker Compose services_ | |
| 100 | +| `npm run docker:compose:logs` | _View Docker Compose logs_ | |
| 101 | +| `npm run docker:prune` | _Clean up unused Docker resources_ | |
| 102 | + |
| 103 | +### 🧪 Testing |
| 104 | + |
| 105 | +| Command | Description | |
| 106 | +| ------- | ----------- | |
| 107 | +| `npm test` | _Run all tests once_ | |
| 108 | +| `npm run test:watch` | _Run tests in watch mode_ | |
| 109 | +| `npm run test:coverage` | _Run tests and generate a coverage report_ | |
| 110 | + |
0 commit comments