feat: Implement core application structure with new dashboard, settings, and help pages, and enhance opportunities management with persistence and filtering.

This commit is contained in:
2026-02-03 20:05:30 +00:00
parent 609b9da020
commit 885bbbf954
21 changed files with 1282 additions and 106 deletions

142
convex/analyses.ts Normal file
View File

@@ -0,0 +1,142 @@
import { mutation, query } from "./_generated/server";
import { v } from "convex/values";
import { getAuthUserId } from "@convex-dev/auth/server";
export const getLatestByProject = query({
args: { projectId: v.id("projects") },
handler: async (ctx, { projectId }) => {
const userId = await getAuthUserId(ctx);
if (!userId) return null;
const project = await ctx.db.get(projectId);
if (!project || project.userId !== userId) return null;
return await ctx.db
.query("analyses")
.withIndex("by_project_createdAt", (q) => q.eq("projectId", projectId))
.order("desc")
.first();
},
});
export const createAnalysis = mutation({
args: {
projectId: v.id("projects"),
dataSourceId: v.id("dataSources"),
analysis: v.object({
productName: v.string(),
tagline: v.string(),
description: v.string(),
category: v.string(),
positioning: v.string(),
features: v.array(v.object({
name: v.string(),
description: v.string(),
benefits: v.array(v.string()),
useCases: v.array(v.string()),
})),
problemsSolved: v.array(v.object({
problem: v.string(),
severity: v.union(v.literal("high"), v.literal("medium"), v.literal("low")),
currentWorkarounds: v.array(v.string()),
emotionalImpact: v.string(),
searchTerms: v.array(v.string()),
})),
personas: v.array(v.object({
name: v.string(),
role: v.string(),
companySize: v.string(),
industry: v.string(),
painPoints: v.array(v.string()),
goals: v.array(v.string()),
techSavvy: v.union(v.literal("low"), v.literal("medium"), v.literal("high")),
objections: v.array(v.string()),
searchBehavior: v.array(v.string()),
})),
keywords: v.array(v.object({
term: v.string(),
type: v.union(
v.literal("product"),
v.literal("problem"),
v.literal("solution"),
v.literal("competitor"),
v.literal("feature"),
v.literal("longtail"),
v.literal("differentiator")
),
searchVolume: v.union(v.literal("high"), v.literal("medium"), v.literal("low")),
intent: v.union(v.literal("informational"), v.literal("navigational"), v.literal("transactional")),
funnel: v.union(v.literal("awareness"), v.literal("consideration"), v.literal("decision")),
emotionalIntensity: v.union(v.literal("frustrated"), v.literal("curious"), v.literal("ready")),
})),
useCases: v.array(v.object({
scenario: v.string(),
trigger: v.string(),
emotionalState: v.string(),
currentWorkflow: v.array(v.string()),
desiredOutcome: v.string(),
alternativeProducts: v.array(v.string()),
whyThisProduct: v.string(),
churnRisk: v.array(v.string()),
})),
competitors: v.array(v.object({
name: v.string(),
differentiator: v.string(),
theirStrength: v.string(),
switchTrigger: v.string(),
theirWeakness: v.string(),
})),
dorkQueries: v.array(v.object({
query: v.string(),
platform: v.union(
v.literal("reddit"),
v.literal("hackernews"),
v.literal("indiehackers"),
v.literal("twitter"),
v.literal("quora"),
v.literal("stackoverflow")
),
intent: v.union(
v.literal("looking-for"),
v.literal("frustrated"),
v.literal("alternative"),
v.literal("comparison"),
v.literal("problem-solving"),
v.literal("tutorial")
),
priority: v.union(v.literal("high"), v.literal("medium"), v.literal("low")),
})),
scrapedAt: v.string(),
analysisVersion: v.string(),
}),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Unauthorized");
const project = await ctx.db.get(args.projectId);
if (!project || project.userId !== userId) {
throw new Error("Project not found or unauthorized");
}
return await ctx.db.insert("analyses", {
projectId: args.projectId,
dataSourceId: args.dataSourceId,
createdAt: Date.now(),
analysisVersion: args.analysis.analysisVersion,
productName: args.analysis.productName,
tagline: args.analysis.tagline,
description: args.analysis.description,
category: args.analysis.category,
positioning: args.analysis.positioning,
features: args.analysis.features,
problemsSolved: args.analysis.problemsSolved,
personas: args.analysis.personas,
keywords: args.analysis.keywords,
useCases: args.analysis.useCases,
competitors: args.analysis.competitors,
dorkQueries: args.analysis.dorkQueries,
scrapedAt: args.analysis.scrapedAt,
});
},
});

View File

@@ -70,6 +70,6 @@ export const addDataSource = mutation({
});
}
return sourceId;
return { sourceId, projectId: projectId! };
},
});

157
convex/opportunities.ts Normal file
View File

@@ -0,0 +1,157 @@
import { mutation, query } from "./_generated/server";
import { v } from "convex/values";
import { getAuthUserId } from "@convex-dev/auth/server";
const opportunityInput = v.object({
url: v.string(),
platform: v.string(),
title: v.string(),
snippet: v.string(),
relevanceScore: v.number(),
intent: v.string(),
suggestedApproach: v.string(),
matchedKeywords: v.array(v.string()),
matchedProblems: v.array(v.string()),
softPitch: v.boolean(),
});
export const listByProject = query({
args: {
projectId: v.id("projects"),
status: v.optional(v.string()),
intent: v.optional(v.string()),
minScore: v.optional(v.number()),
limit: v.optional(v.number()),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) return [];
const project = await ctx.db.get(args.projectId);
if (!project || project.userId !== userId) return [];
const limit = args.limit ?? 50;
let queryBuilder = args.status
? ctx.db
.query("opportunities")
.withIndex("by_project_status", (q) =>
q.eq("projectId", args.projectId).eq("status", args.status!)
)
: ctx.db
.query("opportunities")
.withIndex("by_project_createdAt", (q) =>
q.eq("projectId", args.projectId)
);
if (args.intent) {
queryBuilder = queryBuilder.filter((q) =>
q.eq(q.field("intent"), args.intent)
);
}
if (args.minScore !== undefined) {
queryBuilder = queryBuilder.filter((q) =>
q.gte(q.field("relevanceScore"), args.minScore)
);
}
const results = await queryBuilder.order("desc").collect();
return results.slice(0, limit);
},
});
export const upsertBatch = mutation({
args: {
projectId: v.id("projects"),
analysisId: v.optional(v.id("analyses")),
opportunities: v.array(opportunityInput),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Unauthorized");
const project = await ctx.db.get(args.projectId);
if (!project || project.userId !== userId) {
throw new Error("Project not found or unauthorized");
}
let created = 0;
let updated = 0;
const now = Date.now();
for (const opp of args.opportunities) {
const existing = await ctx.db
.query("opportunities")
.withIndex("by_project_url", (q) =>
q.eq("projectId", args.projectId).eq("url", opp.url)
)
.first();
if (existing) {
await ctx.db.patch(existing._id, {
analysisId: args.analysisId,
platform: opp.platform,
title: opp.title,
snippet: opp.snippet,
relevanceScore: opp.relevanceScore,
intent: opp.intent,
suggestedApproach: opp.suggestedApproach,
matchedKeywords: opp.matchedKeywords,
matchedProblems: opp.matchedProblems,
softPitch: opp.softPitch,
updatedAt: now,
});
updated += 1;
} else {
await ctx.db.insert("opportunities", {
projectId: args.projectId,
analysisId: args.analysisId,
url: opp.url,
platform: opp.platform,
title: opp.title,
snippet: opp.snippet,
relevanceScore: opp.relevanceScore,
intent: opp.intent,
status: "new",
suggestedApproach: opp.suggestedApproach,
matchedKeywords: opp.matchedKeywords,
matchedProblems: opp.matchedProblems,
softPitch: opp.softPitch,
createdAt: now,
updatedAt: now,
});
created += 1;
}
}
return { created, updated };
},
});
export const updateStatus = mutation({
args: {
id: v.id("opportunities"),
status: v.string(),
notes: v.optional(v.string()),
tags: v.optional(v.array(v.string())),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Unauthorized");
const opportunity = await ctx.db.get(args.id);
if (!opportunity) throw new Error("Opportunity not found");
const project = await ctx.db.get(opportunity.projectId);
if (!project || project.userId !== userId) {
throw new Error("Project not found or unauthorized");
}
await ctx.db.patch(args.id, {
status: args.status,
notes: args.notes,
tags: args.tags,
updatedAt: Date.now(),
});
},
});

View File

@@ -32,6 +32,118 @@ const schema = defineSchema({
),
metadata: v.optional(v.any()),
}),
analyses: defineTable({
projectId: v.id("projects"),
dataSourceId: v.id("dataSources"),
createdAt: v.number(),
analysisVersion: v.string(),
productName: v.string(),
tagline: v.string(),
description: v.string(),
category: v.string(),
positioning: v.string(),
features: v.array(v.object({
name: v.string(),
description: v.string(),
benefits: v.array(v.string()),
useCases: v.array(v.string()),
})),
problemsSolved: v.array(v.object({
problem: v.string(),
severity: v.union(v.literal("high"), v.literal("medium"), v.literal("low")),
currentWorkarounds: v.array(v.string()),
emotionalImpact: v.string(),
searchTerms: v.array(v.string()),
})),
personas: v.array(v.object({
name: v.string(),
role: v.string(),
companySize: v.string(),
industry: v.string(),
painPoints: v.array(v.string()),
goals: v.array(v.string()),
techSavvy: v.union(v.literal("low"), v.literal("medium"), v.literal("high")),
objections: v.array(v.string()),
searchBehavior: v.array(v.string()),
})),
keywords: v.array(v.object({
term: v.string(),
type: v.union(
v.literal("product"),
v.literal("problem"),
v.literal("solution"),
v.literal("competitor"),
v.literal("feature"),
v.literal("longtail"),
v.literal("differentiator")
),
searchVolume: v.union(v.literal("high"), v.literal("medium"), v.literal("low")),
intent: v.union(v.literal("informational"), v.literal("navigational"), v.literal("transactional")),
funnel: v.union(v.literal("awareness"), v.literal("consideration"), v.literal("decision")),
emotionalIntensity: v.union(v.literal("frustrated"), v.literal("curious"), v.literal("ready")),
})),
useCases: v.array(v.object({
scenario: v.string(),
trigger: v.string(),
emotionalState: v.string(),
currentWorkflow: v.array(v.string()),
desiredOutcome: v.string(),
alternativeProducts: v.array(v.string()),
whyThisProduct: v.string(),
churnRisk: v.array(v.string()),
})),
competitors: v.array(v.object({
name: v.string(),
differentiator: v.string(),
theirStrength: v.string(),
switchTrigger: v.string(),
theirWeakness: v.string(),
})),
dorkQueries: v.array(v.object({
query: v.string(),
platform: v.union(
v.literal("reddit"),
v.literal("hackernews"),
v.literal("indiehackers"),
v.literal("twitter"),
v.literal("quora"),
v.literal("stackoverflow")
),
intent: v.union(
v.literal("looking-for"),
v.literal("frustrated"),
v.literal("alternative"),
v.literal("comparison"),
v.literal("problem-solving"),
v.literal("tutorial")
),
priority: v.union(v.literal("high"), v.literal("medium"), v.literal("low")),
})),
scrapedAt: v.string(),
})
.index("by_project_createdAt", ["projectId", "createdAt"]),
opportunities: defineTable({
projectId: v.id("projects"),
analysisId: v.optional(v.id("analyses")),
url: v.string(),
platform: v.string(),
title: v.string(),
snippet: v.string(),
relevanceScore: v.number(),
intent: v.string(),
status: v.string(),
suggestedApproach: v.string(),
matchedKeywords: v.array(v.string()),
matchedProblems: v.array(v.string()),
tags: v.optional(v.array(v.string())),
notes: v.optional(v.string()),
softPitch: v.boolean(),
createdAt: v.number(),
updatedAt: v.number(),
})
.index("by_project_status", ["projectId", "status"])
.index("by_project_createdAt", ["projectId", "createdAt"])
.index("by_project_url", ["projectId", "url"]),
});
export default schema;