1. Introduction#
Building a full-stack application used to take weeks of coding. Today, with AI tools like ChatGPT, you can build and deploy a complete application in hours - for free.
This tutorial will show you how to:
- Generate a complete REST API using AI prompts
- Set up a free database (TiDB Serverless)
- Deploy your API to Vercel (free)
- Generate a frontend using the API spec
- Deploy the frontend to Vercel (free)
Total cost: $0
What we’ll build: An E-Commerce API with:
- Customers (name, email)
- Products (name, price, stock)
- Orders (with transaction support)
2. Prerequisites#
Before starting, create these free accounts:
- GitHub ↗ - for code hosting
- Vercel ↗ - for deployment
- TiDB Cloud ↗ - for free database
- ChatGPT ↗ - for AI code generation
Tools you’ll need:
- Node.js installed on your computer
- A code editor (VS Code recommended)
- Terminal/Command Prompt
3. Part 1: Generate Backend API with AI#
Step 1: Create Your Project Folder#
Open your terminal and run:
mkdir ecommerce-api
cd ecommerce-api
npm init -ybashStep 2: The AI Prompt for Backend#
Open ChatGPT ↗ and use this exact prompt:
Create a RESTful API for an e-commerce system using Express.js and mysql2 (no ORM).
Project structure:
ecommerce-api/
├── db.js
├── index.js
├── schema.sql
├── seed.sql
├── .env
└── routes/
├── customers.js
├── products.js
└── orders.js
Database: TiDB
Database name: ecommerce
Tables:
- customers (id, name, email, created_at)
- products (id, name, price, stock, created_at)
- orders (id, customer_id, total, status, created_at)
- order_items (id, order_id, product_id, quantity, price)
Required endpoints for each resource (customers, products, orders):
- GET all - returns array
- GET by id - returns single item or 404
- POST - create new item
- DELETE by id - delete item
For POST /api/orders:
- Use database transactions
- Validate stock before creating order
- Decrease stock when order is placed
- Rollback on any error
Requirements:
- Default port: 3333 (for local development)
- Use parameterized queries (security)
- Return JSON only
- Proper HTTP status codes (200, 201, 404, 500)
- Enable CORS for all origins
- Include error handling
- Export app for Vercel deployment (serverless function)
- Start server only when not in production (NODE_ENV !== 'production')
- .env include DB_SSL
Generate complete code for each file in the exact structure above.
Also provide:
1. npm install command
2. .env file template with database variables
3. Testing commands using curlbashStep 3: Copy the Generated Code#
ChatGPT will generate all the code files. Create each file in your project and copy the code:
ecommerce-api/
├── db.js
├── index.js
├── schema.sql
├── seed.sql
├── .env
├── package.json
└── routes/
├── customers.js
├── products.js
└── orders.jsbashStep 4: Install Dependencies#
npm install express mysql2 cors dotenvbash4. Part 2: Set Up Free Database (TiDB)#
Step 1: Create TiDB Serverless Cluster#
- Go to tidbcloud.com ↗ and sign up
- Click Create Cluster → TiDB Serverless
- Choose a region near you
- Wait for cluster to create (1-2 minutes)
Step 2: Create Database#
- In TiDB Cloud, click SQL Editor or Chat to TiDB
- Run:
CREATE DATABASE ecommerce;
Step 3: Get Connection Details#
- Click Connect on your cluster
- Choose General connection
- Create a password
- Copy the connection string
Update your .env file with TiDB credentials:
DB_HOST=your-tidb-host.gateway.prod.aws.tidbcloud.com
DB_PORT=4000
DB_USERNAME=xxx.root
DB_PASSWORD=your-password
DB_DATABASE=ecommerce
DB_SSL=truebashStep 4: Run Schema and Seed#
- In TiDB Cloud SQL Editor, paste the contents of
schema.sql - Click Run
- Then paste and run
seed.sql
5. Part 3: Test Your API Locally#
Start the Server#
node --watch index.jsbashYou should see: Server running on port 3333
Test with curl (or Postman)#
# Get all customers
curl http://localhost:3333/api/customers
# Create a customer
curl -X POST http://localhost:3333/api/customers \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com"}'
# Get all products
curl http://localhost:3333/api/products
# Create an order
curl -X POST http://localhost:3333/api/orders \
-H "Content-Type: application/json" \
-d '{"customer_id":1,"items":[{"product_id":1,"quantity":2}]}'bashGenerate Postman Collection (Optional)#
For easier testing, ask ChatGPT to generate a Postman collection:
Generate a Postman collection JSON file for my e-commerce API.
Base URL: http://localhost:3333
Create a complete Postman collection export JSON that I can import.bash- Copy the generated JSON
- Save as
ecommerce-api.postman_collection.json - Open Postman → Import → Upload the file
- You’ll have all API requests ready to test with one click
6. Part 4: Deploy API to Vercel#
Create .gitignore#
node_modules
.envbashPush to GitHub using VS Code#
Initialize git and push to GitHub using VS Code:
- Open your project in VS Code
- Click the Source Control icon (or press
Ctrl+Shift+G) - Click Initialize Repository
- Click the + icon next to “Changes” to stage all changes
- Enter a commit message:
Initial commit - E-commerce API - Click Commit
- Click the Publish Branch button
- Follow the prompts to create a new GitHub repository (make it Public)
Your code is now on GitHub at: https://github.com/YOUR_USERNAME/ecommerce-api
Deploy on Vercel#
- Go to vercel.com ↗
- Click Add New → Project
- Import your GitHub repository
- Click Environment Variables
- Add all variables from your
.envfile:- DB_HOST
- DB_PORT
- DB_USERNAME
- DB_PASSWORD
- DB_DATABASE
- DB_SSL
- Click Deploy
Your API is now live at: https://your-project.vercel.app
Test it: https://your-project.vercel.app/api/customers
7. Part 5: Generate API Reference#
Before generating the frontend, we need a complete API specification. Let AI generate it from your code!
The API Reference Prompt#
Open ChatGPT and paste this prompt along with your route files:
Generate a complete API reference documentation for my e-commerce API.
Here are my route files:
=== File: index.js ===
[PASTE CONTENTS of index.js]
=== File: routes/customers.js ===
[PASTE CONTENTS of routes/customers.js]
=== File: routes/products.js ===
[PASTE CONTENTS of routes/products.js]
=== File: routes/orders.js ===
[PASTE CONTENTS of routes/orders.js]
Generate documentation in **markdown format** with:
- Base URL: [Vercel Based URL, for example: https://your-project.vercel.app]
- Each endpoint grouped by resource (CUSTOMERS, PRODUCTS, ORDERS)
- For each endpoint include:
- HTTP method and path (e.g., GET /api/customers)
- Description
- Request body (if POST/PUT)
- Response format with actual example data
- HTTP status codes
Make it easy to copy-paste for frontend development.bashSave Your API Reference#
ChatGPT will output a clean API reference. Save this - you’ll need it for the frontend prompt.
It should look something like this (your actual endpoints may vary):
Base URL: https://your-project.vercel.app
=== CUSTOMERS ===
GET /api/customers
Description: Get all customers
Response: [{"id":1,"name":"Karn Yong","email":"karn@example.com","created_at":"..."}]
...bash8. Part 6: Generate Frontend with AI#
Now that your API is deployed, let’s generate a Next.js frontend.
The AI Prompt for Frontend#
Open a new ChatGPT conversation and use this prompt:
Create a Next.js 15 frontend for an e-commerce system using App Router.
Use these API endpoints:
[PASTE CONTENTS of API Reference]
Requirements:
- Use Tailwind CSS for styling (shadcn/ui components preferred)
- Create pages: Customers, Products, Orders, Create Order
- Display data in tables
- Simple forms to add data
- Show loading states and error messages
- Use fetch for API calls
- Keep it simple and clean
File structure:
- app/page.js - home/dashboard
- app/customers/page.js
- app/products/page.js
- app/orders/page.js
- app/layout.js - with navigation
- components/ - reusable components
- lib/api.js - API functions
Provide complete code for all files.bashCreate the Frontend Project#
npx create-next-app@15 ecommerce-frontend --tailwind --appbashWhen prompted, choose No for TypeScript.
cd ecommerce-frontend
npm installbashCopy the generated code from ChatGPT into your project.
Update API URL#
Make sure to replace https://your-project.vercel.app with your actual deployed API URL in lib/api.js.
Test Frontend Locally#
Before deploying, test your frontend locally:
npm run devbash- Open http://localhost:3000 ↗ in your browser
- Test all pages: Customers, Products, Orders
- Try creating new data
- Verify API calls work correctly
If everything works, you’re ready to deploy!
Press Ctrl+C to stop the dev server when done testing.
9. Part 7: Deploy Frontend to Vercel#
Push Frontend to GitHub using VS Code#
- Create a new repository on GitHub (make it Public)
- Open
ecommerce-frontendin VS Code - Click the Source Control icon (or press
Ctrl+Shift+G) - Click Initialize Repository
- Stage all changes (click the
+icon) - Enter commit message:
Initial commit - E-commerce frontend - Click Commit
- Click Publish Branch
- Follow the prompts to publish to GitHub
Deploy on Vercel#
- Go to Vercel → Add New → Project
- Import
ecommerce-frontendrepository - Click Deploy (no environment variables needed)
Your frontend is now live at: https://your-frontend-project.vercel.app
10. Summary#
What you’ve built for $0:
| Component | Technology | Cost |
|---|---|---|
| API | Express.js + mysql2 | Free |
| Database | TiDB Serverless | Free (5GB) |
| Backend Hosting | Vercel | Free (100GB bandwidth) |
| Frontend | Next.js 15 | Free |
| Frontend Hosting | Vercel | Free (100GB bandwidth) |
Next Steps:
- Add authentication with JWT
- Implement pagination
- Add search and filtering
- Set up custom domain
- Add payment processing
Tips for Better AI Prompts:
- Be specific about your tech stack
- Include sample request/response formats
- Mention security requirements
- Ask for error handling
- Request the complete file structure
The key to building with AI is providing clear specifications. The more detailed your prompt, the better the generated code.
Happy building!