PersonaAI is a full-stack AI chat application where users can sign in with Google, choose a mentor persona, and chat with AI versions of Hitesh Choudhary or Piyush Garg. The frontend is built with Next.js, React, Tailwind CSS, and reusable UI components. The backend is an Express + TypeScript API that handles authentication, chat sessions, messages, MongoDB persistence, and OpenAI-powered persona responses.
- Frontend: Next.js, React, TypeScript, Tailwind CSS, lucide-react, shadcn-style UI components
- Backend: Node.js, Express, TypeScript, MongoDB, Mongoose
- Authentication: Google OAuth, JWT access tokens, JWT refresh tokens, HTTP-only cookies
- AI: OpenAI chat completions with custom system prompts for each persona
PersonaAI/
|-- README.md
|-- frontend/
| +-- public/
| | +-- home.webp
| | +-- Database.jpeg
| +-- src/
| | +-- app/
| | | +-- page.tsx
| | | +-- login/page.tsx
| | | +-- dashboard/page.tsx
| | | +-- chat/[persona]/page.tsx
| | +-- components/
| | | +-- ui/
| | | +-- cartoon/
| | | +-- ProtectedRoute.tsx
| | | +-- personaSelection.tsx
| | | +-- chatsList.tsx
| | | +-- chatInterface.tsx
| | +-- context/
| | +-- lib/
| | +-- types/
| +-- package.json
`-- backend/
+-- src/
| +-- controllers/
| +-- db/
| +-- middleware/
| +-- models/
| +-- routes/
| +-- utils/
| +-- app.ts
| +-- index.ts
+-- package.json
frontend/src/app/page.tsxis the landing page for PersonaAI.frontend/src/app/login/page.tsxcontains the login screen and starts the Google OAuth flow.frontend/src/app/dashboard/page.tsxis a protected dashboard where users choose a persona.frontend/src/app/chat/[persona]/page.tsxrenders the chat page for the selected persona.frontend/src/components/personaSelection.tsxshows the Hitesh and Piyush persona cards.frontend/src/components/chatInterface.tsxmanages the active conversation UI.frontend/src/components/chatsList.tsxdisplays existing chat sessions.frontend/src/components/ProtectedRoute.tsxblocks private pages until the user is authenticated.frontend/src/context/AuthContext.tsxstores user session state and exposes login/logout helpers.frontend/src/lib/api.tswraps API calls and automatically refreshes tokens after a401.frontend/src/lib/auth.ts,chat.ts, andmessage.tscontain frontend API helpers.frontend/public/stores static assets, including the project preview and ER diagram.
backend/src/index.tsstarts the server and connects to MongoDB.backend/src/app.tsconfigures Express, CORS, cookies, JSON parsing, and API routes.backend/src/db/index.tsconnects Mongoose toMONGODB_URI.backend/src/routes/defines API endpoints for auth, health checks, chats, and messages.backend/src/controllers/contains the request handlers for each route group.backend/src/models/defines MongoDB collections for users, chats, and messages.backend/src/middleware/auth.middlewares.tsverifies logged-in users from auth cookies.backend/src/utils/ai.tscontains the OpenAI client and persona prompts.backend/src/utils/api-response.tsandapi-error.tsstandardize API responses.
Stores Google-authenticated users.
nameemailavatar.urlaccessTokenrefreshTokencreatedAtupdatedAt
Stores one conversation session for a user and persona.
userIdreferencesUserpersonacan behiteshorpiyushtitlecreatedAtupdatedAt
Stores messages inside a chat.
chatIdreferencesChatrolecan beuserorassistantcontentcreatedAtupdatedAt
Base API path:
http://localhost:8000/api/v1
GET /auth/googleredirects the user to Google OAuth.GET /auth/google/callbackhandles the OAuth callback, creates or finds the user, sets cookies, and redirects to the dashboard.GET /auth/refreshTokenrefreshes auth cookies.GET /auth/getmereturns the logged-in user.GET /auth/logoutclears auth cookies.
GET /chats/:personareturns the latest chats for a persona.POST /chatscreates a new chat.DELETE /chats/:iddeletes a chat.
GET /messages/:chatIdreturns messages for a chat.POST /messages/:chatIdsends a user message, calls the selected persona, and stores both user and assistant messages.
GET /healthcheckverifies that the backend is running.
Create a .env file inside backend/:
PORT=8000
MONGODB_URI=your_mongodb_connection_string
CORS_ORIGIN=http://localhost:3000
FRONTEND_URL=http://localhost:3000
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URI=http://localhost:8000/api/v1/auth/google/callback
ACCESS_TOKEN_SECRET=your_access_token_secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=your_refresh_token_secret
REFRESH_TOKEN_EXPIRY=15m
OPENAI_API_KEY=your_openai_api_keyCreate a .env.local file inside frontend/:
NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1Install and start the backend:
cd backend
npm install
npm startInstall and start the frontend:
cd frontend
npm install
npm run devThen open:
http://localhost:3000
- The user opens the landing page.
- The user signs in with Google OAuth.
- The backend verifies Google identity, creates or finds the user, and stores JWT cookies.
- The user lands on the dashboard and chooses a persona.
- The frontend creates or loads chat sessions for that persona.
- When the user sends a message, the backend loads recent message history and calls the correct persona helper.
- User and assistant messages are saved in MongoDB and shown in the chat UI.

