π GitHub: https://github.com/4xush/wechat-ai
Full-stack AI chat application with JWT authentication, Google OAuth, multi-workspace organization, and real-time SSE streaming for AI responses.
- π Authentication - Memory-only tokens + HTTP-only cookies for XSS protection + Google OAuth
- π’ Multi-Workspace - Organize chats into separate workspaces
- π¬ Real-Time Chat - Token-by-token streaming AI responses
- π Web Search - AI agent with Tavily web search tool
- πΎ Persistent Memory - Full conversation history across sessions
- π¨ Modern UI - Premium dark theme with Framer Motion animations
- π‘οΈ Production-Ready - Helmet security, rate limiting, input sanitization, XSS protection
- π³ Docker Ready - Docker Compose for easy deployment
welaunch/
βββ backend/ # Node.js + Express + TypeScript API
β βββ src/
β β βββ controllers/ # HTTP request handlers
β β βββ services/ # Business logic & AI agents
β β βββ routes/ # API route definitions
β β βββ middleware/ # Auth, validation, rate limiting
β β βββ db/models/ # MongoDB schemas
β β βββ config/ # Environment & API config
β βββ package.json
β
βββ frontend/ # Next.js 15 + TypeScript + Tailwind
βββ app/ # Next.js pages (App Router)
β βββ chat/ # Main chat interface
β βββ login/ # Authentication pages
β βββ signup/
βββ components/ # React components
β βββ chat/ # Chat UI components
β βββ workspace/ # Workspace selector
β βββ layout/ # Sidebar & layout
β βββ ui/ # shadcn/ui components
βββ lib/
β βββ api/ # API client with auto-refresh
β βββ stores/ # Zustand state management
βββ types/ # TypeScript interfaces
Production-grade REST API with:
- Auth: JWT + bcrypt + Google OAuth (Passport.js)
- Database: MongoDB with Mongoose ODM
- AI Integration: OpenRouter + LangChain agents
- Tool Calling: Web search via Tavily API
- Streaming: Server-Sent Events (SSE) for real-time responses
- Security: Helmet headers, rate limiting, CORS, input sanitization (10k char limit), Zod validation, bcrypt hashing
- Architecture: Controllers β Services β Models pattern
See backend/README.md for API documentation.
Modern Next.js application with:
- Framework: Next.js 15 with App Router
- Styling: Tailwind CSS with custom premium dark theme
- UI: shadcn/ui components + Framer Motion animations
- State: Zustand for auth, workspace, and chat management
- Streaming: EventSource API for SSE token-by-token display
- Notifications: Sonner toast for real-time feedback (success, errors, rate limits)
- TypeScript: Full type safety throughout
- UX: Smooth animations, mobile-responsive, loading states, error handling
See frontend/README.md for setup guide.
- Node.js 18+
- MongoDB database
git clone https://github.com/4xush/wechat-ai.git
cd wechat-aicd backend
npm install
cp .env.example .env
# Edit .env with your API keys
npm run devBackend runs on http://localhost:3000
cd ../frontend
npm install
npm run devFrontend runs on http://localhost:5173
Backend: Copy .env.example to .env and configure. See backend/README.md for full details.
Required keys:
MONGODB_URI- MongoDB connection stringOPENROUTER_API_KEY- OpenRouter API keyWEB_SEARCH_API_KEY- Tavily API keyACCESS_TOKEN_SECRET/REFRESH_TOKEN_SECRET- JWT secrets (min 32 chars)
Frontend (.env.local):
NEXT_PUBLIC_API_URL=http://localhost:3000/api
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your_google_client_id # OptionalGenerate secure JWT secrets:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"- Runtime: Node.js 18+
- Framework: Express
- Language: TypeScript
- Database: MongoDB + Mongoose
- AI: OpenRouter API, LangChain, Tavily
- Auth: JWT + bcrypt + Passport.js (Google OAuth)
- Validation: Zod
- Security: Helmet, express-rate-limit, CORS, input sanitization
- Framework: Next.js 15 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- UI: shadcn/ui + Lucide icons + Framer Motion
- State: Zustand
- Streaming: EventSource (SSE)
- OAuth: Google Sign-In (@react-oauth/google)
POST /api/auth/signup- Create accountPOST /api/auth/login- LoginGET /api/auth/google- Google OAuth login (redirects)GET /api/auth/google/callback- Google OAuth callbackPOST /api/auth/refresh- Refresh access tokenPOST /api/auth/logout- LogoutGET /api/auth/config- Get OAuth client IDs
GET /api/workspaces- List workspacesPOST /api/workspaces- Create workspaceGET /api/workspaces/:id/chats- List chats
POST /api/workspaces/:wid/chats- Create chatPOST /api/workspaces/:wid/chats/:cid/messages- Send message (SSE stream)GET /api/workspaces/:wid/chats/:cid/messages- Get message history
- Production-Grade Auth: Access tokens in memory only, refresh tokens in HTTP-only cookies (prevents XSS)
- SSE Streaming: Real-time token-by-token AI responses
- Agent System: LangChain agents with tool calling
- Rate Limiting: Configurable per-endpoint protection
- Graceful Shutdown: Proper cleanup of connections
- Secure Auth: Access tokens stored in memory only (XSS-proof)
- Session Persistence: Refresh from HTTP-only cookie on page load
- Auto-Refresh: Automatic token refresh every 12 minutes
- Real-Time UI: Token-by-token message streaming
- Responsive Design: Mobile-friendly interface
- Error Handling: User-friendly error messages
# Backend
cd backend
npm run dev # Development with hot-reload
npm run build # TypeScript compilation
npm start # Production mode
# Frontend
cd frontend
npm run dev # Development server (port 5173)
npm run build # Production build
npm start # Production server
npm run lint # ESLint checkDocker Deploy:
# Clone repository
git clone https://github.com/4xush/wechat-ai.git
cd wechat-ai
# Copy and configure environment
cp .env.example .env
# Edit .env with your MongoDB URI and API keys
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
β οΈ Cross-Origin Cookie (Google OAuth): When deploying frontend and backend on different domains (e.g., Vercel + Render), Google OAuth sessions may not persist across page refresh due to browser third-party cookie restrictions. Email/password login works normally. For full OAuth persistence, deploy both on the same domain or use a custom domain.
β οΈ These features are currently delayed and will be implemented in future releases.
- Message Encryption β End-to-end encryption for chat messages
- Redis Caching β Cache chat history for faster retrieval
- Thinking Indicator β Visual indicator when AI is processing
- Web Search Indicator β Show when AI is searching the web for information