Skip to content

metashwat/ytmetrix

Repository files navigation

YTMetrix

YouTube Analytics Dashboard with AI-Powered Insights

License Next.js React Supabase

A comprehensive YouTube analytics platform that helps creators understand their channel performance, track video metrics, and gain AI-powered insights to improve their content strategy.


✨ Features

  • � Channel Analytics - Track views, watch time, subscribers, and engagement
  • 🎬 Video Performance - Per-video metrics with goal-based scoring
  • 🤖 AI Insights - Content analysis powered by Google Gemini
  • 🎯 Goal Profiles - Custom scoring based on your content goals
  • � Trend Analysis - Track performance changes over time
  • 🔍 Segment Analysis - Group videos by playlists or custom criteria
  • 📧 Email Reports - Automated weekly/monthly digests

🚀 Quick Start

Prerequisites

  • Node.js 20+
  • pnpm 10.x (npm install -g pnpm)
  • Supabase account (free tier works)
  • Google Cloud project with YouTube APIs enabled

1. Clone & Install

git clone https://github.com/your-username/ytmetrix.git
cd ytmetrix
pnpm install

2. Set Up Supabase

  1. Create a new project at supabase.com

  2. Go to Project Settings → API and copy:

    • Project URL
    • Anon/Public key
    • Service Role key (keep this secret!)
  3. Run the database migrations:

# Apply all migrations to your Supabase project
# You can use the Supabase CLI or run migrations manually in the SQL editor
cd supabase/migrations
# Apply each migration file in order

3. Set Up Google Cloud

  1. Go to Google Cloud Console
  2. Create a new project (or use existing)
  3. Enable these APIs:
    • YouTube Data API v3
    • YouTube Analytics API
  4. Create OAuth 2.0 credentials:
    • Go to APIs & Services → Credentials
    • Click Create Credentials → OAuth client ID
    • Application type: Web application
    • Authorized redirect URIs:
      • http://localhost:3000/api/auth/google/callback (development)
      • https://your-domain.com/api/auth/google/callback (production)
  5. Create an API Key:
    • Click Create Credentials → API Key
    • Restrict to YouTube Data API v3 (recommended)

4. Configure Environment

cp .env.example .env

Edit .env with your credentials:

# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

# Google OAuth
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
YOUTUBE_API_KEY=your-api-key

# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
NODE_ENV=development

5. Start Development

pnpm dev:all

Open http://localhost:3000


📁 Project Structure

ytmetrix/
├── apps/
│   └── web/                    # Next.js 16 application
│       └── src/
│           ├── app/            # App Router pages & API routes
│           ├── components/     # React components
│           └── lib/            # Utilities & API clients
├── supabase/
│   └── migrations/             # Database migrations (SQL)
├── scripts/                    # Utility scripts
├── tests/                      # Test suites
├── docs/                       # Documentation
└── render.yaml                 # Render deployment config

🔧 Tech Stack

Layer Technology
Frontend Next.js 16, React 19, TypeScript, TailwindCSS 4
UI shadcn/ui, Radix UI, Lucide Icons, Recharts
Backend Next.js API Routes
Database Supabase PostgreSQL with Row Level Security
AI Google Gemini, OpenAI (embeddings)
Auth Supabase Auth + Google OAuth

�️ Database Schema

The database uses a multi-schema architecture:

  • public - User-facing tables with RLS
  • b (bronze) - Raw data from YouTube APIs
  • s (silver) - Processed/aggregated data
  • g (gold) - AI-generated insights

Key tables:

  • channels - Connected YouTube channels
  • videos - Video metadata
  • channel_access - User-channel permissions
  • goal_taxonomy - Goal profiles and scoring weights

🚢 Deployment

Docker (Recommended)

Pull and run the pre-built image from GitHub Container Registry:

# Pull the latest image
docker pull ghcr.io/your-username/ytmetrix:latest

# Run with environment variables
docker run -p 3000:3000 \
  -e NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co \
  -e NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key \
  -e SUPABASE_SERVICE_ROLE_KEY=your-service-role-key \
  -e GOOGLE_CLIENT_ID=your-client-id \
  -e GOOGLE_CLIENT_SECRET=your-client-secret \
  -e YOUTUBE_API_KEY=your-api-key \
  ghcr.io/your-username/ytmetrix:latest

Or use Docker Compose:

# Copy environment file
cp .env.example .env
# Edit .env with your values

# Run with docker-compose
docker compose up -d

Build Docker Image Locally

docker build \
  --build-arg NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co \
  --build-arg NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key \
  -t ytmetrix:local .

docker run -p 3000:3000 ytmetrix:local

Render

  1. Fork this repository
  2. Connect to Render
  3. Create a new Blueprint from render.yaml
  4. Set environment variables in Render dashboard
  5. Deploy!

Vercel / Netlify

Works with any Next.js-compatible platform. Set the environment variables and deploy.

Environment Variables for Production

# Required
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
YOUTUBE_API_KEY=your-api-key
NEXT_PUBLIC_APP_URL=https://your-domain.com

# Optional - AI Features
GOOGLE_GEMINI_API_KEY=your-gemini-key
OPENAI_API_KEY=your-openai-key

# Optional - Email
RESEND_API_KEY=your-resend-key

# Optional - Cron Security
CRON_SECRET=random-secret-string

⏰ Cron Jobs

The app includes scheduled jobs for data synchronization:

Job Schedule Purpose
Channel Sync Daily 1 AM UTC Sync channel metrics
Video Sync Daily 1:30 AM UTC Sync video metrics
Watchlist Sync Daily 2 AM UTC Sync watched channels
Alert Processing Daily 4 AM UTC Process alert rules

Configure CRON_SECRET to secure cron endpoints.


🧪 Testing

# Run all tests
pnpm test

# Run specific category
node tests/run-all-tests.mjs --category=api

See tests/README.md for details.


� Documentation

Document Purpose
docs/DEPLOYMENT.md Deployment guide
docs/PRODUCT_CONTEXT.md Product overview
docs/architecture/ System architecture
docs/EPICS.md Feature development history

🔒 Security

  • OAuth 2.0 for YouTube authentication
  • Row Level Security (RLS) on all database tables
  • Encrypted tokens stored in Supabase
  • HTTPS only in production
  • No write access to YouTube - read-only analytics

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

📜 License

MIT License - see LICENSE for details.


🙏 Acknowledgments

About

A free, supercharged analytics platform with AI features(BYOK) for serious YouTubers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors