Setup Tweetalytics

Get your AI-powered social media platform up and running in minutes

Step 1

Clone Repository & Install

Get the codebase and install dependencies

Clone the repository: git clone https://github.com/sushiselite/auto-social.git
Navigate to the project: cd auto-social
Install dependencies: npm install
Copy environment file: cp env.example .env.local

Commands

git clone https://github.com/sushiselite/auto-social.git
cd auto-social
npm install
cp env.example .env.local
Step 2

Set up Supabase

Create your Supabase project and database

Go to https://supabase.com and create a new project
Copy your project URL and anon key from Settings > API
Copy your service role key from Settings > API (keep this secret!)
Run the SQL commands in the SQL Editor to create tables and policies
Run the additional migrations for enhanced features

SQL Commands

-- Users table
CREATE TABLE users (
  id UUID REFERENCES auth.users ON DELETE CASCADE PRIMARY KEY,
  username TEXT,
  preferences JSONB DEFAULT '{}',
  created_at TIMESTAMP WITH TIME ZONE DEFAULT TIMEZONE('utc'::text, now()) NOT NULL
);

-- Ideas table
CREATE TABLE ideas (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
  user_id UUID REFERENCES users(id) ON DELETE CASCADE,
  content TEXT,
  type TEXT CHECK (type IN ('text', 'voice')),
  audio_url TEXT,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT TIMEZONE('utc'::text, now()) NOT NULL
);

-- Tweets table
CREATE TABLE tweets (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
  user_id UUID REFERENCES users(id) ON DELETE CASCADE,
  idea_id UUID REFERENCES ideas(id) ON DELETE CASCADE,
  content TEXT,
  status TEXT CHECK (status IN ('generated', 'in_review', 'approved', 'published')) DEFAULT 'generated',
  scheduled_time TIMESTAMP WITH TIME ZONE,
  performance JSONB,
  viral_score INTEGER,
  authenticity_score INTEGER,
  engagement_score INTEGER,
  quality_score INTEGER,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT TIMEZONE('utc'::text, now()) NOT NULL
);

-- Training examples table
CREATE TABLE training_examples (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
  user_id UUID REFERENCES users(id) ON DELETE CASCADE,
  tweet_text TEXT NOT NULL,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT TIMEZONE('utc'::text, now()) NOT NULL
);

-- Tweet feedback table
CREATE TABLE tweet_feedback (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
  tweet_id UUID REFERENCES tweets(id) ON DELETE CASCADE,
  user_id UUID REFERENCES users(id) ON DELETE CASCADE,
  comment TEXT,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT TIMEZONE('utc'::text, now()) NOT NULL
);

-- Enable Row Level Security
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
ALTER TABLE ideas ENABLE ROW LEVEL SECURITY;
ALTER TABLE tweets ENABLE ROW LEVEL SECURITY;
ALTER TABLE training_examples ENABLE ROW LEVEL SECURITY;
ALTER TABLE tweet_feedback ENABLE ROW LEVEL SECURITY;

-- Create policies
CREATE POLICY "Users can view own data" ON users FOR SELECT USING (auth.uid() = id);
CREATE POLICY "Users can update own data" ON users FOR UPDATE USING (auth.uid() = id);
CREATE POLICY "Users can insert own data" ON users FOR INSERT WITH CHECK (auth.uid() = id);

CREATE POLICY "Users can manage own ideas" ON ideas FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Users can manage own tweets" ON tweets FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Users can manage own training examples" ON training_examples FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Users can manage own feedback" ON tweet_feedback FOR ALL USING (auth.uid() = user_id);

-- Add indexes for performance
CREATE INDEX IF NOT EXISTS idx_tweets_viral_score ON tweets(viral_score);
CREATE INDEX IF NOT EXISTS idx_tweets_authenticity_score ON tweets(authenticity_score);
CREATE INDEX IF NOT EXISTS idx_tweets_engagement_score ON tweets(engagement_score);
CREATE INDEX IF NOT EXISTS idx_tweets_quality_score ON tweets(quality_score);

-- Add constraints to ensure scores are within 0-100 range
ALTER TABLE tweets ADD CONSTRAINT viral_score_range CHECK (viral_score >= 0 AND viral_score <= 100);
ALTER TABLE tweets ADD CONSTRAINT authenticity_score_range CHECK (authenticity_score >= 0 AND authenticity_score <= 100);
ALTER TABLE tweets ADD CONSTRAINT engagement_score_range CHECK (engagement_score >= 0 AND engagement_score <= 100);
ALTER TABLE tweets ADD CONSTRAINT quality_score_range CHECK (quality_score >= 0 AND quality_score <= 100);

-- Function to handle user creation
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
  INSERT INTO public.users (id, username, preferences, created_at)
  VALUES (
    NEW.id,
    COALESCE(NEW.raw_user_meta_data->>'name', NEW.email),
    '{
      "defaultTone": "professional",
      "timezone": "UTC",
      "notifications": true,
      "autoSchedule": false
    }'::jsonb,
    NOW()
  );
  RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

-- Trigger to call the function when a new user signs up
DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;
CREATE TRIGGER on_auth_user_created
  AFTER INSERT ON auth.users
  FOR EACH ROW EXECUTE FUNCTION public.handle_new_user();
Step 3

Get Anthropic API Key

Set up Claude AI for tweet generation

Visit https://console.anthropic.com
Create an account or sign in
Go to API Keys section
Create a new API key
Copy the key (starts with "sk-ant-")
Add credits to your account for production use

Note: Claude API provides excellent content generation. You'll need to add credits to your account for production use.

Step 4

Get OpenAI API Key

Set up Whisper for voice transcription

Visit https://platform.openai.com
Create an account or sign in
Go to API Keys section
Create a new secret key
Copy the key (starts with "sk-")
Add billing information for API usage

Note: Whisper API is very cost-effective for transcription. Most voice memos will cost less than $0.01 to transcribe.

Step 5

Twitter API Setup (Optional)

Set up Twitter API for direct posting (future feature)

Visit https://developer.twitter.com
Apply for a developer account
Create a new app in the developer portal
Generate API keys and access tokens
Copy all required credentials
Note: This is for future direct posting functionality

Optional: Twitter API credentials are not required for current functionality. This is for future direct posting features. You can skip this step and the app will work perfectly for content creation and optimization.

Environment Variables

Add these to your .env.local file

.env.local

# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key

# AI Configuration
ANTHROPIC_API_KEY=your_anthropic_api_key
OPENAI_API_KEY=your_openai_api_key

# Twitter API Configuration (Optional - for future features)
TWITTER_API_KEY=your_twitter_api_key
TWITTER_API_SECRET=your_twitter_api_secret
TWITTER_ACCESS_TOKEN=your_twitter_access_token
TWITTER_ACCESS_TOKEN_SECRET=your_twitter_access_token_secret
TWITTER_BEARER_TOKEN=your_twitter_bearer_token

# App Configuration
NEXTAUTH_SECRET=your_nextauth_secret
NEXTAUTH_URL=http://localhost:3000

Important: Never commit your .env.local file to version control. It contains sensitive API keys that should be kept private.

You're Almost Done!

Edit your .env.local file with your actual API keys
Run npm run dev to start the development server
Visit http://localhost:3000 in your browser
Start creating amazing content with AI!