Chat
Chat
StableAI chat application supporting multiple language models including local (Ollama) and cloud providers (OpenRouter).
Overview
| Component | Technology | Port |
|---|---|---|
| Backend | NestJS | 3002 |
| Web | SvelteKit | 5173 |
| Mobile | Expo | - |
| Landing | Astro | - |
Quick Start
# Start everything (auth + database + backend + web)pnpm dev:chat:full
# Or individual componentspnpm dev:chat:backendpnpm dev:chat:webpnpm dev:chat:mobileArchitecture
┌─────────────┐ ┌─────────────┐ ┌─────────────┐│ Client │────>│ Backend │────>│ AI Models ││ (Web/Mobile)│ │ (NestJS) │ │ Ollama/API │└─────────────┘ └──────┬──────┘ └─────────────┘ │ ▼ ┌─────────────┐ │ PostgreSQL │ └─────────────┘API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/api/v1/health | GET | Health check |
/api/v1/chat/models | GET | List available AI models |
/api/v1/chat/completions | POST | Create chat completion |
/api/v1/conversations | GET | List user conversations |
/api/v1/conversations/:id | GET | Get conversation details |
/api/v1/conversations/:id/messages | GET | Get conversation messages |
/api/v1/conversations | POST | Create new conversation |
/api/v1/conversations/:id/messages | POST | Add message to conversation |
AI Models
Local Models (Ollama - Free)
| Model | Best For |
|---|---|
| Gemma 3 4B | Everyday tasks (default) |
| Llama 3.2 | General conversation |
| Mistral | Code assistance |
Cloud Models (OpenRouter - Paid)
| Model | Price | Best For |
|---|---|---|
| Llama 3.1 8B | $0.05/M | Fast cloud alternative |
| Llama 3.1 70B | $0.35/M | Complex reasoning |
| DeepSeek V3 | $0.14/M | Reasoning at low cost |
| Claude 3.5 Sonnet | $3/M | Best quality |
| GPT-4o Mini | $0.15/M | Balanced performance |
Environment Variables
Backend
# AI ModelsOPENROUTER_API_KEY=sk-or-v1-xxxOLLAMA_URL=http://localhost:11434OLLAMA_TIMEOUT=120000
# DatabaseDATABASE_URL=postgresql://manacore:devpassword@localhost:5432/chat
# AuthMANA_CORE_AUTH_URL=http://localhost:3001
# ServerPORT=3002Web
PUBLIC_MANA_CORE_AUTH_URL=http://localhost:3001PUBLIC_BACKEND_URL=http://localhost:3002Database Schema
// Conversationsexport const conversations = pgTable('conversations', { id: uuid('id').primaryKey().defaultRandom(), userId: uuid('user_id').notNull(), title: varchar('title', { length: 255 }), modelId: varchar('model_id', { length: 100 }), createdAt: timestamp('created_at').defaultNow(), updatedAt: timestamp('updated_at').defaultNow(),});
// Messagesexport const messages = pgTable('messages', { id: uuid('id').primaryKey().defaultRandom(), conversationId: uuid('conversation_id') .notNull() .references(() => conversations.id, { onDelete: 'cascade' }), role: varchar('role', { length: 20 }).notNull(), // 'user' | 'assistant' content: text('content').notNull(), createdAt: timestamp('created_at').defaultNow(),});Features
- Multi-model support - Switch between local and cloud models
- Conversation history - Persistent chat history
- Streaming responses - Real-time AI responses
- Code highlighting - Syntax highlighting in responses
- Markdown rendering - Rich text formatting
- Mobile app - Native iOS and Android app
Development
Seed Database
First time setup requires seeding AI models:
pnpm --filter @chat/backend db:pushpnpm --filter @chat/backend db:seedRun Tests
pnpm --filter @chat/backend testpnpm --filter @chat/backend test:e2eOpen Database GUI
pnpm --filter @chat/backend db:studioLinks
- Web App: http://localhost:5173
- API: http://localhost:3002
- Drizzle Studio: http://localhost:4983