💻 Coding

Full-Stack REST API Builder with Authentication & Database

Generate a production-ready REST API with JWT authentication, database models, CRUD operations, and error handling in your preferred framework.

0.0
0Reviews
A
March 7, 2026

Prompt

Act as a senior full-stack developer with 10+ years of experience building scalable backend systems. Generate a complete REST API for [Application Type] using [Framework / Language] (e.g., Node.js/Express, Python/FastAPI, Go/Gin).

Requirements:

Project Structure: Provide the full directory layout following industry best practices (MVC or Clean Architecture).

Database Models: Design and implement schemas/models for [Core Entities] using [ORM / Database] (e.g., Prisma/PostgreSQL, SQLAlchemy/MySQL, GORM/SQLite).

Authentication:

Implement JWT-based authentication (register, login, refresh token).

Add middleware for protected routes.

Include password hashing with bcrypt or equivalent.

CRUD Endpoints: For each entity, implement:

GET (list with pagination and filtering)

GET by ID

POST (with validation)

PUT / PATCH

DELETE (soft delete preferred)

Error Handling: Implement a centralized error handler with consistent JSON error responses.

Validation: Add input validation on all POST/PUT endpoints.

Environment Config: Use environment variables for secrets, database URL, and port.

Constraints:

Write clean, commented code.

Include a sample .env file.

Provide setup instructions in a README section.

Tone: Technical but clear. No unnecessary comments.

Instructions

Choose your stack: Replace [Framework / Language] with your preferred backend (e.g., 'Node.js with Express and TypeScript'). Define your entities: Replace [Core Entities] with your data models (e.g., 'Users, Products, Orders'). Specify database: Mention your preferred database and ORM so the generated schemas match. Extend incrementally: Use the generated code as a foundation and ask follow-up prompts for specific features like file uploads, WebSockets, or rate limiting.

Examples

Example Input

Act as a senior full-stack developer with 10+ years of experience building scalable backend systems. Generate a complete REST API for [E-commerce Backend Service] using [Node.js with Express and TypeScript] (e.g., Node.js/Express, Python/FastAPI, Go/Gin).

Requirements:

Project Structure: Provide the full directory layout following industry best practices (MVC or Clean Architecture).

Database Models: Design and implement schemas/models for [Users, Products, Categories, and Orders] using [Prisma with a PostgreSQL database] (e.g., Prisma/PostgreSQL, SQLAlchemy/MySQL, GORM/SQLite).

Authentication:

Implement JWT-based authentication (register, login, refresh token).

Add middleware for protected routes.

Include password hashing with bcrypt or equivalent.

CRUD Endpoints: For each entity, implement:

GET (list with pagination and filtering)

GET by ID

POST (with validation)

PUT / PATCH

DELETE (soft delete preferred)

Error Handling: Implement a centralized error handler with consistent JSON error responses.

Validation: Add input validation on all POST/PUT endpoints.

Environment Config: Use environment variables for secrets, database URL, and port.

Constraints:

Write clean, commented code.

Include a sample .env file.

Provide setup instructions in a README section.

Tone: Technical but clear. No unnecessary comments.

Example Output

E-commerce Backend REST API

Stack: Node.js + Express + TypeScript + Prisma + PostgreSQL

1. Project Structure
ecommerce-api/
 ├ src/
 │ ├ controllers/
 │ │  user.controller.ts
 │ │  product.controller.ts
 │ │  category.controller.ts
 │ │  order.controller.ts
 │ ├ routes/
 │ │  user.routes.ts
 │ │  product.routes.ts
 │ │  category.routes.ts
 │ │  order.routes.ts
 │ │  auth.routes.ts
 │ ├ middleware/
 │ │  auth.middleware.ts
 │ │  error.middleware.ts
 │ │  validate.middleware.ts
 │ ├ services/
 │ │  auth.service.ts
 │ ├ utils/
 │ │  jwt.ts
 │ ├ app.ts
 │ └ server.ts
 ├ prisma/
 │ └ schema.prisma
 ├ package.json
 ├ tsconfig.json
 ├ .env
 â”” README.md
2. Prisma Database Models

prisma/schema.prisma

generator client {
 provider = "prisma-client-js"
}

datasource db {
 provider = "postgresql"
 url      = env("DATABASE_URL")
}

model User {
 id        String   @id @default(uuid())
 email     String   @unique
 password  String
 name      String?
 createdAt DateTime @default(now())
 deleted   Boolean  @default(false)
 orders    Order[]
}

model Category {
 id        String   @id @default(uuid())
 name      String
 products  Product[]
 deleted   Boolean  @default(false)
}

model Product {
 id          String   @id @default(uuid())
 name        String
 price       Float
 categoryId  String
 category    Category @relation(fields:[categoryId], references:[id])
 deleted     Boolean  @default(false)
}

model Order {
 id        String   @id @default(uuid())
 userId    String
 user      User     @relation(fields:[userId], references:[id])
 total     Float
 createdAt DateTime @default(now())
 deleted   Boolean  @default(false)
}
3. Express App

src/app.ts

import express from "express";
import authRoutes from "./routes/auth.routes";
import productRoutes from "./routes/product.routes";
import errorHandler from "./middleware/error.middleware";

const app = express();
app.use(express.json());

app.use("/auth", authRoutes);
app.use("/products", productRoutes);

app.use(errorHandler);
export default app;

src/server.ts

import app from "./app";

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running ${PORT}`));

...

11. README (Setup)
Install
npm install
Setup Prisma
npx prisma migrate dev
npx prisma generate
Run Dev Server
npm run dev
API Example
POST /auth/register
POST /auth/login
GET /products?page=1
POST /products
PUT /products/:id
DELETE /products/:id

This architecture supports scalable REST APIs, JWT security, Prisma ORM, soft deletes, pagination, and centralized error handling suitable for production-ready e-commerce backends.

Reviews (0)

Please login to leave a review.
Loading reviews...