An interactive AI-powered English learning platform built with Next.js, TypeScript, Prisma, and OpenAI. AI Tutor provides personalized English tutoring through an intelligent chat interface.
The application uses two main models:
User Model
model User {
id Int @id @default(autoincrement())
name String
email String @unique
password String
goal String? # Learning goal
level String? # Proficiency level
createdAt DateTime @default(now())
conversations Conversation[]
}Conversation Model
model Conversation {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
messages Json # Stores chat history
createdAt DateTime @default(now())
}Register a new user account.
Request Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}Response (201):
{
"code": 201,
"message": "Successfully registered new account!"
}Validation:
- Name: Required, max 100 characters
- Email: Valid email format required
- Password: Minimum 6 characters
Authenticate an existing user.
Request Body:
{
"email": "john@example.com",
"password": "password123"
}Response (200):
{
"code": 200,
"message": "Successfully Logged in",
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Error Response (401):
{
"code": 401,
"error": "Invalid email or password!"
}Retrieve conversation history for the authenticated user.
Headers:
x-user-id: {userId}
Response (200):
{
"code": 200,
"data": {
"id": 1,
"userId": 1,
"messages": [
{
"role": "ai",
"content": "Hi John! Welcome to JaPi. What's your English learning goal?",
"date": "2025-10-30T10:00:00.000Z"
}
],
"createdAt": "2025-10-30T09:00:00.000Z"
}
}Send a message and receive AI response.
Headers:
x-user-id: {userId}
Request Body:
{
"message": "I want to improve my business English"
}Response (200):
{
"code": 200,
"data": {
"reply": "Great! Business English is very useful. What's your current level?",
"goal": "improve business English",
"level": ""
}
}AI Onboarding Flow:
-
Step 1/2: Extract user's learning goal
- AI asks: "What's your English learning goal?"
- Stores goal, then asks about proficiency level
-
Step 2/2: Extract proficiency level
- AI asks: "What's your English level? (beginner/intermediate/advanced)"
- Stores level, then starts first lesson
-
Active Learning: Once profile complete, provides personalized tutoring
- Signup/Login: User provides credentials
- Token Generation: Server creates JWT with user ID and email
- Token Storage: Client stores token in cookies
- Protected Routes: Middleware validates token
- User Identification: Token payload extracted for API calls
# Development server
npm run dev
# Production build
npm run build
# Start production server
npm run start
# Lint code
npm run lint- ESLint: Code linting with Next.js config
- TypeScript: Strict type checking
- Zod: Runtime validation for API inputs
Ensure all environment variables are configured in your deployment platform:
DATABASE_URLJWT_SECRETOPENAI_API_KEYNEXT_PUBLIC_BASE_URL
Built with ❤️