# REWORK.md

This folder (refs/) contains my current prototype. It was built with AI tools
over several iterations. Treat everything inside refs/ as a reference, not as
the final code. You are allowed to ignore, rewrite, or restructure any of it.

## Goal

Rebuild this prototype as a clean, maintainable web application.
The goal is not a new design or new features. The goal is a proper structure
I can keep developing without fear of breaking everything.

## Stack

- Next.js (App Router)
- TypeScript
- Tailwind CSS
- shadcn/ui for UI components, where it makes sense
- SQLite for the database to start with (managed PostgreSQL later, if needed)
- GitHub as the source of truth
- Vercel for deployment

Do not introduce Docker, Kubernetes, microservices, or custom CI/CD pipelines.
If any of that becomes necessary later, we will add it then.

## How the code must be organized

- Split the UI into small, reusable components. One component per file.
- Keep pages thin. Pages assemble components; they do not contain business logic.
- Move all business logic into a /services folder. Logic must not live inside React components.
- Create a data layer under /lib/db. All database access goes through this layer only.
  UI and services never talk to the database directly.
- Keep TypeScript types in one place per domain. Do not redefine the same type in multiple files.
- No single file should grow beyond ~300 lines. If it does, split it.

## Data

- Use a real database from day one. SQLite via Prisma or Drizzle is fine.
- Define the entities clearly. If the prototype implies entities that are not
  explicit, name them and propose a schema.
- Do not store important data only in React state or in local JSON files.

## Auth and roles

- Start with simple email + password authentication, or magic-link flow.
- Support at least two roles: admin and user. Add more only if the prototype already needs them.
- Protect admin routes on the server, not only by hiding them in the UI.

## Admin area

- Create a minimal admin area inside the same Next.js app under /admin.
- It must let me view, create, edit, and delete the main entities of the product
  without touching the database directly.
- Keep it simple: tables and forms. No dashboards, no charts, no decoration.

## What to keep from the prototype

- The product flows. How the user moves through the app step by step.
- The domain terminology and naming.
- Any UI decisions that clearly work well.

## What to discard from the prototype

- Copy-pasted blocks of code.
- Inline styles mixed with logic.
- Anything that looks like it was patched more than twice.
- Single files longer than ~500 lines.

## Hard rules

- Do not put everything in one file.
- Do not mix UI and business logic.
- Do not invent new frameworks or exotic libraries.
- Do not optimize anything I have not explicitly asked you to optimize.
- Do not add features that are not in the prototype. New features will be requested separately.

## Workflow for every task

1. Read relevant files in refs/.
2. Re-read this REWORK.md.
3. Propose a short plan before writing code.
4. Wait for approval.
5. Implement one area at a time. Small, reviewable steps.
6. After each step, tell me what changed and why.
