Skip to content
adityakhadsecodePublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

Repository files navigation

AdLaunch πŸš€

AdLaunch is a bulk Meta (Facebook & Instagram) ad launching and workflow automation platform built for performance marketing teams. It acts as an optimization layer sitting on top of the Meta Marketing API, removing the slow, manual, and repetitive actions of Meta Ads Manager.

AdLaunch enables marketers to stage campaign creative assets, auto-map dimensions to placement groups, enforce strict naming conventions via tokens, and deploy hundreds of campaign variants in seconds using either a 2-Click Quick Launcher or a Spreadsheet-style bulk sheets interface supporting raw clipboard imports.


πŸ—ΊοΈ System Architecture

AdLaunch utilizes Next.js 14/16 (App Router), Prisma ORM (with PostgreSQL/SQLite adapter configurations), and NextAuth.js v5.

graph TD
    subgraph Client ["Browser / Client-Side"]
        UI["React Frontend (shadcn/ui)"]
        Grid["Interactive Sheets Grid"]
        Uploader["File Staging Uploader"]
    end

    subgraph AppServer ["Next.js Server Runtime (Node.js)"]
        AuthFull["Full Auth Setup (auth.ts)"]
        MetaAPI["Meta API Client (lib/meta)"]
        Queue["Background Worker (launcher-worker.ts)"]
        PrismaClient["Prisma Client & Pool (lib/db.ts)"]
    end

    subgraph EdgeRuntime ["Edge Runtime (Next.js Middleware)"]
        AuthEdge["Edge Auth Setup (auth.config.ts)"]
        Middleware["Route Guard (middleware.ts)"]
    end

    subgraph Services ["External Services & Databases"]
        Postgres[("PostgreSQL Database")]
        MetaGraph["Meta Graph API"]
        GDrive["Google Drive API"]
    end

    %% Client Interactions
    UI --> AuthFull
    Grid -->|POST /api/launch/sheet| AppServer
    Uploader -->|POST /api/creatives/upload| AppServer
    
    %% Middleware Guard
    UI -->|Route Request| Middleware
    Middleware -->|Verify Session| AuthEdge

    %% Server Integrations
    AuthFull -->|Query/Write Users| PrismaClient
    Queue -->|Fetch & Update Rows| PrismaClient
    Queue -->|Push Assets & Ads| MetaAPI
    MetaAPI -->|Graph API Requests| MetaGraph
    PrismaClient -->|CRUD Operations| Postgres
    AppServer -.->|Fetch Staging| GDrive
Loading

πŸ“‚ Core Folder Structure

β”œβ”€β”€ prisma/
β”‚   β”œβ”€β”€ schema.prisma       # Prisma 7 Database schema models
β”‚   └── prisma.config.ts    # Prisma 7 Database connection configuration
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/            # API Route handlers (Auth, Sync, Staging, Launchers)
β”‚   β”‚   β”œβ”€β”€ (dashboard)/    # Secured dashboard shell layouts and views
β”‚   β”‚   β”œβ”€β”€ login/          # Login and user registration interface
β”‚   β”‚   └── onboarding/     # Step-by-step configuration wizard
β”‚   β”œβ”€β”€ components/         # Shared frontend interfaces
β”‚   β”‚   └── dashboard/      # Sidebar, topbar, selectors, and trackers
β”‚   β”œβ”€β”€ lib/                # Backend services & utility wrappers
β”‚   β”‚   β”œβ”€β”€ creative/       # Aspect-ratio placement mapper
β”‚   β”‚   β”œβ”€β”€ meta/           # Meta API client wrapper & Auto-Naming resolver
β”‚   β”‚   β”œβ”€β”€ queue/          # Background worker deployment processor
β”‚   β”‚   └── db.ts           # HMR-safe Prisma 7 Client instantiation
β”‚   β”œβ”€β”€ auth.config.ts      # Edge-compatible NextAuth configurations
β”‚   β”œβ”€β”€ auth.ts             # Database-loaded NextAuth full configurations
β”‚   └── middleware.ts       # Secure path routing filters
β”œβ”€β”€ public/
β”‚   └── uploads/            # Local directory staging area for assets
└── .env                    # Environment credentials variables

⚑ Key Workflows

1. Creative Ingestion & Placement Mapping

When assets are dragged-and-dropped into the library or synced from Google Drive, the aspect-ratio classifier detects the dimensions and auto-maps files to standard Meta placement groups.

flowchart TD
    A[Staging Event: Local Upload or GDrive Sync] --> B[Calculate File Dimensions W x H]
    B --> C[Analyze Aspect Ratio]
    C -->|Ratio = 1:1 or 4:5| D[Auto-Map: Feeds & Streams]
    C -->|Ratio = 9:16| E[Auto-Map: Stories & Reels]
    C -->|Ratio = 16:9| F[Auto-Map: In-Stream & Audience]
    D & E & F --> G[Render Placement Grid Matrix]
    G --> H{User Overrides Mapping?}
    H -->|Yes| I[Update detectedPlacementGroup in DB]
    H -->|No| J[Keep Auto-Map defaults]
    I & J --> K[Staged & Ready for Campaign Deployment]
Loading

2. Campaign Launch Queue (Background Executor)

To prevent HTTP thread blockage during large launches, requests return a tracking ID immediately while a background runner handles sequential API uploads.

sequenceDiagram
    participant User as Marketing User
    participant Router as API Router
    participant DB as Postgres DB
    participant Worker as Launcher Worker
    participant Meta as Meta Graph API

    User->>Router: Click "Launch All" (Quick/Sheet parameters)
    Router->>DB: Write LaunchJob (QUEUED) & LaunchRows (DRAFT)
    Router-->>User: Return 200 OK + Job Tracker ID
    
    Note over Worker, Meta: Non-blocking Background Execution
    Router->>Worker: executeLaunchJob(jobId)
    Worker->>DB: Update LaunchJob status to (LAUNCHING)
    Worker->>Meta: Create Campaign (/campaigns)
    Meta-->>Worker: Return Campaign ID
    
    loop for each LaunchRow (Creative Asset)
        Worker->>DB: Update LaunchRow status to (PENDING)
        Worker->>Meta: Create AdSet (/adsets)
        Worker->>Meta: Upload Image/Video & Create AdCreative (/adcreatives)
        Worker->>Meta: Create final Ad under AdSet (/ads)
        Meta-->>Worker: Return Ad IDs
        Worker->>DB: Update Row (SUCCESS, metaAdId) & increment subscription quota
    end
    Worker->>DB: Update LaunchJob status to (COMPLETED)
Loading

πŸ” Edge Runtime Compatibility (Auth Config Splitting)

Next.js Middleware runs inside the Edge Runtime, which does not support Node.js-specific modules (like fs, path, or native binary bindings like standard database drivers or password encryptors). To allow page protection inside middleware.ts without triggering runtime evaluation errors, AdLaunch splits the NextAuth v5 configuration:

graph TD
    subgraph ConfigSplitting ["NextAuth v5 Config Splitting"]
        ConfigEdge["auth.config.ts (Edge Safe) <br>- JWT session config<br>- Login pages routing paths<br>- OAuth Providers (Facebook, Google)"]
        ConfigNode["auth.ts (Node Runtime Only) <br>- Extends auth.config.ts<br>- Database PrismaAdapter<br>- Credentials provider (bcryptjs lookup)<br>- linkAccount token insertion events"]
    end

    Middleware["middleware.ts (Runs on Edge)"] -->|Imports config| ConfigEdge
    APIHandlers["/api/auth/[...nextauth]/route.ts"] -->|Imports handlers| ConfigNode
    DashboardLayout["(dashboard)/layout.tsx"] -->|Calls server auth()| ConfigNode
Loading

πŸš€ Getting Started

1. Prerequisites

  • Node.js (v20+ recommended)
  • NPM (v10+)
  • A running PostgreSQL instance (or you can use an online database provider like Neon/Supabase)

2. Installation

Clone the repository and install the dependencies:

npm install --legacy-peer-deps

3. Environment Setup

Create a .env file in the root directory:

DATABASE_URL="postgresql://username:password@localhost:5432/adlaunch?schema=public"
NEXTAUTH_SECRET="your-32-character-secret-key-goes-here"
NEXTAUTH_URL="http://localhost:3000"

# Meta App Credentials
META_APP_ID="your_facebook_app_id"
META_APP_SECRET="your_facebook_app_secret"

# Google Drive Credentials
GOOGLE_CLIENT_ID="your_google_client_id"
GOOGLE_CLIENT_SECRET="your_google_client_secret"

4. Database Setup & Client Generation

Initialize database schema migrations and compile the Prisma client:

# Push schema structures to target database
npx prisma db push

# Generate client hooks
npx prisma generate

5. Running the Tests

Verify the placement classifier and token-naming engines:

npx tsx src/lib/test-runner.ts

6. Development Server

Boot up the local dev server:

npm run dev

Open http://localhost:3000 inside your browser.


πŸ› οΈ Developer Tools & Mock Mode

To build and test without active Meta Developer accounts or Google OAuth access, AdLaunch runs in Mock Mode automatically if the environment token matches standard placeholders:

  • OAuth simulation: The Onboarding Wizard and login interfaces feature a "Simulate Connection" trigger. This writes mock access credentials to the database, syncing mock Ad Accounts (e.g. act_1010203040) for dashboard population.
  • API simulation: If the connected access token is a placeholder, the MetaApiClient prints the JSON request payloads to the console and returns successful simulated Meta IDs (e.g., mock_meta_id_395829472) immediately. You can test complete bulk sheets launcher uploads with full row success and failure status changes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages