Skip to content

Repository files navigation

Adbox - Media Campaign MVP

A lightweight Phoenix + LiveView application for managing media campaigns with real-time traffic simulation.

Features

  • Campaign Management: Full CRUD for campaigns (name, daily budget, status)
  • Real-time Simulation: Generate synthetic impressions and clicks per campaign
  • Live Metrics: View impressions, clicks, and CTR updating in real-time
  • Event Streaming: LiveView streams display last 100 events with automatic updates
  • Crash Resilient: Each campaign simulator runs in a supervised process with automatic restart
  • Automatic Cleanup: Background pruner removes events older than 7 days

Setup

  1. Install dependencies

    mix deps.get
  2. Create and migrate database

    mix ecto.create
    mix ecto.migrate
  3. Seed demo campaigns (optional)

    mix run priv/repo/seeds.exs
    # Or use the Mix task with optional auto-start:
    mix adbox.seed --start
  4. Start the Phoenix server

    mix phx.server
  5. Visit localhost:4000

Usage

  1. Create a Campaign: Click "New Campaign" and fill in the form
  2. View Campaign Details: Click "Show" on any campaign
  3. Start Simulation: Click "Start Simulation" to generate traffic events
  4. Watch Live Updates: Metrics and events update automatically via Phoenix PubSub
  5. Stop Simulation: Click "Stop Simulation" to pause event generation

Configuration

Edit config/config.exs to customize:

# Event retention (days)
config :adbox, retention_days: 7

# Simulator settings
config :adbox, Adbox.Sim,
  tick_ms: 1_000,  # Time between event batches (milliseconds)
  batch: 20,       # Events per batch
  ctr: 0.03        # Click-through rate (0.0 to 1.0)

Architecture

  • Context Modules: Campaigns and Traffic provide business logic
  • Simulation Runtime:
    • DynamicSupervisor manages simulator processes
    • Registry for process lookup
    • GenServer per campaign for event generation
  • Pruner: Background process cleans old events every 60 seconds
  • Real-time: Phoenix.PubSub broadcasts events to connected LiveViews

Development

Run in IEx for debugging:

iex -S mix phx.server

Manually start/stop simulators:

# Start simulator for campaign ID 1
Adbox.Sim.start(1)

# Stop simulator
Adbox.Sim.stop(1)

# Check if running
Adbox.Sim.whereis(1)

Database Management

# Drop and recreate database with migrations and seeds
mix ecto.reset

# Drop database only
mix ecto.drop

# Create database only
mix ecto.create

# Run migrations only
mix ecto.migrate

# Rollback last migration
mix ecto.rollback

# Reset to a clean state (useful for development)
mix ecto.drop && mix ecto.create && mix ecto.migrate && mix adbox.seed --start

Production Deployment

See the Phoenix deployment guide

Learn more

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors