A modern, full-stack chat application powered by LangChain and Mistral AI with a beautiful, responsive frontend and a modular backend API.
langchain-chat/
├── backend/ # Node.js/Express Backend
│ ├── server.js # Express server entry point
│ ├── routes.js # API route handlers
│ ├── logger.js # Logging system
│ ├── package.json # Backend dependencies
│ └── README.md # Backend documentation
│
├── frontend/ # React/Vanilla JS Frontend
│ ├── index.html # Main HTML template
│ ├── css/
│ │ └── styles.css # Application styles
│ ├── js/
│ │ ├── app.js # Application logic
│ │ ├── api.js # API communication
│ │ └── ui.js # UI utilities
│ └── README.md # Frontend documentation
│
├── logs/ # Auto-generated log files
│ └── chat.log # Chat history logs
│
├── .env # Environment variables
├── package.json # Root project config
└── README.md # This file
-
Backend
- Express.js server on port 3000
- LangChain + Mistral AI integration
- RESTful API endpoints
- Real-time logging system
- File-based log persistence
- CORS enabled
-
Frontend
- Beautiful gradient UI with purple theme
- Real-time chat messaging
- Backend logs panel
- Modular JavaScript (ES6 modules)
- Responsive design
- Loading animations
- Error handling
- Node.js 16+ and npm
- Mistral AI API key
- Clone or navigate to the project:
cd langchain-chat- Set up environment variables:
cp .env.example .env
# Edit .env and add your MISTRAL_API_KEY- Install dependencies:
npm run setupStart the server (serves both backend API and frontend):
npm startThe application will be available at: http://localhost:3000
GET /chat?message=<user_message>
Send a message to the AI and receive a response.
Response:
{
"response": "AI's response text here"
}GET /logs
Retrieve all stored chat logs.
Response:
{
"logs": [
"[2026-02-08T20:30:45.123Z] [INFO] Server initialized",
"[2026-02-08T20:30:47.456Z] [SUCCESS] Chat response generated successfully"
]
}GET /health
Check if the server is running.
Response:
{
"status": "ok",
"message": "Server is running"
}index.html- Main templatecss/styles.css- All stylingjs/app.js- Application orchestrationjs/api.js- API communicationjs/ui.js- UI utilities
User Input
↓
app.js: sendMessage()
├─ api.js: sendChatMessage()
└─ ui.js: addMessage(), displayLogs()
Create a .env file in the root directory:
MISTRAL_API_KEY=your_api_key_here
PORT=3000
NODE_ENV=development
Edit backend/server.js to modify:
- Port (currently 3000)
- Frontend path
- CORS settings
- Middleware
Edit frontend/js/api.js to modify:
- API base URL
- Endpoints
- Log refresh interval
cd backend
npm install
npm startThe frontend is served automatically by the backend server. Edit files in frontend/ and refresh your browser.
Backend:
- Logging: backend/logger.js
- Routes: backend/routes.js
- Server: backend/server.js
Frontend:
- Application Logic: frontend/js/app.js
- API Communication: frontend/js/api.js
- UI Utilities: frontend/js/ui.js
- Styles: frontend/css/styles.css
- HTML: frontend/index.html
- Install dependencies in the root:
npm run setup- Set environment variables:
export MISTRAL_API_KEY=your_production_key
export NODE_ENV=production- Start the server:
npm startThe server will serve both the API and static frontend assets.
Create a Dockerfile in the backend directory and build your own container.
- Check if port 3000 is already in use
- Verify Node.js version:
node --version(should be 16+) - Check for errors in the terminal
- Verify the server is running:
http://localhost:3000/health - Check browser console (F12) for CORS errors
- Ensure
API_CONFIG.BASE_URLinfrontend/js/api.jsis correct
- Verify API key in
.envfile - Check Mistral API status and rate limits
- Review error logs in the logs panel
- Check
/logsendpoint:http://localhost:3000/logs - Verify
logs/directory exists - Check file permissions
- Logs are limited to 500 entries (configurable in
backend/logger.js) - Log refresh interval: 500ms (configurable in
frontend/js/api.js) - CSS animations use GPU acceleration
- Efficient DOM manipulation
- Chrome/Chromium 90+
- Firefox 88+
- Safari 14+
- Edge 90+
Requires HTTP/HTTPS (file:// protocol not supported)
- Never commit
.envwith real API keys - Use environment variables for sensitive data
- CORS is currently open (adjust for production)
- Sanitize user input in production
MIT
For issues or questions, check:
- Browser console (F12)
- Backend logs in the logs panel
- Terminal output where the server is running
logs/chat.logfile
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Current Version: 1.0.0
Last Updated: 2026-02-08
Status: Production Ready ✅