Skip to content

Enterprise-DNA-OS/ai-power-bi-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Power BI Analyzer

Open-source AI-powered Power BI data model analyzer and DAX/M code optimizer.

Built and open-sourced by Enterprise DNA — a leading data and AI education company.

What is it?Built with AIFeaturesTech StackQuick StartSelf-HostingArchitectureDev with AIContributingLicense

Vite 5 React 18 TypeScript Supabase Tailwind CSS Google Gemini MIT License


What is AI Power BI Analyzer?

AI Power BI Analyzer is a web application that ingests the metadata of a Power BI report (.pbix model) and produces AI-generated insights: DAX measure optimizations, Power Query (M) code reviews, data-model audits, performance bottleneck analysis, and a chat interface that lets you ask questions about your model in plain English.

Think of it as a Power BI co-pilot you self-host — bring your own Gemini key, your own Supabase, your own data, and the AI never has to phone home to a vendor SaaS.

Why another Power BI tool?

Most Power BI tooling stops at static analyzers and rule packs. This is different:

  • AI-first analysis — Gemini reads your DAX measures, M code, and model structure, then explains issues and proposes fixes in your context, not generic best-practice prose
  • Chat with your model — Ask "why is this measure slow?" or "is this relationship causing the wrong totals?" and get answers grounded in the actual model you uploaded
  • DAX + M + relationships in one place — not three different tools to stitch together
  • Self-hostable — Bring your own Supabase project, your own Gemini API key, and optionally your own Stripe credentials. Nothing leaves your infrastructure unless you want it to
  • Pluggable AI providers — Gemini is the default; OpenAI is wired in as an automatic fallback. Add OpenRouter or any other provider with a few lines in _shared/chat.ts
  • Open source — MIT licensed. Fork it, extend it, ship it

Built with AI

This entire application was built using AI-assisted development tools. Enterprise DNA believes in the future of AI-augmented software development, and this project is a reference for what's possible. Every Supabase migration, every edge function, every React component was developed collaboratively with AI coding agents.

AI Development Tools Used

Tool Role
Claude Code by Anthropic Primary development tool. Specialist agents (defined in AGENTS.md) each owned a specific domain.
Cursor AI-powered IDE used throughout development for code navigation, inline edits, and rapid iteration.
GitHub Copilot AI pair programming assistant for code completion and pattern matching.

Enterprise DNA is committed to demonstrating that AI tools are not just productivity boosters — they are a new way to build software. This project serves as a reference implementation for AI-assisted full-stack development.


Features

Power BI Ingestion

  • Upload extracted .pbix metadata as a project, scoped per user
  • Per-project Row Level Security — users only ever see their own models
  • Metadata stored as JSONB so you can re-run any analysis without re-uploading
  • Companion .pbix extractor utility (link configurable via VITE_PBIX_EXTRACTOR_URL)

AI Analysis

  • DAX measure optimization — Find slow measures and get suggested rewrites
  • M (Power Query) code review — Best-practice review of your data prep
  • Data model audit — Tables, relationships, cardinality, ambiguity warnings
  • Performance analysis — Likely bottlenecks called out with reasoning
  • Best-practices audit — Sweep against widely accepted Power BI guidance
  • Pluggable providers — Gemini default, OpenAI fallback, OpenRouter wired in _shared/chat.ts

Chat With Your Model

  • Conversational interface backed by the data-model-chat edge function
  • The AI sees the model structure (tables + relationships), DAX measures, and M code as part of its context
  • Ask follow-up questions about a specific measure or about the model as a whole

AI Advisor Sidebar

  • Inline advisor that watches what you're looking at on the dashboard and surfaces relevant suggestions
  • Independent of the chat — runs as a separate Supabase Edge Function (ai-advisor)

Project Management

  • Multi-project workspaces, each with its own metadata blob and run history
  • Rename or delete projects from the projects page
  • Resume in-progress analysis runs (status + progress are persisted)

Authentication

  • Email + password via Supabase Auth
  • Password reset flow with email confirmation
  • Protected routes via ProtectedRoute component (redirects to /auth)

Optional: Subscription Billing

  • Stripe checkout, billing portal, and subscription mirror are included as edge functions
  • Disabled by default in App.tsx — uncomment and configure if you want a paid tier

UI / UX

  • Responsive dashboard (mobile-friendly)
  • Dark-mode-ready via next-themes
  • Rich form controls powered by shadcn/ui + Radix
  • Inline DAX / M code viewing via Monaco Editor

Tech Stack

Layer Technology
Build / Framework Vite 5 + React 18
Language TypeScript 5
UI Library shadcn/ui + Radix UI
Styling Tailwind CSS 3
Icons Lucide React
Routing React Router 6
Forms React Hook Form + Zod
Data fetching TanStack Query
Code Editor Monaco Editor
Database / Auth Supabase (PostgreSQL + Row Level Security + Auth)
AI Runtime Supabase Edge Functions (Deno) calling Google Gemini, with OpenAI / OpenRouter fallback
Billing (optional) Stripe via @stripe/react-stripe-js
Deployment Netlify, Vercel, or any static host + Supabase

Quick Start

Prerequisites

  • Node.js 20+ and npm (Bun also works if you prefer)
  • A Supabase account (free tier works)
  • A Google Gemini API key — required for analysis. OpenAI is wired in as a fallback

Step 1: Clone and Install

git clone https://github.com/Enterprise-DNA-OS/ai-power-bi-analyzer.git
cd ai-power-bi-analyzer
npm install

Step 2: Create Your Supabase Project

  1. Sign in at supabase.com and click New Project
  2. Wait for the project to provision (~2 minutes)
  3. From Settings -> API, copy:
    • Project URL -> VITE_SUPABASE_URL
    • anon / public key -> VITE_SUPABASE_ANON_KEY

Step 3: Configure Environment Variables

cp .env.example .env.local

Edit .env.local with your credentials. At minimum:

VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-key

See .env.example for the full list, including the optional Stripe and VITE_PBIX_EXTRACTOR_URL settings.

Step 4: Apply Database Schema

Install the Supabase CLI and link your project:

npm install -g supabase
npx supabase login
npx supabase link --project-ref your-project-id

Push the migrations:

npx supabase db push

This creates bim_metadata, analysis_types, analysis_results, and (optional) subscriptions with Row Level Security policies enabled. The migration also seeds a starter set of analysis types so the app works out-of-the-box.

Step 5: Deploy Edge Functions

The AI analysis runs in Supabase Edge Functions:

npx supabase functions deploy

This deploys run-analysis, ai-advisor, data-model-chat, and (optional) stripe-checkout-session, stripe-billing-portal, stripe-subscriptions.

Step 6: Set Edge Function Secrets

Edge functions receive secrets via supabase secrets set, not .env.local:

# Required for AI analysis
npx supabase secrets set GEMINI_API_KEY=your_gemini_key

# Optional fallback / alternative providers
npx supabase secrets set OPENAI_API_KEY=your_openai_key
npx supabase secrets set OPENROUTER_API_KEY=your_openrouter_key

# Optional: Stripe for billing
npx supabase secrets set STRIPE_SECRET_KEY=sk_live_...
npx supabase secrets set STRIPE_WEBHOOK_SECRET=whsec_...

Step 7: Run Locally

npm run dev

Open http://localhost:8080, sign up for an account, upload a .pbix metadata extract, pick an analysis type, and watch the AI go to work.


Self-Hosting

Netlify (recommended)

  1. Push the repo to your own GitHub account (or fork it directly)
  2. Connect the repo to Netlify
  3. Add VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY (and any other VITE_* vars) in Site settings -> Environment variables
  4. Build command: npm run build — Publish directory: dist
  5. Deploy

A netlify.toml is included with a sensible default redirects file.

Vercel

  1. Push the repo to your own GitHub account
  2. Import in Vercel
  3. Add the VITE_* environment variables
  4. Vercel auto-detects Vite. Build command npm run build, output dist
  5. Deploy

Static host + Supabase

The app is a pure SPA — npm run build produces a dist/ directory you can serve from any static host (Cloudflare Pages, S3 + CloudFront, GitHub Pages, etc.). Make sure the host serves index.html for unknown routes (SPA fallback).

Docker

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx-spa.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

Where nginx-spa.conf contains an SPA fallback (try_files $uri $uri/ /index.html;).

Production Deployment Checklist

  1. Update environment variables — Set every .env.example variable in your hosting platform
  2. Set edge function secretsGEMINI_API_KEY is required; rotate it if it ever appears in logs
  3. Supabase Auth redirect URLs — Add your production domain under Supabase Auth settings
  4. Rate-limit edge functions — AI calls cost money. Add a limiter (Supabase rate limits, Cloudflare, or your reverse proxy)
  5. Enable HTTPS — Required for Supabase Auth
  6. Monitor edge function logs — Check the Supabase dashboard for analysis failures and AI provider errors

Architecture

Project Structure

src/
  App.tsx                     Top-level routes + providers
  main.tsx                    Vite entry
  pages/
    Auth.tsx                  Sign in + password reset
    Register.tsx              Sign up
    UpdatePassword.tsx        Reset-link landing page
    Index.tsx                 Public landing page
    Projects.tsx              Authenticated project list
    CreateProject.tsx         Upload + create flow
    Dashboard.tsx             Per-project analysis surface
    Profile.tsx               Account info
    PricingPage.tsx           Optional Stripe pricing card
    PaymentSuccess.tsx        Stripe success callback
    NotFound.tsx              404
  components/
    ui/                       shadcn/ui primitives
    homepage/                 Landing page sections (Hero, TrustIndicators, HowItWorks, etc.)
    dashboard/                Dashboard surface
    ai-advisor/               AI advisor sidebar
    ai-assistant/             Inline AI helpers (text selector, etc.)
    analysis/                 Analysis viewers and selectors
    data-model-chat/          Chat-with-the-model UI
    project-form/             Upload + create-project flow
    projects/                 Project list + cards
    Navigation.tsx            Top nav
    Footer.tsx                Bottom nav
    ProtectedRoute.tsx        Auth gate
    CodeEditor.tsx            Monaco wrapper
  contexts/                   UserContext, AIAdvisorContext, DataModelChatContext, SubscriptionContext
  hooks/                      useAnalysis, useAnalysisResults, useAuthCheck, useSupabaseFunction, ...
  integrations/supabase/
    client.ts                 The singleton Supabase client (env-driven)
    types.ts                  Generated Database types
  types/                      Shared TypeScript types
  utils/                      bimProcessor, formulaFormatter, project, storageUtils, supabaseFunctions
supabase/
  config.toml                 Edge function configuration
  migrations/
    20260430000000_initial_schema.sql
  functions/
    _shared/
      chat.ts                 Gemini wrapper (with OpenAI fallback)
      m-code.ts               M (Power Query) extraction
      dax-code.ts             DAX measure extraction
      data-model.ts           Tables / relationships extraction
    run-analysis/             Main analysis runner
    ai-advisor/               AI advisor chat backend
    data-model-chat/          Chat-with-the-model backend
    stripe-checkout-session/  Optional billing
    stripe-billing-portal/    Optional billing
    stripe-subscriptions/     Optional billing (Stripe webhook handler)

Request Flow: Running an Analysis

User picks an analysis type
  -> supabase.functions.invoke("run-analysis", { analysis_type_id, metadata_id, ... })
    -> Edge function (Deno) reads analysis_type + bim_metadata
      -> _shared/m-code.ts / dax-code.ts / data-model.ts extract relevant slices
        -> _shared/chat.ts -> Gemini (or OpenAI fallback)
        <- Markdown analysis
      -> analysis_results row updated with content + status='completed'
  <- Realtime / polling pushes the result to the dashboard

Request Flow: Chat With Your Model

User opens chat, types question
  -> supabase.functions.invoke("data-model-chat", { messages, metadata_id })
    -> Edge function loads model structure + recent analysis results
    -> Builds a system prompt with that context
    -> _shared/chat.ts -> Gemini
  <- Streamed (or single) response rendered in DataModelChatSidebar

All AI keys live in Supabase Edge Function secrets. They never touch the browser.

Database Schema

The bundled migration creates:

  • bim_metadata — Uploaded Power BI projects, one per user-uploaded .pbix. JSONB metadata column holds the extracted model.
  • analysis_types — Catalogue of analysis flavors (DAX, M code, performance, etc.). Read-only for users.
  • analysis_results — Output of each analysis run. Links to bim_metadata and analysis_types. Status + progress are persisted so runs can be resumed.
  • subscriptions — Optional Stripe mirror. Only used if you enable billing.

Row Level Security is enforced on every user-facing table:

  • Users see their own bim_metadata
  • Users see analysis_results only for projects they own
  • analysis_types is shared, read-only catalogue
  • subscriptions is owner-only

Edge Functions

Function Purpose
run-analysis Main analysis runner. Reads metadata, extracts the relevant slice (M / DAX / model), calls Gemini via _shared/chat.ts, writes back to analysis_results.
ai-advisor Inline advisor sidebar backend. Watches user context and offers suggestions.
data-model-chat Conversational backend. Loads model + recent analysis as context, calls Gemini.
stripe-checkout-session (Optional) Creates a Stripe Checkout session for subscription signup.
stripe-billing-portal (Optional) Generates a Stripe Billing Portal URL for the current customer.
stripe-subscriptions (Optional) Stripe webhook handler that mirrors subscription state into the subscriptions table.

Developing with AI Tools

This project is designed to work well with AI development tools. Two files make this explicit:

  • CLAUDE.md — Project-wide instructions, conventions, and architecture overview. Claude Code reads this automatically.
  • AGENTS.md — Defines specialist agents with clear ownership boundaries.

Using Claude Code

Open the project folder in Claude Code. The agent will pick up CLAUDE.md and AGENTS.md automatically and follow the conventions.

Using Cursor

Open the project in Cursor. The CLAUDE.md file serves as context for Cursor's AI features. Use inline edit (Cmd+K) for quick changes and the chat panel for larger refactors.

Using GitHub Copilot

Copilot picks up patterns from the existing codebase (Supabase client usage, auth checks, Tailwind conventions). The consistent conventions in CLAUDE.md make Copilot suggestions more accurate.

Contributing with AI Tools

We encourage contributors to use AI tools. If you submit a PR:

  1. Mention which AI tools you used — we see it as a positive
  2. Follow the conventions in CLAUDE.md
  3. Use the specialist agent boundaries in AGENTS.md
  4. Run npm run typecheck && npm run lint && npm run build before submitting

Contributing

See CONTRIBUTING.md for detailed guidelines.

TL;DR:

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes (AI tools welcome)
  4. Run npm run typecheck && npm run lint && npm run build to verify
  5. Commit with a descriptive message
  6. Push to your fork and open a PR

License

MIT — use it however you want.


Acknowledgments


Built with pride by Enterprise DNA
Powered by AI-assisted development with Claude Code, Cursor, and GitHub Copilot

Releases

No releases published

Packages

 
 
 

Contributors

Languages