A lightweight Phoenix + LiveView application for managing media campaigns with real-time traffic simulation.
- 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
-
Install dependencies
mix deps.get
-
Create and migrate database
mix ecto.create mix ecto.migrate
-
Seed demo campaigns (optional)
mix run priv/repo/seeds.exs # Or use the Mix task with optional auto-start: mix adbox.seed --start -
Start the Phoenix server
mix phx.server
-
Visit
localhost:4000
- Create a Campaign: Click "New Campaign" and fill in the form
- View Campaign Details: Click "Show" on any campaign
- Start Simulation: Click "Start Simulation" to generate traffic events
- Watch Live Updates: Metrics and events update automatically via Phoenix PubSub
- Stop Simulation: Click "Stop Simulation" to pause event generation
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)- Context Modules:
CampaignsandTrafficprovide business logic - Simulation Runtime:
DynamicSupervisormanages simulator processesRegistryfor process lookupGenServerper campaign for event generation
- Pruner: Background process cleans old events every 60 seconds
- Real-time: Phoenix.PubSub broadcasts events to connected LiveViews
Run in IEx for debugging:
iex -S mix phx.serverManually 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)# 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 --startSee the Phoenix deployment guide
- Official website: https://www.phoenixframework.org/
- Guides: https://hexdocs.pm/phoenix/overview.html
- Docs: https://hexdocs.pm/phoenix
- Forum: https://elixirforum.com/c/phoenix-forum
- Source: https://github.com/phoenixframework/phoenix