Back to portfolio
WebappStudy / personal

MyElectrica

Standalone web application that syncs MyElectrica data into a PostgreSQL model and centralizes contracts, consumption points, invoices, payments, meters, self-readings, and consumption statistics.

MyElectrica

Core stack

TypeScript
Node.js
Hono
PostgreSQL
Drizzle ORMSvelteKit 2Svelte 5Tailwind CSS 4VitepdftotextNode.js Crypto

The challenge

The challenge was turning an API oriented toward the provider's own account into a coherent, fast web experience: multiple contract/NLC levels, tokens that can expire, SAP data with non-uniform formats, live operations such as self-reading and payment, plus useful information available only in invoice PDFs. At the same time, syncing had to avoid excessive requests and keep the historical data structured enough for analysis.

The solution

The solution separates provider access from the app experience. Hono orchestrates authentication, resource authorization, and syncing; Drizzle models the relationships and applies indexes/unique keys for upsert and deduplication; PostgreSQL keeps the local history. PDFs are processed server-side and the result is cached in JSONB with a version and TTL. SvelteKit consumes the backend through server-side loads and endpoints, offers a global NLC selector and responsive screens, and the statistical aggregations are computed on the backend to keep the browser simple and interactive.

Notable complexity

MyElectrica is a personal project built as a standalone web application on top of the flows available in a MyElectrica account. Instead of directly displaying every provider response, the backend syncs the client → contract → consumption point (NLC) hierarchy, invoices, payments, meters, registers, readings, contract details, and consumption conventions into a PostgreSQL database. The local data enables fast queries, filtering, pagination, and historical analysis without every screen depending on a live call to the provider.

The backend is implemented in TypeScript with Hono, Drizzle ORM, and PostgreSQL. Authentication validates credentials through the MyElectrica API, creates its own session, and keeps the upstream password encrypted with AES-256-GCM for automatic re-authentication when the provider's token expires. Sync uses upserts and unique keys for the main entities, normalizes the data and numeric values coming from the API, and runs in a controlled, sequential manner to avoid request bursts.

Invoices have a second level of processing: the provider's PDF can be downloaded server-side, converted to text with pdftotext, and parsed into a structure with billing period, consumption, VAT, previous balance, total due, meter, billed line items, and penalties. The result is persisted in a versioned JSONB cache, invalidated when the source changes, the parser version changes, or the TTL expires. This layer feeds both the detailed invoice modal and the cost/consumption analyses.

The SvelteKit 2 / Svelte 5 frontend is server-rendered and uses a server-side layer for communicating with the backend, so the session key stays in an httpOnly cookie. The responsive interface includes a financial dashboard, an invoice list with status and payment initiation, payment history, meters and readings, self-reading submission within the PAC window, contract details, editing the consumption convention, and a statistics area. The statistics aggregate monthly cost and consumption, average price per kWh, cost structure, payment behavior, seasonality, year-over-year comparison, index evolution, and actual consumption versus convention.

The public cnecrea/myelectrica integration for Home Assistant was documented as a functional reference point. The implementation analyzed here, however, has a different surface: it is a standalone full-stack application with its own database, sync and cache, payment/self-reading flows, and dedicated web dashboards. No Home Assistant integration features nor the provider's API are claimed as having been built by this project's author.

Key results

  • Standalone application with dashboard, invoices, payments, readings, contracts, and statistics in a single responsive interface
  • Persistent relational model for clients, contracts, NLCs, meters, registers, invoices, payments, readings, contract details, and conventions
  • MyElectrica data synchronization with normalization, upsert, and deduplication on the available business keys
  • Server-side parser for invoice PDFs, extracting consumption, VAT, balance, billed items, and penalties
  • Versioned JSONB cache for invoice details, with TTL and invalidation when the source or the parser version changes
  • Payment initiation for unpaid invoices through the provider's API flow and redirect to the received payment URL
  • Submitting self-readings and updating the consumption convention for NLCs belonging to the authenticated user
  • Server-side analytics for monthly cost and consumption, average price per kWh, cost structure, payment behavior, seasonality, and year-over-year comparison
  • Light/dark interface adapted for desktop and mobile, with a persistent selector for multiple consumption points

Related projects

Want something similar?

Start with the estimate wizard — answer a few questions and get a realistic price range and timeline.