$ show teslamate-org/teslamate
TeslaMate is a self-hosted data logger for Tesla vehicles that collects telemetry via the Tesla API (both polling and streaming), stores data in PostgreSQL, and provides visualization through a Phoenix LiveView web interface and Grafana dashboards. It integrates with home automation systems via MQTT and supports importing historical vehicle data from CSV files (TeslaFi format). The application uses a supervision tree to manage background processes for data collection, MQTT publishing, import tasks, and update checking. Key features include geofencing for location-based cost tracking, encrypted storage for API tokens using Cloak, internationalization via Gettext, and custom Ecto expressions for geographic calculations. The architecture is monolithic with clear separation of concerns through Phoenix contexts (Log, Vehicles, Settings, Locations).
The LLM identified 7 files worth highlighting for reuse:
Provides transparent encryption and decryption of sensitive database fields (e.g., API tokens) using the Cloak library. This component isolates encryption logic, making it reusable in other projects requiring Ecto-based field encryption.
Encapsulates MQTT publishing with connection management, QoS handling, and timeout management using the Tortoise311 library. Includes circuit breaker patterns to prevent cascading failures, making it a resilient and reusable MQTT client for other applications.
Handles validation and type conversion of CSV rows during import (TeslaFi format). Separates validation logic from the import process, providing a reusable pattern for ETL pipelines that require robust data validation and timezone-aware parsing.
Provides resilient reverse geocoding with caching and circuit breaker (using Fuse) to handle rate limits and service failures. Abstracts the Nominatim API with fallback mechanisms, making it a reusable component for any application needing geocoding with fault tolerance.
Manages elevation data lookup from SRTM with caching and circuit breaker patterns. Used to enrich vehicle position data with elevation, demonstrating a reusable pattern for external service calls that require fault tolerance and performance optimization.
Phoenix plug for locale detection from query parameters, session, or Accept-Language header. Sets the locale for Gettext translations, providing a reusable and configurable solution for internationalization in Phoenix applications.
Defines custom Ecto expressions for geographic calculations (e.g., within_geofence, distance) that can be used directly in queries. Enables efficient geofencing and distance calculations at the database level, offering a reusable pattern for extending Ecto with domain-specific functions.