Skip to content

Repository files navigation

Social Media AI Automation

Vercel-ready automation system that:

  • onboards businesses with brand and menu context,
  • generates daily platform-specific social posts,
  • saves progress to Google Sheets,
  • saves generated images to Google Drive,
  • stores tenants and post history in Supabase.

Stack

  • Next.js App Router (TypeScript)
  • Supabase (Postgres)
  • Google APIs (Sheets + Drive)
  • Hostinger cron ping to Vercel endpoint

1. Install and run

npm install
npm run dev

2. Environment setup

  1. Copy .env.example to .env.local.
  2. Add your keys and IDs.
  3. Keep CRON_SECRET private and use the same value in Hostinger cron header.
  4. Set ADMIN_BASIC_AUTH_USER and ADMIN_BASIC_AUTH_PASSWORD before exposing /admin.

AI keys for this setup

  • Content generation uses Mistral:
    • MISTRAL_API_KEY
    • MISTRAL_MODEL (default: mistral-small-latest)
  • Optional text fallback uses Google AI Studio (Gemini):
    • GOOGLE_AI_STUDIO_API_KEY
    • GOOGLE_AI_STUDIO_MODEL (default: gemini-2.0-flash)
  • Rich image generation uses Hugging Face Inference API:
    • HUGGING_FACE_API_KEY
    • HUGGING_FACE_IMAGE_MODEL (default: black-forest-labs/FLUX.1-schnell)

3. Supabase setup

  1. Open Supabase SQL editor.
  2. Run supabase/schema.sql.
  3. Add SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY to .env.local.

4. Google setup

  1. Create a Google Cloud service account.
  2. Enable Google Drive API and Google Sheets API.
  3. Share the target Drive folder and Sheet with the service account email.
  4. Fill these env vars:
    • GOOGLE_SERVICE_ACCOUNT_EMAIL
    • GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY
    • GOOGLE_DRIVE_FOLDER_ID
    • GOOGLE_SHEETS_ID

5. Hostinger daily cron

Configure Hostinger cron to call:

POST https://<your-vercel-domain>/api/cron/daily-run
Header: x-cron-secret: <CRON_SECRET>

Recommended start schedule: once per day in off-peak hours.

API routes

  • POST /api/onboarding saves tenant onboarding data.
  • POST /api/cron/daily-run runs daily automation for active tenants.
  • GET /api/health basic health check.

Security

  • /admin is protected by HTTP Basic Auth.
  • Security headers are applied through middleware.ts.
  • No API keys are sent to the client bundle; all provider calls stay server-side.
  • Use SUPABASE_SERVICE_ROLE_KEY only on the server.
  • Keep all secrets in .env.local or your deployment platform's secret store.

Data flow

  1. User submits onboarding form.
  2. Tenant saved in Supabase.
  3. Daily cron triggers automation.
  4. System generates text + image per selected platform.
  5. Image saved to Drive, progress appended to Sheets.
  6. Post record saved in Supabase.

Freemium and cost behavior

  • If model API env vars are empty, app uses local fallback templates and SVG generation.
  • If platform tokens are empty, posts are saved as manual_required drafts.
  • This minimizes operator cost on free tiers and enables controlled scaling later.

Recommended AI default

  • Preferred text model: Mistral small latest for fast smoke testing and predictable latency.
  • Optional fallback text model: Google AI Studio Gemini Flash class model.
  • Fallback text mode: built-in prompt templates when no model key is configured.
  • Rich image generation: Hugging Face Inference API model set by HUGGING_FACE_IMAGE_MODEL.
  • Zero-cost fallback image mode: built-in SVG rendering when no Hugging Face key is configured.

Next upgrades

  • Replace platform publish stubs in src/lib/platforms.ts with direct API integrations.
  • Add auth and tenant admin dashboard.
  • Add queue worker for high concurrency.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages