This project is now split into separate frontend and backend applications.
MiddlewareAssignment/
├── backend/ # Express.js API server
│ ├── lib/ # Backend utilities
│ ├── prisma/ # Database schema
│ ├── scripts/ # Utility scripts
│ └── server.js # Express server
├── src/ # React + Vite frontend
│ ├── pages/ # Page components
│ ├── components/ # UI components
│ └── config/ # Configuration
├── components/ # React components
└── package.json # Frontend dependencies
cd backend
npm installCreate backend/.env:
DATABASE_URL="postgresql://roopansh@localhost:5432/chatbot?schema=public"
OPENAI_API_KEY="your-openai-api-key"
JWT_SECRET="your-secret-key"
PORT=5000
FRONTEND_URL="http://localhost:3000"# Generate Prisma client
npm run db:generate
# Push schema to database
npm run db:push
# Start backend server
npm run devBackend will run on http://localhost:5000
# From project root
npm installCreate .env:
VITE_API_URL="http://localhost:5000"# Start frontend
npm run devFrontend will run on http://localhost:3000
Terminal 1 (Backend):
cd backend
npm run devTerminal 2 (Frontend):
npm run devAdd to root package.json:
{
"scripts": {
"dev:backend": "cd backend && npm run dev",
"dev:frontend": "vite",
"dev": "npm-run-all --parallel dev:backend dev:frontend"
},
"devDependencies": {
"npm-run-all": "^4.1.5"
}
}Then run: npm run dev
All backend endpoints are prefixed with /api:
POST /api/auth/register- Register new userPOST /api/auth/login- Login userPOST /api/chat- Send chat messageGET /api/messages- Get user messagesGET /api/health- Health check
DATABASE_URL- PostgreSQL connection stringOPENAI_API_KEY- OpenAI API keyJWT_SECRET- Secret for JWT tokensPORT- Backend server port (default: 5000)FRONTEND_URL- Frontend URL for CORS
VITE_API_URL- Backend API URL (default: http://localhost:5000)
- Backend:
http://localhost:5000 - Frontend:
http://localhost:3000 - Frontend calls backend API automatically
- Deploy to Railway, Render, or similar
- Set environment variables
- Database should be accessible
- Deploy to Vercel, Netlify, or similar
- Set
VITE_API_URLto your backend URL - Build:
npm run build