A polished, self-hostable chat application that uses Mistral AI models to power responses. It includes Google authentication, per-user threads, server-issued access tokens stored as secure HTTP-only cookies, and a minimal admin/persistence layer using Prisma + MySQL.
- Overview
- Introduction
- Demo & User Guide
- Prerequisites
- Installation & Setup
- Project Structure
- API Reference
- Authentication Flow
- Roadmap
- Documentation / Help Center
- Contributing
- Acknowledgements
- Contact
- License
Project name: MistralChat — Open Assistant (Unofficial)
This repository is a demonstration chat application built on top of Mistral AI (community SDK). It is aimed at developers who want a self-hosted, extensible chat UI that supports:
- Google OAuth sign-in
- Server-issued access tokens (stored in a database)
- Threaded conversations saved per user
- Integration with Mistral AI models (via
@mistralai/mistralai) - Prisma for data persistence
MistralChat is a lightweight chat UI and backend stack that demonstrates how to implement authentication, data persistence, and model-powered chat responses. The app is ideal for prototyping, internal tools, and experimenting with LLMs.
Target audience: Anyone who already uses LLMs or wants to experiment with them.
Quick demo (server):
- Visit
https://chatbot.infuseting.frand sign in with Google. - Get your API key from Mistral.
- Create or open threads, send messages, and view model responses.
Tip: Use the Share feature to open a shared thread URL.
Model Configuration Page
Here you can set your API key,
choose models from a fast list, and define a default model for all threads.

Fast Config
Quickly modify the context and model for the current thread.

Voice call
Use you're voice to talk with AI.

Image Generation
Generate image from text or other image

- Node.js (v18+ recommended)
- npm (or pnpm/yarn)
- A database supported by Prisma (MySQL recommended)
- Google OAuth credentials (Client ID) configured for
http://localhost:3000redirect - A Mistral API key
- Clone the repository:
git clone https://github.com/Infuseting/ChatBOT_MistralAI.git
cd ChatBOT_MistralAI- Install dependencies:
npm install- Create a
.envfile in the project root with the following variables:
DATABASE_URL="mysql://<username>:<password>@<url>:<port>/chatbot"
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your-google-client-id
TTS_API_KEY=your-tts-api-key
NODE_ENV=developmentTo get a valid api key for my TTS api you can contact me or just test by yourself with the official website (TTS key is required to use the voice chat and video chat but you can use this program without having TTS API KEY)
- Prisma setup (run migrations):
npx prisma generate
npx prisma migrate dev- Start the development server:
npm run dev- Open
http://localhost:3000and sign in.
Top-level structure:
src/
app/
api/ # Next.js API routes (auth, user, thread, validate)
components/ # React components (Chatbot, Navbar, Modals...)
login/ # Login page
layout.tsx # App root layout
lib/
prisma.ts # Prisma client
utils/ # Helpers (User, Thread, Messages...)
middleware.ts # Auth middleware for validating tokens
The project exposes a set of Next.js API routes under src/app/api. Below are the main endpoints and a short description of their behavior. All server-side tokens used by these routes are stored in the database and may be supplied either via the Authorization: Bearer <token> header or the access_token httpOnly cookie.
-
POST /api/auth/google/token— Exchange a Google OAuthaccess_token(obtained on the client) for a server-side access token. Verifies Google tokeninfo, upserts the user bygoogleId, and sets a secure, httpOnlyaccess_tokencookie on success. -
POST /api/auth/logout— Logs out the current user: deletes the server-side token(s) matching the provided token and clears theaccess_tokencookie. -
DELETE /api/auth/delete— Permanently deletes the authenticated user's account and related data (messages, threads, shares, tokens). Requires authentication. -
POST /api/auth/email/login— Email/password login. Accepts{ email, password }JSON body. On success returns{ ok: true }and sets anaccess_tokencookie. -
POST /api/auth/email/register— Email/password registration. Accepts{ email, password, name? }. Creates a user (provider = 'MDP'), issues anaccess_tokencookie on success. -
GET /api/auth/validate— Validates the provided server-side token and returns{ ok: true }when valid. Useful for middleware and client-side checks. -
GET /api/user— Returns basic profile information for the authenticated user (id, name, picture). Requires a valid server token. -
GET /api/thread— Multi-purpose GET that supports:?shareCode=CODE— Return a publicly-shared thread by share code (no auth required).?idThread=ID— Return a specific thread and its messages if the requester is the owner (requires auth). Supportslimitandbeforefor paginated message loading.- no query params — List threads for the authenticated user (supports
limitandbefore).
-
POST /api/thread— Multi-action endpoint. The request JSON should include anactionfield with one of the following values:create— Create a new thread. Body:{ action: 'create', data: { ... } }. Requires auth.share— Create or fetch a share code for an owned thread. Body:{ action: 'share', idThread }. Requires auth and ownership.sync— Bulk-insert/sync messages for existing threads (used for imports/sync). Body:{ action: 'sync', messages: [...] }. Only inserts messages that target known threads and are permitted (owner or shared).update— Update thread metadata (name, context, model). Body:{ action: 'update', idThread, data: { ... } }. Requires auth and ownership.
-
POST /api/tts— Server-side TTS proxy. Supports two actions in the body:{ validate: true }— Validates the server TTS API key with the provider.{ text: string, lang?: string }— Generates audio (mp3) via the configured provider and returns audio bytes (Content-Type: audio/mpeg). Uses the server's configured TTS API key.
Notes:
- Many endpoints accept the server-side token via
Authorization: Bearer <token>or theaccess_tokencookie. The cookie is httpOnly and set on successful login/registration. - Error responses follow a JSON shape like
{ error: 'Message' }and appropriate HTTP status codes (401 for auth failures, 400 for bad requests, 500 for server errors).
There are two primary sign-in flows supported by the app: Google OAuth and traditional email/password. Both flows result in a server-side access token which is persisted in the database and returned to the client as a secure, httpOnly cookie (access_token). API routes and middleware validate requests using this server-side token.
Google OAuth:
- The client obtains a Google OAuth
access_tokenon the client (via Google Sign-In). - The client POSTs
{ access_token }to/api/auth/google/token. - The server verifies the token with Google's tokeninfo endpoint, upserts the user by
googleId, creates a local server-side access token in the DB, and sets an httpOnlyaccess_tokencookie on success.
Email/password:
- The client POSTs
{ email, password }to/api/auth/email/loginto sign in. If successful, the server creates a server-side access token and sets theaccess_tokencookie. - New users can register via
POST /api/auth/email/registerwith{ email, password, name? }, which creates the user and issues the cookie.
Logout / token management:
POST /api/auth/logoutdeletes server-side token(s) that match the supplied token and clears the cookie.DELETE /api/auth/deleteperforms a destructive deletion of the authenticated user's account and related data (requires authentication).
Token usage:
- API routes accept the server token either as
Authorization: Bearer <token>or via theaccess_tokenhttpOnly cookie. The cookie is preferred in browser flows to avoid exposing tokens to JS.
Security Notes:
- Access tokens are stored server-side and sent as httpOnly cookies to reduce XSS risk.
- The server-side tokens are short-lived by design (if
expiresAtis set) and validated against the DB byGET /api/auth/validate. - For very large deployments, consider switching to signed JWTs or an introspection-capable auth layer to avoid DB lookups in hot paths.
| Feature | Smartphone | Tablet | Computer |
|---|---|---|---|
| Remote Storage | ✅ | ✅ | ✅ |
| Thread Management | ✅ | ✅ | ✅ |
| Responsive Design | ✅ | ✅ | ✅ |
| Model & Context Configurator | ✅ | ✅ | ✅ |
| Google OAuth Login | ✅ | ✅ | ✅ |
| Deep Think Integration | ✅ | ✅ | ✅ |
| Edit & Regenerate Requests | ✅ | ✅ | ✅ |
| Email Login | ✅ | ✅ | ✅ |
| Model Features Viewer | ✅ | ✅ | ✅ |
| File Input | ✅ | ✅ | ✅ |
| Image OCR | ✅ | ✅ | ✅ |
| Audio Call | ✅ | ✅ | ✅ |
| Image Generation | ✅ | ✅ | ✅ |
| Video Call | ❌ | ❌ | ❌ |
| Access without login | ✅ | ✅ | ✅ |
| Subthread | ❌ | ❌ | ❌ |
| Web Search | ✅ | ✅ | ✅ |
| Keybinds | ✅ | ✅ | ✅ |
| Comments & Docs | ✅ | ✅ | ✅ |
| Project Classification | ❌ | ❌ | ❌ |
| Lazy load | ✅ | ✅ | ✅ |
The codebase is fully documented.
If you encounter issues, please open an issue directly on GitHub.
This project was created to demonstrate my skills to potential employers.
As such, direct contributions will not be accepted, except through suggestions.
However, feel free to fork the project — I would love to see what you build with it!
Contributors:
- @Infuseting (Owner)
- Mistral AI and community SDKs
- My friend who inspired this project
For collaboration or to report issues, open a GitHub issue or email me at: serretarthur@gmail.com
This project is licensed under the MIT License.
