Jacksuyu Claude Opus 4.6 commited on
Commit
8e944c6
·
0 Parent(s):

Initial release: Community Demand Board V0.1

Browse files

AI-powered platform where users submit product ideas, get structured
specs (features, tasks, effort estimates), and the community can
upvote, comment, claim tasks, and link implementations.

- Next.js 16 + TypeScript + Tailwind CSS v4
- SQLite + Prisma ORM v7
- OpenAI-compatible LLM for spec generation + embeddings
- Cookie-based anonymous identity (no login)
- CC BY-NC-SA 4.0 license

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

.env.example ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # LLM API (OpenAI-compatible endpoint)
2
+ OPENAI_API_BASE_URL=http://localhost:11434/v1
3
+ OPENAI_API_KEY=sk-placeholder
4
+ OPENAI_MODEL=gpt-4o-mini
5
+ OPENAI_EMBEDDING_MODEL=text-embedding-3-small
6
+
7
+ # Database
8
+ DATABASE_URL="file:./dev.db"
.gitignore ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Environment
2
+ .env
3
+
4
+ # Node.js / Next.js
5
+ node_modules/
6
+ .next/
7
+ out/
8
+ *.tsbuildinfo
9
+ next-env.d.ts
10
+
11
+ # Prisma / Database
12
+ *.db
13
+ *.db-journal
14
+ /generated/prisma
15
+
16
+ # IDE
17
+ .vscode/
18
+ .idea/
19
+ *.swp
20
+ *.swo
21
+
22
+ # OS
23
+ .DS_Store
24
+ Thumbs.db
LICENSE ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
2
+
3
+ Copyright (c) 2026 DolphinWorld
4
+
5
+ This work is licensed under the Creative Commons
6
+ Attribution-NonCommercial-ShareAlike 4.0 International License.
7
+
8
+ You are free to:
9
+
10
+ Share - copy and redistribute the material in any medium or format
11
+ Adapt - remix, transform, and build upon the material
12
+
13
+ Under the following terms:
14
+
15
+ Attribution - You must give appropriate credit, provide a link to the
16
+ license, and indicate if changes were made. You may do so in any
17
+ reasonable manner, but not in any way that suggests the licensor
18
+ endorses you or your use.
19
+
20
+ NonCommercial - You may not use the material for commercial purposes.
21
+
22
+ ShareAlike - If you remix, transform, or build upon the material, you
23
+ must distribute your contributions under the same license as the
24
+ original.
25
+
26
+ No additional restrictions - You may not apply legal terms or
27
+ technological measures that legally restrict others from doing
28
+ anything the license permits.
29
+
30
+ Notices:
31
+
32
+ You do not have to comply with the license for elements of the
33
+ material in the public domain or where your use is permitted by an
34
+ applicable exception or limitation.
35
+
36
+ No warranties are given. The license may not give you all of the
37
+ permissions necessary for your intended use. For example, other
38
+ rights such as publicity, privacy, or moral rights may limit how
39
+ you use the material.
40
+
41
+ For the full license text, see:
42
+ https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
README.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # RequestSolution
2
+
3
+ A community-driven platform where users submit product ideas, AI generates structured specifications (features + tasks), and the community validates, discusses, and builds together.
4
+
5
+ ## Features
6
+
7
+ - **AI-Powered Specs** — Submit a vague idea, get a structured spec with features, tasks, effort estimates, and open questions
8
+ - **Community Validation** — Upvote ideas, comment, and discuss
9
+ - **Developer Collaboration** — Claim tasks, link GitHub PRs/repos, track progress
10
+ - **Similar Ideas** — Embedding-based similarity detection to surface related ideas
11
+ - **No Login Required** — Cookie-based anonymous identity
12
+
13
+ ## Tech Stack
14
+
15
+ - Next.js 16 (App Router) + TypeScript
16
+ - Tailwind CSS v4
17
+ - SQLite + Prisma ORM v7
18
+ - OpenAI-compatible API (works with OpenAI, Ollama, OpenRouter, etc.)
19
+
20
+ ## Getting Started
21
+
22
+ ```bash
23
+ # Install dependencies
24
+ npm install
25
+
26
+ # Set up your environment
27
+ cp .env.example .env
28
+ # Edit .env with your LLM API endpoint and key
29
+
30
+ # Initialize the database
31
+ npx prisma db push
32
+
33
+ # Start the dev server
34
+ npm run dev
35
+ ```
36
+
37
+ Open [http://localhost:3000](http://localhost:3000).
38
+
39
+ ## Environment Variables
40
+
41
+ | Variable | Description | Example |
42
+ |---|---|---|
43
+ | `OPENAI_API_BASE_URL` | OpenAI-compatible API base URL | `https://api.openai.com/v1` |
44
+ | `OPENAI_API_KEY` | API key | `sk-...` |
45
+ | `OPENAI_MODEL` | Model for spec generation | `gpt-4o-mini` |
46
+ | `OPENAI_EMBEDDING_MODEL` | Model for embeddings | `text-embedding-3-small` |
47
+ | `DATABASE_URL` | SQLite database path | `file:./dev.db` |
48
+
49
+ ## License
50
+
51
+ This project is licensed under [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/).
52
+
53
+ You may not use this project for commercial purposes without explicit permission.
app/api/ideas/[id]/comments/route.ts ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+ import { commentSchema } from "@/lib/validators";
5
+
6
+ export async function GET(
7
+ _request: NextRequest,
8
+ { params }: { params: Promise<{ id: string }> }
9
+ ) {
10
+ const { id } = await params;
11
+
12
+ const comments = await prisma.comment.findMany({
13
+ where: { ideaId: id },
14
+ orderBy: { createdAt: "desc" },
15
+ });
16
+
17
+ return NextResponse.json({ data: comments });
18
+ }
19
+
20
+ export async function POST(
21
+ request: NextRequest,
22
+ { params }: { params: Promise<{ id: string }> }
23
+ ) {
24
+ const { id } = await params;
25
+ const anonId = await getAnonId();
26
+
27
+ const idea = await prisma.idea.findUnique({ where: { id } });
28
+ if (!idea) {
29
+ return NextResponse.json(
30
+ { error: { message: "Idea not found", code: "NOT_FOUND" } },
31
+ { status: 404 }
32
+ );
33
+ }
34
+
35
+ const body = await request.json();
36
+ const parsed = commentSchema.safeParse(body);
37
+ if (!parsed.success) {
38
+ return NextResponse.json(
39
+ { error: { message: "Validation failed", code: "VALIDATION_ERROR", details: parsed.error.issues } },
40
+ { status: 400 }
41
+ );
42
+ }
43
+
44
+ // Look up nickname
45
+ const anonUser = await prisma.anonUser.findUnique({
46
+ where: { id: anonId },
47
+ });
48
+
49
+ const [comment] = await prisma.$transaction([
50
+ prisma.comment.create({
51
+ data: {
52
+ ideaId: id,
53
+ body: parsed.data.body,
54
+ createdByAnonId: anonId,
55
+ nickname: anonUser?.nickname || null,
56
+ },
57
+ }),
58
+ prisma.idea.update({
59
+ where: { id },
60
+ data: { commentsCount: { increment: 1 } },
61
+ }),
62
+ ]);
63
+
64
+ return NextResponse.json({ data: comment }, { status: 201 });
65
+ }
app/api/ideas/[id]/route.ts ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+ import { findSimilarIdeas } from "@/lib/embedding";
5
+
6
+ export async function GET(
7
+ _request: NextRequest,
8
+ { params }: { params: Promise<{ id: string }> }
9
+ ) {
10
+ const { id } = await params;
11
+ const anonId = await getAnonId();
12
+
13
+ const idea = await prisma.idea.findUnique({
14
+ where: { id },
15
+ include: {
16
+ tasks: {
17
+ include: { links: true },
18
+ orderBy: { updatedAt: "asc" },
19
+ },
20
+ comments: {
21
+ orderBy: { createdAt: "desc" },
22
+ },
23
+ },
24
+ });
25
+
26
+ if (!idea) {
27
+ return NextResponse.json(
28
+ { error: { message: "Idea not found", code: "NOT_FOUND" } },
29
+ { status: 404 }
30
+ );
31
+ }
32
+
33
+ // Check if current user has voted
34
+ const vote = await prisma.vote.findUnique({
35
+ where: { ideaId_anonId: { ideaId: id, anonId } },
36
+ });
37
+
38
+ // Find similar ideas
39
+ let similarIdeas: { id: string; title: string; similarity: number }[] = [];
40
+ if (idea.embedding) {
41
+ const allIdeas = await prisma.idea.findMany({
42
+ select: { id: true, title: true, embedding: true },
43
+ });
44
+ const targetEmbedding = JSON.parse(idea.embedding) as number[];
45
+ similarIdeas = findSimilarIdeas(targetEmbedding, allIdeas, id);
46
+ }
47
+
48
+ return NextResponse.json({
49
+ data: {
50
+ id: idea.id,
51
+ createdAt: idea.createdAt,
52
+ createdByAnonId: idea.createdByAnonId,
53
+ rawInputText: idea.rawInputText,
54
+ title: idea.title,
55
+ problemStatement: idea.problemStatement,
56
+ tags: JSON.parse(idea.tags || "[]"),
57
+ features: JSON.parse(idea.features || "[]"),
58
+ openQuestions: JSON.parse(idea.openQuestions || "[]"),
59
+ upvotesCount: idea.upvotesCount,
60
+ commentsCount: idea.commentsCount,
61
+ tasks: idea.tasks,
62
+ comments: idea.comments,
63
+ hasVoted: !!vote,
64
+ similarIdeas,
65
+ isOwner: idea.createdByAnonId === anonId,
66
+ },
67
+ });
68
+ }
app/api/ideas/[id]/upvote/route.ts ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+
5
+ export async function POST(
6
+ _request: NextRequest,
7
+ { params }: { params: Promise<{ id: string }> }
8
+ ) {
9
+ const { id } = await params;
10
+ const anonId = await getAnonId();
11
+
12
+ const idea = await prisma.idea.findUnique({ where: { id } });
13
+ if (!idea) {
14
+ return NextResponse.json(
15
+ { error: { message: "Idea not found", code: "NOT_FOUND" } },
16
+ { status: 404 }
17
+ );
18
+ }
19
+
20
+ const existing = await prisma.vote.findUnique({
21
+ where: { ideaId_anonId: { ideaId: id, anonId } },
22
+ });
23
+
24
+ if (existing) {
25
+ return NextResponse.json(
26
+ { error: { message: "Already upvoted", code: "ALREADY_EXISTS" } },
27
+ { status: 409 }
28
+ );
29
+ }
30
+
31
+ await prisma.$transaction([
32
+ prisma.vote.create({
33
+ data: { ideaId: id, anonId },
34
+ }),
35
+ prisma.idea.update({
36
+ where: { id },
37
+ data: { upvotesCount: { increment: 1 } },
38
+ }),
39
+ ]);
40
+
41
+ return NextResponse.json({ data: { voted: true } }, { status: 201 });
42
+ }
43
+
44
+ export async function DELETE(
45
+ _request: NextRequest,
46
+ { params }: { params: Promise<{ id: string }> }
47
+ ) {
48
+ const { id } = await params;
49
+ const anonId = await getAnonId();
50
+
51
+ const existing = await prisma.vote.findUnique({
52
+ where: { ideaId_anonId: { ideaId: id, anonId } },
53
+ });
54
+
55
+ if (!existing) {
56
+ return NextResponse.json(
57
+ { error: { message: "Not voted", code: "NOT_FOUND" } },
58
+ { status: 404 }
59
+ );
60
+ }
61
+
62
+ await prisma.$transaction([
63
+ prisma.vote.delete({
64
+ where: { ideaId_anonId: { ideaId: id, anonId } },
65
+ }),
66
+ prisma.idea.update({
67
+ where: { id },
68
+ data: { upvotesCount: { decrement: 1 } },
69
+ }),
70
+ ]);
71
+
72
+ return NextResponse.json({ data: { voted: false } });
73
+ }
app/api/ideas/route.ts ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+ import { rateLimit } from "@/lib/rate-limit";
5
+ import { submitIdeaSchema, specSchema } from "@/lib/validators";
6
+ import { llm, LLM_MODEL } from "@/lib/llm";
7
+ import { IDEA_TO_SPEC_SYSTEM_PROMPT, buildIdeaPrompt } from "@/lib/prompts";
8
+ import { generateEmbedding } from "@/lib/embedding";
9
+ import { hotScore } from "@/lib/hot-score";
10
+
11
+ export async function GET(request: NextRequest) {
12
+ const searchParams = request.nextUrl.searchParams;
13
+ const sort = searchParams.get("sort") || "hot";
14
+ const search = searchParams.get("search") || "";
15
+ const page = Math.max(1, parseInt(searchParams.get("page") || "1"));
16
+ const limit = Math.min(50, Math.max(1, parseInt(searchParams.get("limit") || "20")));
17
+
18
+ const where = search
19
+ ? {
20
+ OR: [
21
+ { title: { contains: search } },
22
+ { problemStatement: { contains: search } },
23
+ ],
24
+ }
25
+ : {};
26
+
27
+ if (sort === "new") {
28
+ const [ideas, total] = await Promise.all([
29
+ prisma.idea.findMany({
30
+ where,
31
+ orderBy: { createdAt: "desc" },
32
+ skip: (page - 1) * limit,
33
+ take: limit,
34
+ include: {
35
+ tasks: { select: { id: true, status: true } },
36
+ },
37
+ }),
38
+ prisma.idea.count({ where }),
39
+ ]);
40
+
41
+ return NextResponse.json({
42
+ ideas: ideas.map(serializeIdea),
43
+ total,
44
+ page,
45
+ totalPages: Math.ceil(total / limit),
46
+ });
47
+ }
48
+
49
+ // Hot sort: fetch all, compute score, sort in JS
50
+ const ideas = await prisma.idea.findMany({
51
+ where,
52
+ include: {
53
+ tasks: { select: { id: true, status: true } },
54
+ },
55
+ });
56
+
57
+ const scored = ideas
58
+ .map((idea) => ({
59
+ ...idea,
60
+ _hotScore: hotScore(idea.upvotesCount, idea.createdAt),
61
+ }))
62
+ .sort((a, b) => b._hotScore - a._hotScore);
63
+
64
+ const total = scored.length;
65
+ const paginated = scored.slice((page - 1) * limit, page * limit);
66
+
67
+ return NextResponse.json({
68
+ ideas: paginated.map(serializeIdea),
69
+ total,
70
+ page,
71
+ totalPages: Math.ceil(total / limit),
72
+ });
73
+ }
74
+
75
+ export async function POST(request: NextRequest) {
76
+ const anonId = await getAnonId();
77
+
78
+ // Rate limit by anon_id
79
+ const rl = rateLimit(`idea:${anonId}`, 5);
80
+ if (!rl.success) {
81
+ return NextResponse.json(
82
+ { error: { message: "Rate limited. Max 5 ideas per hour.", code: "RATE_LIMITED" } },
83
+ { status: 429 }
84
+ );
85
+ }
86
+
87
+ // Also rate limit by IP
88
+ const ip = request.headers.get("x-forwarded-for") || "unknown";
89
+ const rlIp = rateLimit(`idea:ip:${ip}`, 10);
90
+ if (!rlIp.success) {
91
+ return NextResponse.json(
92
+ { error: { message: "Rate limited by IP.", code: "RATE_LIMITED" } },
93
+ { status: 429 }
94
+ );
95
+ }
96
+
97
+ const body = await request.json();
98
+ const parsed = submitIdeaSchema.safeParse(body);
99
+ if (!parsed.success) {
100
+ return NextResponse.json(
101
+ { error: { message: "Validation failed", code: "VALIDATION_ERROR", details: parsed.error.issues } },
102
+ { status: 400 }
103
+ );
104
+ }
105
+
106
+ const { rawInputText, targetUsers, platform, constraints } = parsed.data;
107
+ const userPrompt = buildIdeaPrompt(rawInputText, targetUsers, platform, constraints);
108
+
109
+ // Generate spec via LLM
110
+ let spec;
111
+ try {
112
+ spec = await generateSpec(userPrompt);
113
+ } catch (error) {
114
+ console.error("LLM spec generation failed:", error);
115
+ return NextResponse.json(
116
+ { error: { message: "Failed to generate specification. Please try again.", code: "LLM_ERROR" } },
117
+ { status: 502 }
118
+ );
119
+ }
120
+
121
+ // Generate embedding (non-blocking failure)
122
+ const embedding = await generateEmbedding(rawInputText);
123
+
124
+ // Create idea + tasks in a transaction
125
+ const idea = await prisma.$transaction(async (tx) => {
126
+ const idea = await tx.idea.create({
127
+ data: {
128
+ createdByAnonId: anonId,
129
+ rawInputText,
130
+ title: spec.title,
131
+ problemStatement: spec.problemStatement,
132
+ tags: JSON.stringify(spec.tags),
133
+ features: JSON.stringify(spec.features),
134
+ openQuestions: JSON.stringify(spec.openQuestions),
135
+ embedding: embedding ? JSON.stringify(embedding) : null,
136
+ },
137
+ });
138
+
139
+ if (spec.tasks.length > 0) {
140
+ await tx.task.createMany({
141
+ data: spec.tasks.map((t) => ({
142
+ ideaId: idea.id,
143
+ title: t.title,
144
+ description: t.description,
145
+ acceptanceCriteria: t.acceptanceCriteria,
146
+ effort: t.effort,
147
+ })),
148
+ });
149
+ }
150
+
151
+ return idea;
152
+ });
153
+
154
+ const created = await prisma.idea.findUnique({
155
+ where: { id: idea.id },
156
+ include: { tasks: true },
157
+ });
158
+
159
+ return NextResponse.json({ data: serializeIdea(created!) }, { status: 201 });
160
+ }
161
+
162
+ async function generateSpec(userPrompt: string, retries = 1) {
163
+ for (let attempt = 0; attempt <= retries; attempt++) {
164
+ const completion = await llm.chat.completions.create({
165
+ model: LLM_MODEL,
166
+ messages: [
167
+ { role: "system", content: IDEA_TO_SPEC_SYSTEM_PROMPT },
168
+ { role: "user", content: userPrompt },
169
+ ],
170
+ temperature: 0.7,
171
+ });
172
+
173
+ const content = completion.choices[0].message.content;
174
+ if (!content) throw new Error("Empty LLM response");
175
+
176
+ try {
177
+ // Strip markdown fences if present
178
+ const cleaned = content.replace(/^```json?\s*\n?/i, "").replace(/\n?```\s*$/i, "");
179
+ const parsed = JSON.parse(cleaned);
180
+ return specSchema.parse(parsed);
181
+ } catch (err) {
182
+ if (attempt === retries) throw err;
183
+ // Retry with a fix prompt
184
+ console.warn("Invalid spec JSON, retrying...", err);
185
+ }
186
+ }
187
+ throw new Error("Failed to generate valid spec");
188
+ }
189
+
190
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
191
+ function serializeIdea(idea: any) {
192
+ return {
193
+ id: idea.id,
194
+ createdAt: idea.createdAt,
195
+ title: idea.title,
196
+ problemStatement: idea.problemStatement,
197
+ tags: JSON.parse(idea.tags || "[]"),
198
+ features: JSON.parse(idea.features || "[]"),
199
+ openQuestions: JSON.parse(idea.openQuestions || "[]"),
200
+ upvotesCount: idea.upvotesCount,
201
+ commentsCount: idea.commentsCount,
202
+ tasks: idea.tasks || [],
203
+ };
204
+ }
app/api/me/nickname/route.ts ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+ import { nicknameSchema } from "@/lib/validators";
5
+
6
+ export async function POST(request: NextRequest) {
7
+ const anonId = await getAnonId();
8
+
9
+ const body = await request.json();
10
+ const parsed = nicknameSchema.safeParse(body);
11
+ if (!parsed.success) {
12
+ return NextResponse.json(
13
+ { error: { message: "Validation failed", code: "VALIDATION_ERROR" } },
14
+ { status: 400 }
15
+ );
16
+ }
17
+
18
+ const user = await prisma.anonUser.upsert({
19
+ where: { id: anonId },
20
+ create: { id: anonId, nickname: parsed.data.nickname },
21
+ update: { nickname: parsed.data.nickname },
22
+ });
23
+
24
+ return NextResponse.json({ data: user });
25
+ }
26
+
27
+ export async function GET() {
28
+ const anonId = await getAnonId();
29
+
30
+ const user = await prisma.anonUser.findUnique({
31
+ where: { id: anonId },
32
+ });
33
+
34
+ return NextResponse.json({
35
+ data: { anonId, nickname: user?.nickname || null },
36
+ });
37
+ }
app/api/task-links/[linkId]/route.ts ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+
5
+ export async function DELETE(
6
+ _request: NextRequest,
7
+ { params }: { params: Promise<{ linkId: string }> }
8
+ ) {
9
+ const { linkId } = await params;
10
+ const anonId = await getAnonId();
11
+
12
+ const link = await prisma.taskLink.findUnique({ where: { id: linkId } });
13
+ if (!link) {
14
+ return NextResponse.json(
15
+ { error: { message: "Link not found", code: "NOT_FOUND" } },
16
+ { status: 404 }
17
+ );
18
+ }
19
+
20
+ if (link.createdByAnonId !== anonId) {
21
+ return NextResponse.json(
22
+ { error: { message: "Not the creator", code: "FORBIDDEN" } },
23
+ { status: 403 }
24
+ );
25
+ }
26
+
27
+ await prisma.taskLink.delete({ where: { id: linkId } });
28
+
29
+ return NextResponse.json({ data: { deleted: true } });
30
+ }
app/api/tasks/[taskId]/claim/route.ts ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+
5
+ export async function POST(
6
+ _request: NextRequest,
7
+ { params }: { params: Promise<{ taskId: string }> }
8
+ ) {
9
+ const { taskId } = await params;
10
+ const anonId = await getAnonId();
11
+
12
+ const task = await prisma.task.findUnique({ where: { id: taskId } });
13
+ if (!task) {
14
+ return NextResponse.json(
15
+ { error: { message: "Task not found", code: "NOT_FOUND" } },
16
+ { status: 404 }
17
+ );
18
+ }
19
+
20
+ if (task.status !== "open") {
21
+ return NextResponse.json(
22
+ { error: { message: "Task is already claimed", code: "ALREADY_EXISTS" } },
23
+ { status: 409 }
24
+ );
25
+ }
26
+
27
+ const updated = await prisma.task.update({
28
+ where: { id: taskId },
29
+ data: {
30
+ claimedByAnonId: anonId,
31
+ claimedAt: new Date(),
32
+ status: "in_progress",
33
+ },
34
+ });
35
+
36
+ return NextResponse.json({ data: updated });
37
+ }
38
+
39
+ export async function DELETE(
40
+ _request: NextRequest,
41
+ { params }: { params: Promise<{ taskId: string }> }
42
+ ) {
43
+ const { taskId } = await params;
44
+ const anonId = await getAnonId();
45
+
46
+ const task = await prisma.task.findUnique({ where: { id: taskId } });
47
+ if (!task) {
48
+ return NextResponse.json(
49
+ { error: { message: "Task not found", code: "NOT_FOUND" } },
50
+ { status: 404 }
51
+ );
52
+ }
53
+
54
+ if (task.claimedByAnonId !== anonId) {
55
+ return NextResponse.json(
56
+ { error: { message: "Not the claimant", code: "FORBIDDEN" } },
57
+ { status: 403 }
58
+ );
59
+ }
60
+
61
+ const updated = await prisma.task.update({
62
+ where: { id: taskId },
63
+ data: {
64
+ claimedByAnonId: null,
65
+ claimedAt: null,
66
+ status: "open",
67
+ },
68
+ });
69
+
70
+ return NextResponse.json({ data: updated });
71
+ }
app/api/tasks/[taskId]/links/route.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+ import { taskLinkSchema } from "@/lib/validators";
5
+
6
+ export async function POST(
7
+ request: NextRequest,
8
+ { params }: { params: Promise<{ taskId: string }> }
9
+ ) {
10
+ const { taskId } = await params;
11
+ const anonId = await getAnonId();
12
+
13
+ const task = await prisma.task.findUnique({ where: { id: taskId } });
14
+ if (!task) {
15
+ return NextResponse.json(
16
+ { error: { message: "Task not found", code: "NOT_FOUND" } },
17
+ { status: 404 }
18
+ );
19
+ }
20
+
21
+ const body = await request.json();
22
+ const parsed = taskLinkSchema.safeParse(body);
23
+ if (!parsed.success) {
24
+ return NextResponse.json(
25
+ { error: { message: "Validation failed", code: "VALIDATION_ERROR" } },
26
+ { status: 400 }
27
+ );
28
+ }
29
+
30
+ const link = await prisma.taskLink.create({
31
+ data: {
32
+ taskId,
33
+ url: parsed.data.url,
34
+ label: parsed.data.label || "",
35
+ createdByAnonId: anonId,
36
+ },
37
+ });
38
+
39
+ return NextResponse.json({ data: link }, { status: 201 });
40
+ }
app/api/tasks/[taskId]/status/route.ts ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { prisma } from "@/lib/prisma";
3
+ import { getAnonId } from "@/lib/anon-id";
4
+ import { taskStatusSchema } from "@/lib/validators";
5
+
6
+ export async function POST(
7
+ request: NextRequest,
8
+ { params }: { params: Promise<{ taskId: string }> }
9
+ ) {
10
+ const { taskId } = await params;
11
+ const anonId = await getAnonId();
12
+
13
+ const task = await prisma.task.findUnique({ where: { id: taskId } });
14
+ if (!task) {
15
+ return NextResponse.json(
16
+ { error: { message: "Task not found", code: "NOT_FOUND" } },
17
+ { status: 404 }
18
+ );
19
+ }
20
+
21
+ const body = await request.json();
22
+ const parsed = taskStatusSchema.safeParse(body);
23
+ if (!parsed.success) {
24
+ return NextResponse.json(
25
+ { error: { message: "Validation failed", code: "VALIDATION_ERROR" } },
26
+ { status: 400 }
27
+ );
28
+ }
29
+
30
+ const { status } = parsed.data;
31
+
32
+ // If setting to open, unclaim the task
33
+ if (status === "open") {
34
+ if (task.claimedByAnonId && task.claimedByAnonId !== anonId) {
35
+ return NextResponse.json(
36
+ { error: { message: "Not the claimant", code: "FORBIDDEN" } },
37
+ { status: 403 }
38
+ );
39
+ }
40
+
41
+ const updated = await prisma.task.update({
42
+ where: { id: taskId },
43
+ data: { status: "open", claimedByAnonId: null, claimedAt: null },
44
+ });
45
+ return NextResponse.json({ data: updated });
46
+ }
47
+
48
+ // For other statuses, only the claimant can change
49
+ if (task.claimedByAnonId !== anonId) {
50
+ return NextResponse.json(
51
+ { error: { message: "Only the claimant can change task status", code: "FORBIDDEN" } },
52
+ { status: 403 }
53
+ );
54
+ }
55
+
56
+ const updated = await prisma.task.update({
57
+ where: { id: taskId },
58
+ data: { status },
59
+ });
60
+
61
+ return NextResponse.json({ data: updated });
62
+ }
app/error.tsx ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ export default function Error({
4
+ error,
5
+ reset,
6
+ }: {
7
+ error: Error & { digest?: string };
8
+ reset: () => void;
9
+ }) {
10
+ return (
11
+ <div className="text-center py-20">
12
+ <h1 className="text-2xl font-bold text-gray-900 mb-4">
13
+ Something went wrong
14
+ </h1>
15
+ <p className="text-gray-500 mb-8">
16
+ {error.message || "An unexpected error occurred."}
17
+ </p>
18
+ <button
19
+ onClick={reset}
20
+ className="px-6 py-2 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700"
21
+ >
22
+ Try again
23
+ </button>
24
+ </div>
25
+ );
26
+ }
app/globals.css ADDED
@@ -0,0 +1 @@
 
 
1
+ @import "tailwindcss";
app/ideas/[id]/error.tsx ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+
5
+ export default function IdeaError({
6
+ error,
7
+ reset,
8
+ }: {
9
+ error: Error & { digest?: string };
10
+ reset: () => void;
11
+ }) {
12
+ return (
13
+ <div className="text-center py-20">
14
+ <h1 className="text-2xl font-bold text-gray-900 mb-4">
15
+ Failed to load idea
16
+ </h1>
17
+ <p className="text-gray-500 mb-8">
18
+ {error.message || "Could not load this idea."}
19
+ </p>
20
+ <div className="flex gap-4 justify-center">
21
+ <button
22
+ onClick={reset}
23
+ className="px-6 py-2 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700"
24
+ >
25
+ Try again
26
+ </button>
27
+ <Link
28
+ href="/"
29
+ className="px-6 py-2 bg-gray-100 text-gray-700 rounded-lg font-medium hover:bg-gray-200"
30
+ >
31
+ Back to home
32
+ </Link>
33
+ </div>
34
+ </div>
35
+ );
36
+ }
app/ideas/[id]/page.tsx ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { useEffect, useState, use } from "react";
4
+ import { UpvoteButton } from "@/components/UpvoteButton";
5
+ import { TaskList } from "@/components/TaskList";
6
+ import { CommentSection } from "@/components/CommentSection";
7
+ import Link from "next/link";
8
+
9
+ interface Feature {
10
+ title: string;
11
+ description: string;
12
+ }
13
+
14
+ interface TaskLink {
15
+ id: string;
16
+ url: string;
17
+ label: string;
18
+ createdByAnonId: string;
19
+ }
20
+
21
+ interface Task {
22
+ id: string;
23
+ title: string;
24
+ description: string;
25
+ acceptanceCriteria: string;
26
+ effort: string;
27
+ status: string;
28
+ claimedByAnonId: string | null;
29
+ links: TaskLink[];
30
+ }
31
+
32
+ interface Comment {
33
+ id: string;
34
+ body: string;
35
+ nickname: string | null;
36
+ createdByAnonId: string;
37
+ createdAt: string;
38
+ }
39
+
40
+ interface SimilarIdea {
41
+ id: string;
42
+ title: string;
43
+ similarity: number;
44
+ }
45
+
46
+ interface IdeaDetail {
47
+ id: string;
48
+ createdAt: string;
49
+ title: string;
50
+ problemStatement: string;
51
+ tags: string[];
52
+ features: Feature[];
53
+ openQuestions: string[];
54
+ upvotesCount: number;
55
+ commentsCount: number;
56
+ tasks: Task[];
57
+ comments: Comment[];
58
+ hasVoted: boolean;
59
+ similarIdeas: SimilarIdea[];
60
+ isOwner: boolean;
61
+ }
62
+
63
+ export default function IdeaDetailPage({
64
+ params,
65
+ }: {
66
+ params: Promise<{ id: string }>;
67
+ }) {
68
+ const { id } = use(params);
69
+ const [idea, setIdea] = useState<IdeaDetail | null>(null);
70
+ const [loading, setLoading] = useState(true);
71
+ const [error, setError] = useState<string | null>(null);
72
+
73
+ useEffect(() => {
74
+ fetch(`/api/ideas/${id}`)
75
+ .then((r) => {
76
+ if (!r.ok) throw new Error("Not found");
77
+ return r.json();
78
+ })
79
+ .then((d) => setIdea(d.data))
80
+ .catch((e) => setError(e.message))
81
+ .finally(() => setLoading(false));
82
+ }, [id]);
83
+
84
+ if (loading) {
85
+ return (
86
+ <div className="animate-pulse space-y-4">
87
+ <div className="h-8 bg-gray-200 rounded w-2/3" />
88
+ <div className="h-4 bg-gray-100 rounded w-full" />
89
+ <div className="h-4 bg-gray-100 rounded w-3/4" />
90
+ <div className="h-32 bg-gray-100 rounded" />
91
+ </div>
92
+ );
93
+ }
94
+
95
+ if (error || !idea) {
96
+ return (
97
+ <div className="text-center py-16">
98
+ <p className="text-gray-500 text-lg mb-4">
99
+ {error || "Idea not found"}
100
+ </p>
101
+ <Link href="/" className="text-indigo-600 hover:underline">
102
+ Back to home
103
+ </Link>
104
+ </div>
105
+ );
106
+ }
107
+
108
+ return (
109
+ <div className="space-y-8">
110
+ {/* Header */}
111
+ <div>
112
+ <Link
113
+ href="/"
114
+ className="text-sm text-gray-500 hover:text-gray-700 mb-4 inline-block"
115
+ >
116
+ &larr; Back to ideas
117
+ </Link>
118
+
119
+ <div className="flex items-start gap-4">
120
+ <UpvoteButton
121
+ ideaId={idea.id}
122
+ initialCount={idea.upvotesCount}
123
+ initialHasVoted={idea.hasVoted}
124
+ />
125
+ <div>
126
+ <h1 className="text-2xl font-bold text-gray-900">{idea.title}</h1>
127
+ <p className="text-gray-600 mt-2">{idea.problemStatement}</p>
128
+ </div>
129
+ </div>
130
+
131
+ <div className="flex flex-wrap gap-2 mt-4">
132
+ {idea.tags.map((tag) => (
133
+ <span
134
+ key={tag}
135
+ className="px-2.5 py-1 bg-indigo-50 text-indigo-700 rounded-full text-xs font-medium"
136
+ >
137
+ {tag}
138
+ </span>
139
+ ))}
140
+ </div>
141
+ </div>
142
+
143
+ {/* Features */}
144
+ <section>
145
+ <h2 className="text-lg font-semibold text-gray-900 mb-3">
146
+ Core Features
147
+ </h2>
148
+ <div className="grid gap-3">
149
+ {idea.features.map((feature, i) => (
150
+ <div
151
+ key={i}
152
+ className="bg-white border border-gray-200 rounded-lg p-4"
153
+ >
154
+ <h3 className="font-medium text-gray-900">{feature.title}</h3>
155
+ <p className="text-sm text-gray-500 mt-1">
156
+ {feature.description}
157
+ </p>
158
+ </div>
159
+ ))}
160
+ </div>
161
+ </section>
162
+
163
+ {/* Tasks */}
164
+ <section>
165
+ <h2 className="text-lg font-semibold text-gray-900 mb-3">
166
+ Tasks ({idea.tasks.filter((t) => t.status === "done").length}/
167
+ {idea.tasks.length} done)
168
+ </h2>
169
+ <TaskList tasks={idea.tasks} onUpdate={(tasks) => setIdea({ ...idea, tasks })} />
170
+ </section>
171
+
172
+ {/* Open Questions */}
173
+ {idea.openQuestions.length > 0 && (
174
+ <section>
175
+ <h2 className="text-lg font-semibold text-gray-900 mb-3">
176
+ Open Questions
177
+ </h2>
178
+ <ul className="space-y-2">
179
+ {idea.openQuestions.map((q, i) => (
180
+ <li
181
+ key={i}
182
+ className="flex items-start gap-2 text-sm text-gray-700"
183
+ >
184
+ <span className="text-amber-500 mt-0.5">?</span>
185
+ {q}
186
+ </li>
187
+ ))}
188
+ </ul>
189
+ </section>
190
+ )}
191
+
192
+ {/* Similar Ideas */}
193
+ {idea.similarIdeas.length > 0 && (
194
+ <section>
195
+ <h2 className="text-lg font-semibold text-gray-900 mb-3">
196
+ Similar Ideas
197
+ </h2>
198
+ <div className="space-y-2">
199
+ {idea.similarIdeas.map((sim) => (
200
+ <Link
201
+ key={sim.id}
202
+ href={`/ideas/${sim.id}`}
203
+ className="block bg-white border border-gray-200 rounded-lg p-3 hover:border-indigo-300 transition-colors"
204
+ >
205
+ <div className="flex items-center justify-between">
206
+ <span className="text-sm font-medium text-gray-900">
207
+ {sim.title}
208
+ </span>
209
+ <span className="text-xs text-gray-400">
210
+ {Math.round(sim.similarity * 100)}% similar
211
+ </span>
212
+ </div>
213
+ </Link>
214
+ ))}
215
+ </div>
216
+ </section>
217
+ )}
218
+
219
+ {/* Comments */}
220
+ <section>
221
+ <h2 className="text-lg font-semibold text-gray-900 mb-3">
222
+ Comments ({idea.commentsCount})
223
+ </h2>
224
+ <CommentSection ideaId={idea.id} initialComments={idea.comments} />
225
+ </section>
226
+ </div>
227
+ );
228
+ }
app/layout.tsx ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Metadata } from "next";
2
+ import "./globals.css";
3
+ import { Navbar } from "@/components/Navbar";
4
+
5
+ export const metadata: Metadata = {
6
+ title: "Community Demand Board",
7
+ description:
8
+ "Submit product ideas, get structured specs, and build together.",
9
+ };
10
+
11
+ export default function RootLayout({
12
+ children,
13
+ }: {
14
+ children: React.ReactNode;
15
+ }) {
16
+ return (
17
+ <html lang="en">
18
+ <body className="bg-gray-50 text-gray-900 min-h-screen antialiased">
19
+ <Navbar />
20
+ <main className="max-w-5xl mx-auto px-4 py-8">{children}</main>
21
+ </body>
22
+ </html>
23
+ );
24
+ }
app/not-found.tsx ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Link from "next/link";
2
+
3
+ export default function NotFound() {
4
+ return (
5
+ <div className="text-center py-20">
6
+ <h1 className="text-6xl font-bold text-gray-200 mb-4">404</h1>
7
+ <p className="text-lg text-gray-500 mb-8">Page not found</p>
8
+ <Link
9
+ href="/"
10
+ className="text-indigo-600 hover:underline font-medium"
11
+ >
12
+ Back to home
13
+ </Link>
14
+ </div>
15
+ );
16
+ }
app/page.tsx ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { Suspense, useEffect, useState, useCallback } from "react";
4
+ import { useSearchParams, useRouter } from "next/navigation";
5
+ import { IdeaCard } from "@/components/IdeaCard";
6
+
7
+ interface Idea {
8
+ id: string;
9
+ title: string;
10
+ problemStatement: string;
11
+ tags: string[];
12
+ upvotesCount: number;
13
+ commentsCount: number;
14
+ createdAt: string;
15
+ tasks: { id: string; status: string }[];
16
+ }
17
+
18
+ function HomeContent() {
19
+ const searchParams = useSearchParams();
20
+ const router = useRouter();
21
+ const sort = searchParams.get("sort") || "hot";
22
+ const search = searchParams.get("search") || "";
23
+
24
+ const [ideas, setIdeas] = useState<Idea[]>([]);
25
+ const [loading, setLoading] = useState(true);
26
+ const [total, setTotal] = useState(0);
27
+ const [page, setPage] = useState(1);
28
+ const [totalPages, setTotalPages] = useState(1);
29
+ const [searchInput, setSearchInput] = useState(search);
30
+
31
+ const fetchIdeas = useCallback(
32
+ async (p: number = 1) => {
33
+ setLoading(true);
34
+ const params = new URLSearchParams({
35
+ sort,
36
+ page: String(p),
37
+ limit: "20",
38
+ });
39
+ if (search) params.set("search", search);
40
+ const res = await fetch(`/api/ideas?${params}`);
41
+ const data = await res.json();
42
+ setIdeas(data.ideas);
43
+ setTotal(data.total);
44
+ setPage(data.page);
45
+ setTotalPages(data.totalPages);
46
+ setLoading(false);
47
+ },
48
+ [sort, search]
49
+ );
50
+
51
+ useEffect(() => {
52
+ fetchIdeas();
53
+ }, [fetchIdeas]);
54
+
55
+ function setSort(newSort: string) {
56
+ const params = new URLSearchParams();
57
+ params.set("sort", newSort);
58
+ if (search) params.set("search", search);
59
+ router.push(`/?${params}`);
60
+ }
61
+
62
+ function handleSearch(e: React.FormEvent) {
63
+ e.preventDefault();
64
+ const params = new URLSearchParams();
65
+ params.set("sort", sort);
66
+ if (searchInput.trim()) params.set("search", searchInput.trim());
67
+ router.push(`/?${params}`);
68
+ }
69
+
70
+ return (
71
+ <div>
72
+ <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6">
73
+ <div>
74
+ <h1 className="text-2xl font-bold text-gray-900">Ideas</h1>
75
+ <p className="text-sm text-gray-500 mt-1">
76
+ {total} {total === 1 ? "idea" : "ideas"} submitted
77
+ </p>
78
+ </div>
79
+
80
+ <form onSubmit={handleSearch} className="flex gap-2">
81
+ <input
82
+ type="text"
83
+ value={searchInput}
84
+ onChange={(e) => setSearchInput(e.target.value)}
85
+ placeholder="Search ideas..."
86
+ className="px-3 py-2 border border-gray-300 rounded-lg text-sm w-48 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
87
+ />
88
+ <button
89
+ type="submit"
90
+ className="px-3 py-2 bg-gray-100 rounded-lg text-sm hover:bg-gray-200"
91
+ >
92
+ Search
93
+ </button>
94
+ </form>
95
+ </div>
96
+
97
+ <div className="flex gap-1 mb-6">
98
+ {["hot", "new"].map((s) => (
99
+ <button
100
+ key={s}
101
+ onClick={() => setSort(s)}
102
+ className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
103
+ sort === s
104
+ ? "bg-indigo-600 text-white"
105
+ : "bg-white text-gray-600 border border-gray-200 hover:bg-gray-50"
106
+ }`}
107
+ >
108
+ {s.charAt(0).toUpperCase() + s.slice(1)}
109
+ </button>
110
+ ))}
111
+ </div>
112
+
113
+ {loading ? (
114
+ <div className="space-y-4">
115
+ {[1, 2, 3].map((i) => (
116
+ <div
117
+ key={i}
118
+ className="bg-white rounded-xl border border-gray-200 p-5 animate-pulse"
119
+ >
120
+ <div className="h-5 bg-gray-200 rounded w-2/3 mb-3" />
121
+ <div className="h-4 bg-gray-100 rounded w-full mb-2" />
122
+ <div className="h-4 bg-gray-100 rounded w-1/2" />
123
+ </div>
124
+ ))}
125
+ </div>
126
+ ) : ideas.length === 0 ? (
127
+ <div className="text-center py-16">
128
+ <p className="text-gray-500 text-lg mb-4">No ideas yet</p>
129
+ <a
130
+ href="/submit"
131
+ className="text-indigo-600 hover:underline font-medium"
132
+ >
133
+ Be the first to submit an idea
134
+ </a>
135
+ </div>
136
+ ) : (
137
+ <div className="space-y-3">
138
+ {ideas.map((idea) => (
139
+ <IdeaCard key={idea.id} idea={idea} />
140
+ ))}
141
+ </div>
142
+ )}
143
+
144
+ {totalPages > 1 && (
145
+ <div className="flex justify-center gap-2 mt-8">
146
+ <button
147
+ onClick={() => fetchIdeas(page - 1)}
148
+ disabled={page <= 1}
149
+ className="px-4 py-2 rounded-lg text-sm bg-white border border-gray-200 disabled:opacity-50"
150
+ >
151
+ Previous
152
+ </button>
153
+ <span className="px-4 py-2 text-sm text-gray-500">
154
+ Page {page} of {totalPages}
155
+ </span>
156
+ <button
157
+ onClick={() => fetchIdeas(page + 1)}
158
+ disabled={page >= totalPages}
159
+ className="px-4 py-2 rounded-lg text-sm bg-white border border-gray-200 disabled:opacity-50"
160
+ >
161
+ Next
162
+ </button>
163
+ </div>
164
+ )}
165
+ </div>
166
+ );
167
+ }
168
+
169
+ function LoadingSkeleton() {
170
+ return (
171
+ <div className="space-y-4">
172
+ <div className="h-8 bg-gray-200 rounded w-32 mb-6" />
173
+ {[1, 2, 3].map((i) => (
174
+ <div
175
+ key={i}
176
+ className="bg-white rounded-xl border border-gray-200 p-5 animate-pulse"
177
+ >
178
+ <div className="h-5 bg-gray-200 rounded w-2/3 mb-3" />
179
+ <div className="h-4 bg-gray-100 rounded w-full mb-2" />
180
+ <div className="h-4 bg-gray-100 rounded w-1/2" />
181
+ </div>
182
+ ))}
183
+ </div>
184
+ );
185
+ }
186
+
187
+ export default function HomePage() {
188
+ return (
189
+ <Suspense fallback={<LoadingSkeleton />}>
190
+ <HomeContent />
191
+ </Suspense>
192
+ );
193
+ }
app/submit/error.tsx ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+
5
+ export default function SubmitError({
6
+ error,
7
+ reset,
8
+ }: {
9
+ error: Error & { digest?: string };
10
+ reset: () => void;
11
+ }) {
12
+ return (
13
+ <div className="text-center py-20">
14
+ <h1 className="text-2xl font-bold text-gray-900 mb-4">
15
+ Submission error
16
+ </h1>
17
+ <p className="text-gray-500 mb-8">
18
+ {error.message || "Something went wrong while submitting your idea."}
19
+ </p>
20
+ <div className="flex gap-4 justify-center">
21
+ <button
22
+ onClick={reset}
23
+ className="px-6 py-2 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700"
24
+ >
25
+ Try again
26
+ </button>
27
+ <Link
28
+ href="/"
29
+ className="px-6 py-2 bg-gray-100 text-gray-700 rounded-lg font-medium hover:bg-gray-200"
30
+ >
31
+ Back to home
32
+ </Link>
33
+ </div>
34
+ </div>
35
+ );
36
+ }
app/submit/page.tsx ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+ import { useRouter } from "next/navigation";
5
+
6
+ export default function SubmitPage() {
7
+ const router = useRouter();
8
+ const [rawInputText, setRawInputText] = useState("");
9
+ const [targetUsers, setTargetUsers] = useState("");
10
+ const [platform, setPlatform] = useState("");
11
+ const [constraints, setConstraints] = useState("");
12
+ const [loading, setLoading] = useState(false);
13
+ const [error, setError] = useState<string | null>(null);
14
+
15
+ async function handleSubmit(e: React.FormEvent) {
16
+ e.preventDefault();
17
+ setError(null);
18
+ setLoading(true);
19
+
20
+ try {
21
+ const res = await fetch("/api/ideas", {
22
+ method: "POST",
23
+ headers: { "Content-Type": "application/json" },
24
+ body: JSON.stringify({
25
+ rawInputText,
26
+ targetUsers: targetUsers || undefined,
27
+ platform: platform || undefined,
28
+ constraints: constraints || undefined,
29
+ }),
30
+ });
31
+
32
+ if (!res.ok) {
33
+ const data = await res.json();
34
+ setError(data.error?.message || "Something went wrong");
35
+ setLoading(false);
36
+ return;
37
+ }
38
+
39
+ const data = await res.json();
40
+ router.push(`/ideas/${data.data.id}`);
41
+ } catch {
42
+ setError("Network error. Please try again.");
43
+ setLoading(false);
44
+ }
45
+ }
46
+
47
+ return (
48
+ <div className="max-w-2xl mx-auto">
49
+ <h1 className="text-2xl font-bold text-gray-900 mb-2">
50
+ Submit an Idea
51
+ </h1>
52
+ <p className="text-gray-500 mb-8">
53
+ Describe your product idea and our AI will turn it into a structured
54
+ specification with features and tasks.
55
+ </p>
56
+
57
+ <form onSubmit={handleSubmit} className="space-y-6">
58
+ <div>
59
+ <label
60
+ htmlFor="idea"
61
+ className="block text-sm font-medium text-gray-700 mb-2"
62
+ >
63
+ Your Idea *
64
+ </label>
65
+ <textarea
66
+ id="idea"
67
+ value={rawInputText}
68
+ onChange={(e) => setRawInputText(e.target.value)}
69
+ placeholder="Describe your product idea in detail. What problem does it solve? Who is it for? What should it do?"
70
+ rows={6}
71
+ required
72
+ minLength={20}
73
+ maxLength={5000}
74
+ className="w-full px-4 py-3 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent resize-y"
75
+ />
76
+ <p className="text-xs text-gray-400 mt-1">
77
+ {rawInputText.length}/5000 characters (min 20)
78
+ </p>
79
+ </div>
80
+
81
+ <details className="group">
82
+ <summary className="cursor-pointer text-sm font-medium text-gray-600 hover:text-gray-800">
83
+ Optional details
84
+ </summary>
85
+ <div className="mt-4 space-y-4">
86
+ <div>
87
+ <label
88
+ htmlFor="target"
89
+ className="block text-sm font-medium text-gray-700 mb-1"
90
+ >
91
+ Target Users
92
+ </label>
93
+ <input
94
+ id="target"
95
+ type="text"
96
+ value={targetUsers}
97
+ onChange={(e) => setTargetUsers(e.target.value)}
98
+ placeholder="e.g., small business owners, students, developers"
99
+ className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500"
100
+ />
101
+ </div>
102
+
103
+ <div>
104
+ <label
105
+ htmlFor="platform"
106
+ className="block text-sm font-medium text-gray-700 mb-1"
107
+ >
108
+ Platform
109
+ </label>
110
+ <select
111
+ id="platform"
112
+ value={platform}
113
+ onChange={(e) => setPlatform(e.target.value)}
114
+ className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500"
115
+ >
116
+ <option value="">Any</option>
117
+ <option value="Web">Web</option>
118
+ <option value="Mobile">Mobile</option>
119
+ <option value="Desktop">Desktop</option>
120
+ <option value="CLI">CLI</option>
121
+ </select>
122
+ </div>
123
+
124
+ <div>
125
+ <label
126
+ htmlFor="constraints"
127
+ className="block text-sm font-medium text-gray-700 mb-1"
128
+ >
129
+ Constraints
130
+ </label>
131
+ <input
132
+ id="constraints"
133
+ type="text"
134
+ value={constraints}
135
+ onChange={(e) => setConstraints(e.target.value)}
136
+ placeholder="e.g., no login required, privacy-first, low budget"
137
+ className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500"
138
+ />
139
+ </div>
140
+ </div>
141
+ </details>
142
+
143
+ {error && (
144
+ <div className="p-4 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700">
145
+ {error}
146
+ </div>
147
+ )}
148
+
149
+ <button
150
+ type="submit"
151
+ disabled={loading || rawInputText.length < 20}
152
+ className="w-full py-3 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2"
153
+ >
154
+ {loading ? (
155
+ <>
156
+ <svg
157
+ className="animate-spin h-4 w-4"
158
+ viewBox="0 0 24 24"
159
+ fill="none"
160
+ >
161
+ <circle
162
+ className="opacity-25"
163
+ cx="12"
164
+ cy="12"
165
+ r="10"
166
+ stroke="currentColor"
167
+ strokeWidth="4"
168
+ />
169
+ <path
170
+ className="opacity-75"
171
+ fill="currentColor"
172
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
173
+ />
174
+ </svg>
175
+ Generating Requirements...
176
+ </>
177
+ ) : (
178
+ "Generate Requirements"
179
+ )}
180
+ </button>
181
+ </form>
182
+ </div>
183
+ );
184
+ }
components/CommentSection.tsx ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+
5
+ interface Comment {
6
+ id: string;
7
+ body: string;
8
+ nickname: string | null;
9
+ createdByAnonId: string;
10
+ createdAt: string;
11
+ }
12
+
13
+ function timeAgo(date: string): string {
14
+ const seconds = Math.floor(
15
+ (Date.now() - new Date(date).getTime()) / 1000
16
+ );
17
+ if (seconds < 60) return "just now";
18
+ const minutes = Math.floor(seconds / 60);
19
+ if (minutes < 60) return `${minutes}m ago`;
20
+ const hours = Math.floor(minutes / 60);
21
+ if (hours < 24) return `${hours}h ago`;
22
+ const days = Math.floor(hours / 24);
23
+ return `${days}d ago`;
24
+ }
25
+
26
+ export function CommentSection({
27
+ ideaId,
28
+ initialComments,
29
+ }: {
30
+ ideaId: string;
31
+ initialComments: Comment[];
32
+ }) {
33
+ const [comments, setComments] = useState(initialComments);
34
+ const [body, setBody] = useState("");
35
+ const [submitting, setSubmitting] = useState(false);
36
+
37
+ async function handleSubmit(e: React.FormEvent) {
38
+ e.preventDefault();
39
+ if (!body.trim() || submitting) return;
40
+
41
+ setSubmitting(true);
42
+
43
+ try {
44
+ const res = await fetch(`/api/ideas/${ideaId}/comments`, {
45
+ method: "POST",
46
+ headers: { "Content-Type": "application/json" },
47
+ body: JSON.stringify({ body: body.trim() }),
48
+ });
49
+
50
+ if (res.ok) {
51
+ const d = await res.json();
52
+ setComments([d.data, ...comments]);
53
+ setBody("");
54
+ }
55
+ } finally {
56
+ setSubmitting(false);
57
+ }
58
+ }
59
+
60
+ return (
61
+ <div className="space-y-4">
62
+ <form onSubmit={handleSubmit} className="flex gap-2">
63
+ <input
64
+ type="text"
65
+ value={body}
66
+ onChange={(e) => setBody(e.target.value)}
67
+ placeholder="Add a comment..."
68
+ maxLength={2000}
69
+ className="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500"
70
+ />
71
+ <button
72
+ type="submit"
73
+ disabled={!body.trim() || submitting}
74
+ className="px-4 py-2 bg-indigo-600 text-white rounded-lg text-sm font-medium hover:bg-indigo-700 disabled:opacity-50"
75
+ >
76
+ Post
77
+ </button>
78
+ </form>
79
+
80
+ {comments.length === 0 ? (
81
+ <p className="text-sm text-gray-400 py-4">
82
+ No comments yet. Be the first!
83
+ </p>
84
+ ) : (
85
+ <div className="space-y-3">
86
+ {comments.map((comment) => (
87
+ <div
88
+ key={comment.id}
89
+ className="bg-white border border-gray-200 rounded-lg p-3"
90
+ >
91
+ <div className="flex items-center gap-2 mb-1">
92
+ <span className="text-xs font-medium text-gray-700">
93
+ {comment.nickname ||
94
+ `anon-${comment.createdByAnonId.slice(0, 6)}`}
95
+ </span>
96
+ <span className="text-xs text-gray-400">
97
+ {timeAgo(comment.createdAt)}
98
+ </span>
99
+ </div>
100
+ <p className="text-sm text-gray-700">{comment.body}</p>
101
+ </div>
102
+ ))}
103
+ </div>
104
+ )}
105
+ </div>
106
+ );
107
+ }
components/IdeaCard.tsx ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import Link from "next/link";
2
+ import { UpvoteButton } from "./UpvoteButton";
3
+
4
+ interface IdeaCardProps {
5
+ idea: {
6
+ id: string;
7
+ title: string;
8
+ problemStatement: string;
9
+ tags: string[];
10
+ upvotesCount: number;
11
+ commentsCount: number;
12
+ createdAt: string;
13
+ tasks?: { id: string; status: string }[];
14
+ };
15
+ hasVoted?: boolean;
16
+ }
17
+
18
+ function timeAgo(date: string): string {
19
+ const seconds = Math.floor(
20
+ (Date.now() - new Date(date).getTime()) / 1000
21
+ );
22
+ if (seconds < 60) return "just now";
23
+ const minutes = Math.floor(seconds / 60);
24
+ if (minutes < 60) return `${minutes}m ago`;
25
+ const hours = Math.floor(minutes / 60);
26
+ if (hours < 24) return `${hours}h ago`;
27
+ const days = Math.floor(hours / 24);
28
+ return `${days}d ago`;
29
+ }
30
+
31
+ export function IdeaCard({ idea, hasVoted = false }: IdeaCardProps) {
32
+ const tasksDone = idea.tasks?.filter((t) => t.status === "done").length || 0;
33
+ const tasksTotal = idea.tasks?.length || 0;
34
+
35
+ return (
36
+ <Link href={`/ideas/${idea.id}`} className="block">
37
+ <div className="bg-white rounded-xl border border-gray-200 p-5 hover:border-indigo-300 hover:shadow-sm transition-all">
38
+ <div className="flex gap-4">
39
+ <div className="flex-shrink-0 pt-1">
40
+ <UpvoteButton
41
+ ideaId={idea.id}
42
+ initialCount={idea.upvotesCount}
43
+ initialHasVoted={hasVoted}
44
+ />
45
+ </div>
46
+
47
+ <div className="flex-1 min-w-0">
48
+ <h3 className="font-semibold text-gray-900 mb-1">{idea.title}</h3>
49
+ <p className="text-sm text-gray-500 line-clamp-2 mb-3">
50
+ {idea.problemStatement}
51
+ </p>
52
+
53
+ <div className="flex flex-wrap items-center gap-2">
54
+ {idea.tags.slice(0, 5).map((tag) => (
55
+ <span
56
+ key={tag}
57
+ className="px-2 py-0.5 bg-gray-100 text-gray-600 rounded-full text-xs"
58
+ >
59
+ {tag}
60
+ </span>
61
+ ))}
62
+
63
+ <span className="text-xs text-gray-400 ml-auto flex items-center gap-3">
64
+ {tasksTotal > 0 && (
65
+ <span>
66
+ {tasksDone}/{tasksTotal} tasks
67
+ </span>
68
+ )}
69
+ <span>{idea.commentsCount} comments</span>
70
+ <span>{timeAgo(idea.createdAt)}</span>
71
+ </span>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </Link>
77
+ );
78
+ }
components/Navbar.tsx ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+ import { useEffect, useState } from "react";
5
+
6
+ export function Navbar() {
7
+ const [nickname, setNickname] = useState<string | null>(null);
8
+ const [editing, setEditing] = useState(false);
9
+ const [input, setInput] = useState("");
10
+
11
+ useEffect(() => {
12
+ fetch("/api/me/nickname")
13
+ .then((r) => r.json())
14
+ .then((d) => setNickname(d.data?.nickname || null))
15
+ .catch(() => {});
16
+ }, []);
17
+
18
+ async function saveNickname() {
19
+ if (!input.trim()) return;
20
+ const res = await fetch("/api/me/nickname", {
21
+ method: "POST",
22
+ headers: { "Content-Type": "application/json" },
23
+ body: JSON.stringify({ nickname: input.trim() }),
24
+ });
25
+ if (res.ok) {
26
+ const d = await res.json();
27
+ setNickname(d.data.nickname);
28
+ setEditing(false);
29
+ }
30
+ }
31
+
32
+ return (
33
+ <nav className="bg-white border-b border-gray-200 sticky top-0 z-50">
34
+ <div className="max-w-5xl mx-auto px-4 h-14 flex items-center justify-between">
35
+ <Link href="/" className="font-bold text-lg text-indigo-600">
36
+ DemandBoard
37
+ </Link>
38
+
39
+ <div className="flex items-center gap-4">
40
+ {editing ? (
41
+ <div className="flex items-center gap-2">
42
+ <input
43
+ type="text"
44
+ value={input}
45
+ onChange={(e) => setInput(e.target.value)}
46
+ onKeyDown={(e) => e.key === "Enter" && saveNickname()}
47
+ placeholder="Your nickname"
48
+ className="px-2 py-1 border rounded text-sm w-32"
49
+ autoFocus
50
+ />
51
+ <button
52
+ onClick={saveNickname}
53
+ className="text-sm text-indigo-600 hover:underline"
54
+ >
55
+ Save
56
+ </button>
57
+ <button
58
+ onClick={() => setEditing(false)}
59
+ className="text-sm text-gray-400 hover:underline"
60
+ >
61
+ Cancel
62
+ </button>
63
+ </div>
64
+ ) : (
65
+ <button
66
+ onClick={() => {
67
+ setInput(nickname || "");
68
+ setEditing(true);
69
+ }}
70
+ className="text-sm text-gray-500 hover:text-gray-700"
71
+ >
72
+ {nickname || "Set nickname"}
73
+ </button>
74
+ )}
75
+
76
+ <Link
77
+ href="/submit"
78
+ className="bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-indigo-700 transition-colors"
79
+ >
80
+ Submit Idea
81
+ </Link>
82
+ </div>
83
+ </div>
84
+ </nav>
85
+ );
86
+ }
components/TaskList.tsx ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+
5
+ interface TaskLink {
6
+ id: string;
7
+ url: string;
8
+ label: string;
9
+ createdByAnonId: string;
10
+ }
11
+
12
+ interface Task {
13
+ id: string;
14
+ title: string;
15
+ description: string;
16
+ acceptanceCriteria: string;
17
+ effort: string;
18
+ status: string;
19
+ claimedByAnonId: string | null;
20
+ links: TaskLink[];
21
+ }
22
+
23
+ const statusColors: Record<string, string> = {
24
+ open: "bg-gray-100 text-gray-700",
25
+ in_progress: "bg-blue-100 text-blue-700",
26
+ done: "bg-green-100 text-green-700",
27
+ };
28
+
29
+ const statusLabels: Record<string, string> = {
30
+ open: "Open",
31
+ in_progress: "In Progress",
32
+ done: "Done",
33
+ };
34
+
35
+ const effortColors: Record<string, string> = {
36
+ S: "bg-emerald-50 text-emerald-700",
37
+ M: "bg-yellow-50 text-yellow-700",
38
+ L: "bg-orange-50 text-orange-700",
39
+ XL: "bg-red-50 text-red-700",
40
+ };
41
+
42
+ export function TaskList({
43
+ tasks,
44
+ onUpdate,
45
+ }: {
46
+ tasks: Task[];
47
+ onUpdate: (tasks: Task[]) => void;
48
+ }) {
49
+ const [expandedId, setExpandedId] = useState<string | null>(null);
50
+ const [linkUrl, setLinkUrl] = useState("");
51
+ const [linkLabel, setLinkLabel] = useState("");
52
+ const [actionLoading, setActionLoading] = useState<string | null>(null);
53
+
54
+ async function claimTask(taskId: string) {
55
+ setActionLoading(taskId);
56
+ const res = await fetch(`/api/tasks/${taskId}/claim`, { method: "POST" });
57
+ if (res.ok) {
58
+ const d = await res.json();
59
+ onUpdate(tasks.map((t) => (t.id === taskId ? { ...t, ...d.data } : t)));
60
+ }
61
+ setActionLoading(null);
62
+ }
63
+
64
+ async function unclaimTask(taskId: string) {
65
+ setActionLoading(taskId);
66
+ const res = await fetch(`/api/tasks/${taskId}/claim`, {
67
+ method: "DELETE",
68
+ });
69
+ if (res.ok) {
70
+ const d = await res.json();
71
+ onUpdate(tasks.map((t) => (t.id === taskId ? { ...t, ...d.data } : t)));
72
+ }
73
+ setActionLoading(null);
74
+ }
75
+
76
+ async function updateStatus(taskId: string, status: string) {
77
+ setActionLoading(taskId);
78
+ const res = await fetch(`/api/tasks/${taskId}/status`, {
79
+ method: "POST",
80
+ headers: { "Content-Type": "application/json" },
81
+ body: JSON.stringify({ status }),
82
+ });
83
+ if (res.ok) {
84
+ const d = await res.json();
85
+ onUpdate(tasks.map((t) => (t.id === taskId ? { ...t, ...d.data } : t)));
86
+ }
87
+ setActionLoading(null);
88
+ }
89
+
90
+ async function addLink(taskId: string) {
91
+ if (!linkUrl.trim()) return;
92
+ const res = await fetch(`/api/tasks/${taskId}/links`, {
93
+ method: "POST",
94
+ headers: { "Content-Type": "application/json" },
95
+ body: JSON.stringify({ url: linkUrl, label: linkLabel || undefined }),
96
+ });
97
+ if (res.ok) {
98
+ const d = await res.json();
99
+ onUpdate(
100
+ tasks.map((t) =>
101
+ t.id === taskId ? { ...t, links: [...t.links, d.data] } : t
102
+ )
103
+ );
104
+ setLinkUrl("");
105
+ setLinkLabel("");
106
+ }
107
+ }
108
+
109
+ async function deleteLink(taskId: string, linkId: string) {
110
+ const res = await fetch(`/api/task-links/${linkId}`, {
111
+ method: "DELETE",
112
+ });
113
+ if (res.ok) {
114
+ onUpdate(
115
+ tasks.map((t) =>
116
+ t.id === taskId
117
+ ? { ...t, links: t.links.filter((l) => l.id !== linkId) }
118
+ : t
119
+ )
120
+ );
121
+ }
122
+ }
123
+
124
+ return (
125
+ <div className="space-y-2">
126
+ {tasks.map((task) => {
127
+ const isExpanded = expandedId === task.id;
128
+ const isLoading = actionLoading === task.id;
129
+
130
+ return (
131
+ <div
132
+ key={task.id}
133
+ className="bg-white border border-gray-200 rounded-lg overflow-hidden"
134
+ >
135
+ <button
136
+ onClick={() =>
137
+ setExpandedId(isExpanded ? null : task.id)
138
+ }
139
+ className="w-full px-4 py-3 flex items-center gap-3 text-left hover:bg-gray-50"
140
+ >
141
+ <span
142
+ className={`px-2 py-0.5 rounded text-xs font-medium ${
143
+ statusColors[task.status]
144
+ }`}
145
+ >
146
+ {statusLabels[task.status]}
147
+ </span>
148
+ <span
149
+ className={`px-1.5 py-0.5 rounded text-xs font-medium ${
150
+ effortColors[task.effort]
151
+ }`}
152
+ >
153
+ {task.effort}
154
+ </span>
155
+ <span className="flex-1 text-sm font-medium text-gray-900">
156
+ {task.title}
157
+ </span>
158
+ <svg
159
+ className={`w-4 h-4 text-gray-400 transition-transform ${
160
+ isExpanded ? "rotate-180" : ""
161
+ }`}
162
+ fill="none"
163
+ stroke="currentColor"
164
+ viewBox="0 0 24 24"
165
+ >
166
+ <path
167
+ strokeLinecap="round"
168
+ strokeLinejoin="round"
169
+ strokeWidth={2}
170
+ d="M19 9l-7 7-7-7"
171
+ />
172
+ </svg>
173
+ </button>
174
+
175
+ {isExpanded && (
176
+ <div className="px-4 pb-4 border-t border-gray-100 pt-3 space-y-3">
177
+ {task.description && (
178
+ <p className="text-sm text-gray-600">{task.description}</p>
179
+ )}
180
+
181
+ {task.acceptanceCriteria && (
182
+ <div>
183
+ <p className="text-xs font-medium text-gray-500 mb-1">
184
+ Acceptance Criteria
185
+ </p>
186
+ <p className="text-sm text-gray-700">
187
+ {task.acceptanceCriteria}
188
+ </p>
189
+ </div>
190
+ )}
191
+
192
+ {/* Actions */}
193
+ <div className="flex flex-wrap gap-2">
194
+ {task.status === "open" && (
195
+ <button
196
+ onClick={() => claimTask(task.id)}
197
+ disabled={isLoading}
198
+ className="px-3 py-1.5 bg-indigo-600 text-white rounded text-sm hover:bg-indigo-700 disabled:opacity-50"
199
+ >
200
+ Claim Task
201
+ </button>
202
+ )}
203
+ {task.claimedByAnonId && task.status !== "done" && (
204
+ <>
205
+ {task.status === "in_progress" && (
206
+ <button
207
+ onClick={() => updateStatus(task.id, "done")}
208
+ disabled={isLoading}
209
+ className="px-3 py-1.5 bg-green-600 text-white rounded text-sm hover:bg-green-700 disabled:opacity-50"
210
+ >
211
+ Mark Done
212
+ </button>
213
+ )}
214
+ <button
215
+ onClick={() => unclaimTask(task.id)}
216
+ disabled={isLoading}
217
+ className="px-3 py-1.5 bg-gray-200 text-gray-700 rounded text-sm hover:bg-gray-300 disabled:opacity-50"
218
+ >
219
+ Unclaim
220
+ </button>
221
+ </>
222
+ )}
223
+ {task.status === "done" && (
224
+ <button
225
+ onClick={() => updateStatus(task.id, "open")}
226
+ disabled={isLoading}
227
+ className="px-3 py-1.5 bg-gray-200 text-gray-700 rounded text-sm hover:bg-gray-300 disabled:opacity-50"
228
+ >
229
+ Reopen
230
+ </button>
231
+ )}
232
+ </div>
233
+
234
+ {/* Links */}
235
+ {task.links.length > 0 && (
236
+ <div className="space-y-1">
237
+ <p className="text-xs font-medium text-gray-500">Links</p>
238
+ {task.links.map((link) => (
239
+ <div
240
+ key={link.id}
241
+ className="flex items-center gap-2 text-sm"
242
+ >
243
+ <a
244
+ href={link.url}
245
+ target="_blank"
246
+ rel="noopener noreferrer"
247
+ className="text-indigo-600 hover:underline truncate"
248
+ >
249
+ {link.label || link.url}
250
+ </a>
251
+ <button
252
+ onClick={() => deleteLink(task.id, link.id)}
253
+ className="text-gray-400 hover:text-red-500 text-xs"
254
+ >
255
+ Remove
256
+ </button>
257
+ </div>
258
+ ))}
259
+ </div>
260
+ )}
261
+
262
+ {/* Add Link */}
263
+ {task.claimedByAnonId && (
264
+ <div className="flex gap-2">
265
+ <input
266
+ type="url"
267
+ value={linkUrl}
268
+ onChange={(e) => setLinkUrl(e.target.value)}
269
+ placeholder="https://github.com/..."
270
+ className="flex-1 px-2 py-1.5 border rounded text-sm"
271
+ />
272
+ <input
273
+ type="text"
274
+ value={linkLabel}
275
+ onChange={(e) => setLinkLabel(e.target.value)}
276
+ placeholder="Label"
277
+ className="w-24 px-2 py-1.5 border rounded text-sm"
278
+ />
279
+ <button
280
+ onClick={() => addLink(task.id)}
281
+ className="px-3 py-1.5 bg-gray-100 rounded text-sm hover:bg-gray-200"
282
+ >
283
+ Add
284
+ </button>
285
+ </div>
286
+ )}
287
+ </div>
288
+ )}
289
+ </div>
290
+ );
291
+ })}
292
+ </div>
293
+ );
294
+ }
components/UpvoteButton.tsx ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+
5
+ export function UpvoteButton({
6
+ ideaId,
7
+ initialCount,
8
+ initialHasVoted,
9
+ }: {
10
+ ideaId: string;
11
+ initialCount: number;
12
+ initialHasVoted: boolean;
13
+ }) {
14
+ const [count, setCount] = useState(initialCount);
15
+ const [hasVoted, setHasVoted] = useState(initialHasVoted);
16
+ const [isPending, setIsPending] = useState(false);
17
+
18
+ async function handleVote(e: React.MouseEvent) {
19
+ e.preventDefault();
20
+ e.stopPropagation();
21
+ if (isPending) return;
22
+
23
+ setIsPending(true);
24
+ const newVoted = !hasVoted;
25
+ setHasVoted(newVoted);
26
+ setCount((c) => (newVoted ? c + 1 : c - 1));
27
+
28
+ try {
29
+ const res = await fetch(`/api/ideas/${ideaId}/upvote`, {
30
+ method: newVoted ? "POST" : "DELETE",
31
+ });
32
+ if (!res.ok) {
33
+ setHasVoted(!newVoted);
34
+ setCount((c) => (newVoted ? c - 1 : c + 1));
35
+ }
36
+ } catch {
37
+ setHasVoted(!newVoted);
38
+ setCount((c) => (newVoted ? c - 1 : c + 1));
39
+ } finally {
40
+ setIsPending(false);
41
+ }
42
+ }
43
+
44
+ return (
45
+ <button
46
+ onClick={handleVote}
47
+ disabled={isPending}
48
+ className={`flex items-center gap-1 px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${
49
+ hasVoted
50
+ ? "bg-indigo-100 text-indigo-700 border border-indigo-300"
51
+ : "bg-gray-100 text-gray-600 border border-gray-200 hover:bg-gray-200"
52
+ }`}
53
+ >
54
+ <svg
55
+ className="w-4 h-4"
56
+ fill={hasVoted ? "currentColor" : "none"}
57
+ stroke="currentColor"
58
+ viewBox="0 0 24 24"
59
+ >
60
+ <path
61
+ strokeLinecap="round"
62
+ strokeLinejoin="round"
63
+ strokeWidth={2}
64
+ d="M5 15l7-7 7 7"
65
+ />
66
+ </svg>
67
+ {count}
68
+ </button>
69
+ );
70
+ }
eslint.config.mjs ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { dirname } from "path";
2
+ import { fileURLToPath } from "url";
3
+ import { FlatCompat } from "@eslint/eslintrc";
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+
8
+ const compat = new FlatCompat({
9
+ baseDirectory: __dirname,
10
+ });
11
+
12
+ const eslintConfig = [
13
+ ...compat.extends("next/core-web-vitals", "next/typescript"),
14
+ ];
15
+
16
+ export default eslintConfig;
lib/anon-id.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import { cookies } from "next/headers";
2
+
3
+ export async function getAnonId(): Promise<string> {
4
+ const cookieStore = await cookies();
5
+ const anonId = cookieStore.get("anon_id")?.value;
6
+ if (!anonId) {
7
+ throw new Error("anon_id cookie not found");
8
+ }
9
+ return anonId;
10
+ }
lib/embedding.ts ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { llm, EMBEDDING_MODEL } from "./llm";
2
+
3
+ export async function generateEmbedding(
4
+ text: string
5
+ ): Promise<number[] | null> {
6
+ try {
7
+ const response = await llm.embeddings.create({
8
+ model: EMBEDDING_MODEL,
9
+ input: text.slice(0, 8000),
10
+ });
11
+ return response.data[0].embedding;
12
+ } catch (error) {
13
+ console.error("Failed to generate embedding:", error);
14
+ return null;
15
+ }
16
+ }
17
+
18
+ export function cosineSimilarity(a: number[], b: number[]): number {
19
+ if (a.length !== b.length) return 0;
20
+ let dotProduct = 0;
21
+ let normA = 0;
22
+ let normB = 0;
23
+ for (let i = 0; i < a.length; i++) {
24
+ dotProduct += a[i] * b[i];
25
+ normA += a[i] * a[i];
26
+ normB += b[i] * b[i];
27
+ }
28
+ if (normA === 0 || normB === 0) return 0;
29
+ return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
30
+ }
31
+
32
+ export function findSimilarIdeas(
33
+ targetEmbedding: number[],
34
+ allIdeas: { id: string; title: string; embedding: string | null }[],
35
+ excludeId: string,
36
+ topK: number = 5
37
+ ): { id: string; title: string; similarity: number }[] {
38
+ const results: { id: string; title: string; similarity: number }[] = [];
39
+
40
+ for (const idea of allIdeas) {
41
+ if (idea.id === excludeId || !idea.embedding) continue;
42
+ try {
43
+ const embedding = JSON.parse(idea.embedding) as number[];
44
+ const similarity = cosineSimilarity(targetEmbedding, embedding);
45
+ results.push({ id: idea.id, title: idea.title, similarity });
46
+ } catch {
47
+ continue;
48
+ }
49
+ }
50
+
51
+ return results
52
+ .sort((a, b) => b.similarity - a.similarity)
53
+ .slice(0, topK)
54
+ .filter((r) => r.similarity > 0.3);
55
+ }
lib/hot-score.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ export function hotScore(upvotes: number, createdAt: Date): number {
2
+ const ageInHours =
3
+ (Date.now() - createdAt.getTime()) / (1000 * 60 * 60);
4
+ return Math.log10(Math.max(upvotes, 1)) - ageInHours / 24;
5
+ }
lib/llm.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import OpenAI from "openai";
2
+
3
+ export const llm = new OpenAI({
4
+ baseURL: process.env.OPENAI_API_BASE_URL || "https://api.openai.com/v1",
5
+ apiKey: process.env.OPENAI_API_KEY || "",
6
+ });
7
+
8
+ export const LLM_MODEL = process.env.OPENAI_MODEL || "gpt-4o-mini";
9
+ export const EMBEDDING_MODEL =
10
+ process.env.OPENAI_EMBEDDING_MODEL || "text-embedding-3-small";
lib/prisma.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";
2
+ import { PrismaClient } from "@/generated/prisma/client";
3
+
4
+ const globalForPrisma = globalThis as unknown as {
5
+ prisma: PrismaClient | undefined;
6
+ };
7
+
8
+ function createPrismaClient() {
9
+ const adapter = new PrismaBetterSqlite3({
10
+ url: process.env.DATABASE_URL || "file:./prisma/dev.db",
11
+ });
12
+ return new PrismaClient({ adapter });
13
+ }
14
+
15
+ export const prisma = globalForPrisma.prisma ?? createPrismaClient();
16
+
17
+ if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
lib/prompts.ts ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export const IDEA_TO_SPEC_SYSTEM_PROMPT = `You are a product manager who turns vague product ideas into structured, buildable specifications.
2
+
3
+ Given a user's idea (and optional context like target users, platform, constraints), generate a structured specification.
4
+
5
+ You MUST return valid JSON with exactly this schema:
6
+ {
7
+ "title": "A concise title (5-10 words)",
8
+ "problemStatement": "A clear 2-3 sentence problem statement explaining what problem this solves and why it matters",
9
+ "tags": ["tag1", "tag2"],
10
+ "features": [
11
+ {
12
+ "title": "Feature name",
13
+ "description": "What it does and why (1-2 sentences)"
14
+ }
15
+ ],
16
+ "tasks": [
17
+ {
18
+ "title": "Task name",
19
+ "description": "What needs to be implemented",
20
+ "acceptanceCriteria": "How to verify the task is done correctly",
21
+ "effort": "S|M|L|XL"
22
+ }
23
+ ],
24
+ "openQuestions": ["Question about missing info"]
25
+ }
26
+
27
+ Rules:
28
+ - Generate exactly 3-7 features
29
+ - Generate exactly 10-20 tasks that cover all features
30
+ - Effort estimates: S (< 2 hours), M (2-8 hours), L (1-3 days), XL (3+ days)
31
+ - Tags should be lowercase, technology or domain related (3-6 tags)
32
+ - Tasks must be concrete and implementable by a developer
33
+ - Do NOT hallucinate integrations or technologies the user didn't mention
34
+ - If key information is missing, add questions to openQuestions rather than guessing
35
+ - Return ONLY valid JSON, no markdown fences or extra text`;
36
+
37
+ export function buildIdeaPrompt(
38
+ rawInput: string,
39
+ targetUsers?: string,
40
+ platform?: string,
41
+ constraints?: string
42
+ ): string {
43
+ let prompt = rawInput;
44
+
45
+ if (targetUsers) {
46
+ prompt += `\n\nTarget users: ${targetUsers}`;
47
+ }
48
+ if (platform) {
49
+ prompt += `\nPlatform: ${platform}`;
50
+ }
51
+ if (constraints) {
52
+ prompt += `\nConstraints: ${constraints}`;
53
+ }
54
+
55
+ return prompt;
56
+ }
lib/rate-limit.ts ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const rateLimitMap = new Map<
2
+ string,
3
+ { count: number; resetTime: number }
4
+ >();
5
+
6
+ export function rateLimit(
7
+ identifier: string,
8
+ limit: number = 5,
9
+ windowMs: number = 60 * 60 * 1000 // 1 hour
10
+ ): { success: boolean; remaining: number } {
11
+ const now = Date.now();
12
+ const entry = rateLimitMap.get(identifier);
13
+
14
+ if (!entry || now > entry.resetTime) {
15
+ rateLimitMap.set(identifier, { count: 1, resetTime: now + windowMs });
16
+ return { success: true, remaining: limit - 1 };
17
+ }
18
+
19
+ if (entry.count >= limit) {
20
+ return { success: false, remaining: 0 };
21
+ }
22
+
23
+ entry.count++;
24
+ return { success: true, remaining: limit - entry.count };
25
+ }
lib/validators.ts ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { z } from "zod/v4";
2
+
3
+ export const submitIdeaSchema = z.object({
4
+ rawInputText: z
5
+ .string()
6
+ .min(20, "Idea must be at least 20 characters")
7
+ .max(5000, "Idea must be under 5000 characters"),
8
+ targetUsers: z.string().max(500).optional(),
9
+ platform: z.string().max(100).optional(),
10
+ constraints: z.string().max(1000).optional(),
11
+ });
12
+
13
+ export const commentSchema = z.object({
14
+ body: z
15
+ .string()
16
+ .min(1, "Comment cannot be empty")
17
+ .max(2000, "Comment must be under 2000 characters"),
18
+ });
19
+
20
+ export const taskStatusSchema = z.object({
21
+ status: z.enum(["open", "in_progress", "done"]),
22
+ });
23
+
24
+ export const taskLinkSchema = z.object({
25
+ url: z.url("Must be a valid URL"),
26
+ label: z.string().max(200).optional(),
27
+ });
28
+
29
+ export const nicknameSchema = z.object({
30
+ nickname: z.string().min(1).max(30),
31
+ });
32
+
33
+ export const specSchema = z.object({
34
+ title: z.string(),
35
+ problemStatement: z.string(),
36
+ tags: z.array(z.string()),
37
+ features: z.array(
38
+ z.object({
39
+ title: z.string(),
40
+ description: z.string(),
41
+ })
42
+ ),
43
+ tasks: z.array(
44
+ z.object({
45
+ title: z.string(),
46
+ description: z.string(),
47
+ acceptanceCriteria: z.string(),
48
+ effort: z.enum(["S", "M", "L", "XL"]),
49
+ })
50
+ ),
51
+ openQuestions: z.array(z.string()),
52
+ });
53
+
54
+ export type SubmitIdeaInput = z.infer<typeof submitIdeaSchema>;
55
+ export type SpecOutput = z.infer<typeof specSchema>;
middleware.ts ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextResponse } from "next/server";
2
+ import type { NextRequest } from "next/server";
3
+
4
+ export function middleware(request: NextRequest) {
5
+ const response = NextResponse.next();
6
+
7
+ if (!request.cookies.has("anon_id")) {
8
+ const anonId = crypto.randomUUID();
9
+ response.cookies.set({
10
+ name: "anon_id",
11
+ value: anonId,
12
+ path: "/",
13
+ httpOnly: true,
14
+ secure: process.env.NODE_ENV === "production",
15
+ sameSite: "lax",
16
+ maxAge: 60 * 60 * 24 * 365, // 1 year
17
+ });
18
+ }
19
+
20
+ return response;
21
+ }
22
+
23
+ export const config = {
24
+ matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
25
+ };
next.config.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import type { NextConfig } from "next";
2
+
3
+ const nextConfig: NextConfig = {};
4
+
5
+ export default nextConfig;
package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
package.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "community-demand-board",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start",
9
+ "lint": "next lint",
10
+ "db:push": "npx prisma db push",
11
+ "db:studio": "npx prisma studio",
12
+ "postinstall": "npx prisma generate"
13
+ },
14
+ "dependencies": {
15
+ "@prisma/adapter-better-sqlite3": "^7.4.1",
16
+ "@prisma/client": "^7.4.1",
17
+ "@tailwindcss/postcss": "^4.2.0",
18
+ "@types/node": "^25.3.0",
19
+ "@types/react": "^19.2.14",
20
+ "@types/react-dom": "^19.2.3",
21
+ "@types/uuid": "^10.0.0",
22
+ "autoprefixer": "^10.4.24",
23
+ "dotenv": "^17.3.1",
24
+ "eslint": "^9.39.2",
25
+ "eslint-config-next": "^16.1.6",
26
+ "next": "^16.1.6",
27
+ "openai": "^6.22.0",
28
+ "postcss": "^8.5.6",
29
+ "prisma": "^7.4.1",
30
+ "react": "^19.2.4",
31
+ "react-dom": "^19.2.4",
32
+ "tailwindcss": "^4.2.0",
33
+ "typescript": "^5.9.3",
34
+ "uuid": "^13.0.0",
35
+ "zod": "^4.3.6"
36
+ }
37
+ }
postcss.config.mjs ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ /** @type {import('postcss-load-config').Config} */
2
+ const config = {
3
+ plugins: {
4
+ "@tailwindcss/postcss": {},
5
+ },
6
+ };
7
+
8
+ export default config;
prisma.config.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file was generated by Prisma, and assumes you have installed the following:
2
+ // npm install --save-dev prisma dotenv
3
+ import "dotenv/config";
4
+ import { defineConfig } from "prisma/config";
5
+
6
+ export default defineConfig({
7
+ schema: "prisma/schema.prisma",
8
+ migrations: {
9
+ path: "prisma/migrations",
10
+ },
11
+ datasource: {
12
+ url: process.env["DATABASE_URL"],
13
+ },
14
+ });
prisma/schema.prisma ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ generator client {
2
+ provider = "prisma-client"
3
+ output = "../generated/prisma"
4
+ }
5
+
6
+ datasource db {
7
+ provider = "sqlite"
8
+ }
9
+
10
+ model Idea {
11
+ id String @id @default(uuid())
12
+ createdAt DateTime @default(now()) @map("created_at")
13
+ createdByAnonId String @map("created_by_anon_id")
14
+ rawInputText String @map("raw_input_text")
15
+ title String
16
+ problemStatement String @map("problem_statement")
17
+ tags String @default("[]") // JSON-serialized string[]
18
+ features String @default("[]") // JSON-serialized Feature[]
19
+ openQuestions String @default("[]") @map("open_questions") // JSON-serialized string[]
20
+ upvotesCount Int @default(0) @map("upvotes_count")
21
+ commentsCount Int @default(0) @map("comments_count")
22
+ embedding String? // JSON-serialized float[] for similarity
23
+
24
+ tasks Task[]
25
+ comments Comment[]
26
+ votes Vote[]
27
+
28
+ @@map("ideas")
29
+ }
30
+
31
+ model Task {
32
+ id String @id @default(uuid())
33
+ ideaId String @map("idea_id")
34
+ title String
35
+ description String @default("")
36
+ acceptanceCriteria String @default("") @map("acceptance_criteria")
37
+ effort String @default("M") // "S" | "M" | "L" | "XL"
38
+ status String @default("open") // "open" | "in_progress" | "done"
39
+ claimedByAnonId String? @map("claimed_by_anon_id")
40
+ claimedAt DateTime? @map("claimed_at")
41
+ updatedAt DateTime @updatedAt @map("updated_at")
42
+
43
+ idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
44
+ links TaskLink[]
45
+
46
+ @@map("tasks")
47
+ }
48
+
49
+ model TaskLink {
50
+ id String @id @default(uuid())
51
+ taskId String @map("task_id")
52
+ url String
53
+ label String @default("")
54
+ createdByAnonId String @map("created_by_anon_id")
55
+ createdAt DateTime @default(now()) @map("created_at")
56
+
57
+ task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
58
+
59
+ @@map("task_links")
60
+ }
61
+
62
+ model Comment {
63
+ id String @id @default(uuid())
64
+ ideaId String @map("idea_id")
65
+ body String
66
+ createdByAnonId String @map("created_by_anon_id")
67
+ nickname String?
68
+ createdAt DateTime @default(now()) @map("created_at")
69
+
70
+ idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
71
+
72
+ @@map("comments")
73
+ }
74
+
75
+ model Vote {
76
+ ideaId String @map("idea_id")
77
+ anonId String @map("anon_id")
78
+ createdAt DateTime @default(now()) @map("created_at")
79
+
80
+ idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
81
+
82
+ @@unique([ideaId, anonId])
83
+ @@map("votes")
84
+ }
85
+
86
+ model AnonUser {
87
+ id String @id
88
+ nickname String?
89
+ createdAt DateTime @default(now()) @map("created_at")
90
+
91
+ @@map("anon_users")
92
+ }
tsconfig.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": [
5
+ "dom",
6
+ "dom.iterable",
7
+ "esnext"
8
+ ],
9
+ "allowJs": true,
10
+ "skipLibCheck": true,
11
+ "strict": true,
12
+ "noEmit": true,
13
+ "esModuleInterop": true,
14
+ "module": "esnext",
15
+ "moduleResolution": "bundler",
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": true,
18
+ "jsx": "react-jsx",
19
+ "incremental": true,
20
+ "plugins": [
21
+ {
22
+ "name": "next"
23
+ }
24
+ ],
25
+ "paths": {
26
+ "@/*": [
27
+ "./*"
28
+ ]
29
+ }
30
+ },
31
+ "include": [
32
+ "next-env.d.ts",
33
+ "**/*.ts",
34
+ "**/*.tsx",
35
+ ".next/types/**/*.ts",
36
+ ".next/dev/types/**/*.ts"
37
+ ],
38
+ "exclude": [
39
+ "node_modules",
40
+ "src/**/*.py"
41
+ ]
42
+ }