Repository navigation
Description
What
Add a Competition column to the All Prompts tab on the prompts
page (/dashboard/prompts?tab=all). Each row shows the prompt's
search competition as a 5-bar meter (equal-height bars) with
colour progression: green → orange → dark orange → red → dark red.
Same UX family as Ahrefs / SEMrush keyword-difficulty indicators.
The data already comes back from DataForSEO on every volume fetch —
we just don't capture it. This issue wires that data end-to-end:
DataForSEO → DB → UI.
Why
Marketers planning content need to know "is this prompt cheap to
win or is everyone fighting for it?" before they invest in content.
Right now the All Prompts tab shows estimated demand but no signal
on how contested the territory is. A glanceable competition meter
solves this in one column.
Data source
DataForSEO's keywords_data/google_ads/search_volume/live endpoint
already returns these fields per keyword that we currently throw away:
competition—"LOW"/"MEDIUM"/"HIGH"(Google Ads label)competition_index—0–100numeric
We're reusing the existing API call — no extra DataForSEO
spending. We aggregate per-prompt (a prompt has multiple keywords)
by volume-weighted average.
Honest framing: This is Google Ads paid-bid competition,
a proxy for "general topic difficulty" — not perfect AEO
difficulty (which is about being cited by AI engines). The
tooltip on the column header should say so. A truer AEO-native
difficulty can replace this column later; this is the practical
first signal.
Where to change
1. Migration
Add a new SQL file at
supabase/migrations/00004_prompt_competition.sql:
-- Capture DataForSEO competition data alongside search volume so the
-- prompts table can show a difficulty meter without an extra API call.
ALTER TABLE "public"."prompt_volumes"
ADD COLUMN IF NOT EXISTS "competition_index" integer,
ADD COLUMN IF NOT EXISTS "competition" text
CHECK ("competition" IS NULL OR "competition" IN ('LOW', 'MEDIUM', 'HIGH'));Follow the same patterns used in
supabase/migrations/00003_api_keys.sql — simple ALTER TABLE /
ADD COLUMN structure, no RLS changes needed because
prompt_volumes inherits from existing brand-scoped policies.
(The maintainer applies this migration via Supabase Studio after
merge — contributors don't need DB access, just commit the SQL.)
2. Supabase types
Update web/src/types/supabase.ts — find the prompt_volumes
table definition and add competition_index: number | null and
competition: string | null to all three of Row / Insert / Update.
3. DataForSEO client (server)
In server/src/lib/dataforseo.js, change the return shape of
getSearchVolumes so each keyword carries the competition fields,
not just the volume. Suggested new shape:
volumes[item.keyword] = {
volume: item.search_volume ?? 0,
competitionIndex: item.competition_index ?? null,
competition: item.competition ?? null, // "LOW" | "MEDIUM" | "HIGH" | null
};This is a breaking change to the function's return shape — every
caller that does volumes[kw] and uses the number directly needs to
read .volume instead. Update:
server/src/routes/volumes.js(the main caller — also where the
per-prompt aggregation should happen)server/src/test-volumes.js(test script also uses the function;
failing to update breaks local DataForSEO testing)
For the per-prompt aggregation, do a volume-weighted average of
competitionIndex across the prompt's keywords before saving:
// pseudo-code: weighted avg of competitionIndex by volume
let sum = 0, weight = 0;
for (const { volume, competitionIndex } of perKeyword) {
if (competitionIndex === null) continue;
sum += competitionIndex * volume;
weight += volume;
}
const avgIdx = weight > 0 ? Math.round(sum / weight) : null;
const label = avgIdx === null ? null
: avgIdx <= 33 ? 'LOW'
: avgIdx <= 66 ? 'MEDIUM'
: 'HIGH';Store both competition_index and competition on the
prompt_volumes row.
4. Web action layer
web/src/lib/actions/volumes.ts — pass the two new fields through
on read.
web/src/types/index.ts — extend the PromptVolume interface
(line ~153) with:
competitionIndex: number | null;
competition: 'LOW' | 'MEDIUM' | 'HIGH' | null;5. The 5-bar meter component
Create web/src/components/ui/competition-bars.tsx. Behaviour:
- Maps
competitionIndex(0–100) to a level (1–5):
level = max(1, min(5, ceil(index / 20))) - Renders 5 equal-height bars; the first
levelbars are
coloured by level (see palette below), the remaining5 - level
bars are muted grey - If
indexisnull, render—instead
Suggested implementation:
import { cn } from "@/lib/utils";
const ACTIVE_BY_LEVEL: Record<number, string> = {
1: "bg-green-500",
2: "bg-orange-300",
3: "bg-orange-500",
4: "bg-red-500",
5: "bg-red-700",
};
export function CompetitionBars({
index,
label,
}: {
index: number | null;
label?: string | null; // optional LOW/MEDIUM/HIGH for tooltip
}) {
if (index === null || index === undefined) {
return <span className="text-muted-foreground text-xs">—</span>;
}
const level = Math.max(1, Math.min(5, Math.ceil(index / 20)));
const active = ACTIVE_BY_LEVEL[level];
return (
<div
className="flex items-center gap-0.5"
title={label ? `${label} (${index}/100)` : `${index}/100`}
aria-label={`Competition ${index} of 100`}
>
{Array.from({ length: 5 }, (_, i) => (
<div
key={i}
className={cn(
"w-1 h-4 rounded-sm",
i < level ? active : "bg-muted",
)}
/>
))}
</div>
);
}Adjust widths / spacing to taste — the spec is: 5 vertical
equal-height bars, fill colour changes with level, unfilled bars
are muted grey.
6. Use it on the prompts page
In web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx,
inside the AllPromptsTab table:
- Add a Competition column header (between Volume and the action
column feels natural) - Render
<CompetitionBars index={vol?.competitionIndex ?? null} label={vol?.competition ?? null} />in each row - The column header tooltip should read: "Based on Google Ads
competition for related keywords (LOW / MEDIUM / HIGH). A proxy
for topic difficulty."
Local testing flow
Because new rows need the new columns populated, after applying the
migration locally you'll want to either:
- Re-fetch volumes from the prompts page (the "Re-fetch volumes"
action triggers a fresh DataForSEO call), or - Manually seed one row in Supabase Studio to verify the meter
renders without waiting for a fresh API call:UPDATE prompt_volumes SET competition_index = 50, competition = 'MEDIUM' WHERE id = '<some-row-id>';
Existing rows that haven't been re-fetched will show — in the
column, which is the correct null-state behaviour.
How to verify
- Migration applies cleanly (no errors, columns appear on
prompt_volumes) - After a fresh volume fetch, new rows have
competition_index
+competitionpopulated - Existing rows that haven't been re-fetched show
—(graceful
null handling) - All Prompts tab shows the new column with the bars rendering
at the right level and colour per row - Hovering the column header shows the tooltip explaining the
proxy nature of the metric - Hovering an individual meter shows the numeric index +
LOW/MEDIUM/HIGH label - Dark mode: meters remain readable (active colours pop, muted
bars subtle) -
server/src/test-volumes.jsstill runs without error against
the new return shape
Out of scope
- Per-keyword competition breakdown (storing
{keyword: competitionIndex}per row) — single aggregate is
enough for now - AEO-native composite difficulty (mention/citation/competitor
density from tracking data) — separate future enhancement, this
meter is the baseline - Adding the same column to other pages — pure prompts-tab scope
- Sorting / filtering by competition — column is read-only for now
- MCP / REST API exposure of the new field — not currently in
list_prompts, can be a follow-up
Contribution guide
See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.
Activity
feat(prompts): add Competition column with a 5-bar difficulty meter (a…