I am a researcher in video/image compression. Every time I have new data, I have to write Python code to plot RD curves, which is too troublesome. Please help me write a web page to implement the following functions.
Use better-auth for email registration and login.
After logging in, users can create a new dataset, writing a name and description.
In the dataset, users can create a new method, such as "JPEG", and fill in a description.
Users can edit (including delete) the method or all RD data points of that method.
Users can also upload data files in any format (such as txt, csv, etc.) or directly paste experimental results as text, which will be parsed by AI and converted into standard JSON data in the format of {"name": "JPEG", "description": "some description", "data":[{"bpp": float, "psnr": float, "ms_ssim": float}, ...]}, and displayed. The user decides whether to insert it into the database. If there is the same name, merge data points sorted by bpp without updating other content.
If name or description is not parsed, let the user input them, where name cannot be empty.
Each point must have bpp, representing the horizontal axis. PSNR, MS-SSIM, etc. are optional, representing the vertical axis. Users are also allowed to customize other vertical axes, such as LPIPS, etc. The two default vertical axes can be deleted by the user.
Each vertical axis data has a mapping function that needs to be customized by the user, indicating the value on the chart. For example, the range of MS-SSIM is 0-1, but when displayed on the chart, it needs -10*log10(1 - ms_ssim). Users can fill in this mapping function, but please be careful to prevent users from filling in dangerous functions.
AI uses the OpenAI format API for data parsing, and parameters such as endpoint, api key, and model can be specified through environment variables.
Users can directly view the RD curve graphs of various methods on the dataset interface, and support hiding the curves of certain methods or certain points in a method. These display settings can be saved in the browser locally for easy restoration on the next visit.
All API responses and page content should be in English.
The product name is "RD Curve AI".
For the frontend, please use the shadcn/ui component library and lucide icon library.
For the database, please use Drizzle ORM to connect to PostgreSQL.
Use pnpm as the package management tool. The shadcn/ui component library should be installed and initialized using the npx command.
Types should be validated and transformed using zod, and uniformly saved in the lib/types.ts file.
Environment variables should be uniformly managed and exported using the lib/config.ts file.
When necessary, you can call shadcn mcp to retrieve the component library, lucide-icons mcp to retrieve the icon library, and context7 mcp to retrieve the latest documentation and materials for the tech stack used.
Reuse existing code in the lib folder as much as possible.
All API information and frontend text should be in English.
# RD Curve AI - Copilot Instructions
You are assisting with "RD Curve AI", a Next.js 16 application for video/image compression researchers to manage datasets and plot Rate-Distortion (RD) curves.
## Tech Stack & Key Libraries
- **Framework:** Next.js 16 (App Router), React 19
- **Database:** PostgreSQL, Drizzle ORM (`lib/schema.ts`, `lib/db.ts`)
- **Auth:** Better-Auth (`lib/auth.ts`, `lib/auth-client.ts`)
- **UI:** Tailwind CSS, shadcn/ui, Recharts (`components/rd-chart.tsx`)
- **Validation:** Zod (`lib/types.ts`)
- **AI:** OpenAI (for data parsing)
## Architecture Overview
### Data Model (`lib/schema.ts`)
The core hierarchy is **Dataset -> Method -> DataPoint**.
- **Dataset:** A collection of methods (e.g., "Kodak Dataset").
- **Method:** A specific algorithm (e.g., "JPEG", "HEVC").
- **DataPoint:** A single result with `bpp` (x-axis) and dynamic `metrics` (y-axis) stored in a `jsonb` column.
- **Metric:** Custom definitions for y-axis values (e.g., "PSNR", "MS-SSIM") with a `mapping_function` string for display transformation.
### Authentication Pattern
- **Server-side:** Use `auth.api.getSession({ headers: await headers() })` in API routes/Server Components.
- **Client-side:** Use `authClient` hooks (e.g., `useSession`).
- **Protection:** Always check `if (!session)` in API routes before sensitive operations.
### API Route Pattern (`app/api/**`)
Follow this pattern for Route Handlers:
1. **Auth Check:** Verify session immediately.
2. **Validation:** Parse request body with Zod schemas from `lib/types.ts`.
3. **DB Operation:** Use Drizzle to query/mutate.
4. **Response:** Return `NextResponse.json`.
## Critical Conventions
### Database & Drizzle
- **Schema:** Define all tables in `lib/schema.ts`.
- **IDs:** Use `uuid` with `.defaultRandom()`.
- **Relations:** Use `drizzle-orm` relations for cleaner queries.
- **JSONB:** Use the `metrics` jsonb column in `data_point` for flexible metric storage.
### Frontend Components
- **UI:** Use `components/ui` (shadcn) for primitives, install new ones with `npx shadcn@latest add <component>`.
- **Charts:** Use `Recharts` in `components/rd-chart.tsx`. Handle the `mapping_function` logic (likely via `lib/safe-eval.ts`) when rendering axes.
- **Icons:** Use `lucide-react`.
- **MCP:** Use `context7` mcp for documentation if needed. Use `shadcn` mcp for UI components. Use `lucide-icons` mcp for searching icons.
### Configuration
- **Env Vars:** Access via `lib/config.ts` (e.g., `CONFIG.OPENAI_API_KEY`), NOT `process.env` directly.
- **Types:** Keep shared Zod schemas and TS interfaces in `lib/types.ts`.
### Language
- All API responses and frontend text must be in English.
## Developer Workflows
- **Migrations:** Run `pnpm db:generate` and `pnpm db:migrate` when changing schema.
- **AI Parsing:** The parsing logic (converting text to JSON) should handle unstructured input and map it to the `data_point` structure.
Building a Full-Stack Application with AI Again — RD Curve AI
Building a Full-Stack Application with AI Again — RD Curve AI
At the beginning of the year, I tried using a large language model to complete a full-stack project. See "A Record of Using AI to Complete an Entire Full-Stack Project".
At that time, my opinion was that it was very difficult. Even with existing code in other languages as a reference, it was still hard to reproduce. To a large extent, human involvement in writing code was still necessary (especially for some compilation issues and runtime bugs).
But this year, the rapid progress of agents has also driven the fast development of Vibe Coding, and as I gradually became more familiar with the Next.js framework, this task seems to have become much simpler.
As a researcher in the compression field, I have always been troubled by having to find experimental results of old methods from past experimental data and write matplotlib code to plot new RD curves every time. These past few days, I finally couldn't resist wanting to create an application for managing related experimental data and performing visualization — RD Curve AI. You are welcome to try it out and give me some suggestions for improvement.
This time, Vibe Coding actually took only one day to complete. Personally, I think it went very smoothly. The general process was as follows:
Finally, I want to explain that Vibe Coding still cannot help a novice complete a relatively complex system task. Although a person does not necessarily have to fully understand the code written by AI, they must have a relatively comprehensive grasp of the system framework. Here I quote a radical statement: "AI (almost) cannot help you complete tasks that you do not already know how to do". My familiarity with the Next.js framework grew over this year through self-study and completing small projects or improving some open-source projects with the help of AI. After accumulating this experience, AI can become an excellent tool for improving efficiency.