PowerMonitor API is a backend service for monitoring, collecting, and analyzing power consumption and availability data. Built with NestJS and TypeScript, it provides RESTful endpoints for retrieving and managing power, voltage, amperage, and energy metering data, as well as system and calibration information.
- Collects and stores power, voltage, amperage, and energy metering data
- Provides daily, monthly, and yearly statistics on power consumption and availability
- Supports calibration coefficients and system information endpoints
- Scheduled tasks for data cleanup and maintenance
- JWT-based authentication and role-based access control
- MQTT integration for real-time data
- Logging with Winston
- Real-time updates via WebSockets (Socket.IO)
- Receives serial data frames from the monitoring board over a serial port, e.g.:
{ "type": "data", "voltage": 220.0, "current": 5.0, "frequency": 50.0 } - Centralized logging to Elasticsearch (via Winston Elasticsearch transport)
- Application Performance Monitoring with Elastic APM (elastic-apm-node)
src/modules/β NestJS modules, grouping related controllers and servicessrc/entities/β TypeORM entities (database models)src/common/β Shared DTOs, models, interfaces, and utilitiessrc/migrations/β Database migration scriptssrc/constants.tsβ Application-wide constantssrc/environments.tsβ Environment configurationsrc/main.tsβ Application entry pointtests/β Unit tests (Mocha + Chai)
- Node.js (v20+ recommended)
- npm
- PostgreSQL database
- Clone the repository:
git clone <repo-url> cd PowerMonitor.API
- Install dependencies:
npm install
- Configure environment variables:
- Copy
development.envorproduction.envand update with your settings.
- Copy
- Configure your PostgreSQL connection in
src/ormconfig.tsor via environment variables. - Run migrations if needed.
- Development mode:
npm run start:dev
- Production build:
npm run build npm run start:prod
- Power data:
/api/power/* - Power consumption:
/api/power-consumption/* - Services/system info:
/api/services/* - WebSocket real-time data: Socket.IO endpoint at
/socket.io/
Most endpoints require JWT authentication.
npm run buildβ Build for productionnpm run packageβ Lint, version bump, replace build, and compilenpm run build-devβ Build in development modenpm run startβ Run with ts-nodenpm run start:devβ Start in watch/dev modenpm run start:prodβ Run the production buildnpm run start:debugβ Run in debug modenpm run lintβ Lint the codebasenpm run formatβ Format code with Prettiernpm run testβ Execute unit tests (Mocha + ts-node)npm run coverageβ Generate code coverage report
Copyright (c) 2025 Serhiy Krasovskyy xhunter74@gmail.com