How lalabuy948/phoenixanalytics works
• Phoenix Application Integration:
• Analytics Plug (PhoenixAnalytics.Plugs.RequestTracker) inserted into endpoint (as per the README instructions).
• Routing and Controller components in the “web” directory (both traditional controllers and LiveView components such as the dashboard and charts).
• Data Processing and Storage:
• Services and Queries (in lib/phoenix_analytics/services and lib/phoenix_analytics/queries) which handle batching, telemetry, caching, and the building of stats/charts.
• Entities and migrations (in lib/phoenix_analytics/entities and priv/repo) that define data schemas and migration scripts.
• Storage Options:
• DuckDB for lightweight, separate analytics storage (used by default to avoid interference with the main database).
• Postgres (optionally enabled in configuration) including caching and connection management if running in a dynamic/distributed environment.
• Frontend & Dashboard:
• React components (in assets/react) and LiveView (in lib/phoenix_analytics/web/live) that together build the dashboard UI and charting components.
• Static assets and configuration for Tailwind CSS alongside JavaScript files which style and animate the dashboard.
• External Integration / Example Applications:
• Example projects (e.g., examples/duck_only, examples/duck_postgres, examples/duck_postgres_in_memory) that show how to wire up the analytics plug, manage configuration, and launch a server.
Relationships and interactions
• The RequestTracker plug collects relevant user and request data, then passes the data to the analytics service layer.
• The Services (such as the Batcher and Cache modules) process the data asynchronously and invoke queries that populate the analytics database.
• The Query layer handles retrieving data to build statistics and charts. This data is then served to the dashboard.
Architectural patterns and design principles
• Separation of Concerns: The analytics logic is clearly separated from the primary application logic via the plug and independent storage (via configuration options).
• Modularity: The project is organized into distinct modules (web, services, queries, entities) making it easier to extend or replace components.
• Extensibility: Options in the configuration (like in_memory flag, caching options, multiple storage choices) allow the same core plug-and-play tool to be tailored for different Phoenix deployment scenarios.