Rails DB Analytics
webmatze/rails_db_analytics
Relatórios de dados via linguagem natural com Claude para Rails
Ver no GitHubEngine Rails que gera e executa relatórios de análise de dados usando LLMs (Claude) baseado em descrições em linguagem natural. Lê o schema da aplicação, interpreta requisições de análise e gera queries ActiveRecord seguras automaticamente.
Instalação
npx convez-ai webmatze/rails_db_analytics1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.
Métricas
Casos de uso
- Gerar relatórios de análise de dados sem escrever SQL manualmente
- Explorar tendências e padrões na base de dados via descrição natural
- Dashboard interativo de analytics para aplicações Rails
Veredito

Solução prática que democratiza análise de dados em Rails ao eliminar necessidade de escrever queries. Bem implementada com cache, segurança de query e UI moderna, embora dependa de créditos de API Claude para funcionar.
README
A tradução para o português deste README ainda está na fila.
Rails DB Analytics
Rails DB Analytics is a powerful Rails engine that provides database analytics functionality by leveraging Large Language Models (LLM) to generate and execute data analysis reports. It analyzes your application's schema and allows users to create reports using natural language descriptions.
Features
- 📊 Generate data analysis reports using natural language descriptions
- 🤖 Powered by Claude 3 Sonnet for intelligent query generation
- 📈 Interactive dashboard for managing reports
- 🔄 Real-time data refresh capabilities
- 🎨 Modern UI with Tailwind CSS
- ⚡️ Hotwire/Stimulus for dynamic interactions
- 🔒 Safe query generation with ActiveRecord
- 📦 Easy installation and configuration
Installation
Add this line to your application's Gemfile:
gem 'rails_db_analytics'
And then execute:
bundle install
Run the installation generator:
bin/rails generate rails_db_analytics:install
Configuration
Configure the engine in config/initializers/rails_db_analytics.rb:
RailsDbAnalytics.configure do |config|
config.anthropic_api_key = Rails.application.credentials.dig(:anthropic, :api_key)
# Optional configurations
config.llm_model = "claude-3-sonnet-20240229"
config.max_tokens = 4096
config.temperature = 0.7
config.schema_path = Rails.root.join('db/schema.rb')
config.cache_store = Rails.cache
config.cache_responses = Rails.env.production?
config.cache_ttl = 1.hour
end
Usage
- Visit
/analyticsin your Rails application - Click "New Report" to create a data analysis report
- Provide a natural language description of the data you want to analyze
- The engine will:
- Read your schema.rb
- Generate a DataReport subclass using Claude
- Execute the report
- Display the results
Example Report Descriptions
"Show me the top 10 users who have created the most posts in the last month,
including their total posts and average post length"
"Analyze the order trends over the last quarter, showing total revenue by
product category and identifying the best-selling products"
"Generate a user engagement report showing daily active users, average session
duration, and most used features in the last week"
How It Works
-
Schema Analysis: The engine reads your Rails application's schema.rb to understand the database structure, relationships, and available data.
-
Report Generation: When you create a new report:
- Your description is sent to Claude along with the schema
- Claude generates a DataReport subclass with appropriate ActiveRecord queries
- The report is saved and can be re-run at any time
-
Data Collection: The generated report class:
- Implements
report_datato fetch data using ActiveRecord - Implements
format_datato structure the results - Supports date ranges for temporal analysis
- Implements
Example generated report class:
class UserEngagementReport < RailsDbAnalytics::DataReport
def report_data
User.joins(:sessions)
.where(sessions: { created_at: date_range })
.group('users.id')
.select(
'users.*, ' \
'COUNT(sessions.id) as session_count, ' \
'AVG(sessions.duration) as avg_duration'
)
end
def format_data(data)
{
total_active_users: data.count,
average_sessions_per_user: data.average(:session_count).round(2),
average_session_duration: data.average(:avg_duration).round(2),
most_active_users: data.order('session_count DESC').limit(5)
.map { |u| { name: u.name, sessions: u.session_count } }
}
end
end
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/webmatze/rails_db_analytics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Rails DB Analytics project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.