DEV Community

Arslon Erkinov
Arslon Erkinov

Posted on

Building a Real Analytics Engine in Django (AI Security SaaS)

Today I implemented a production-style analytics layer for my AI Phishing Defense Platform.

What was added?
Global Usage Metrics
Total requests
Requests today

Risk Distribution

High / Medium / Low counts
Percentage breakdown
Product-ready formatting

Daily Usage Trend

Using:

TruncDate + Count
This produces a 7-day usage trend that can directly power charts.

Per-User Stats

Each PRO API key now sees:
Its own total request count

Clean JSON Structure

Instead of returning flat data, the response is structured for dashboards:

{
"global_stats": {...},
"risk_distribution": {...},
"usage_by_plan": {...},
"daily_usage_trend": [...],
"my_usage": {...}
}

This makes frontend integration trivial.

Architectural Takeaway

Good analytics endpoints are:
Aggregated at DB level
Role-protected
Plan-aware
Structurally clean
Frontend-ready

This project is now evolving from an API experiment into a monetizable security SaaS.

Next milestone:
Latency tracking + error rate monitoring.

Top comments (0)