Skip to content

Chat

Chat

Stable

AI chat application supporting multiple language models including local (Ollama) and cloud providers (OpenRouter).

Overview

ComponentTechnologyPort
BackendNestJS3002
WebSvelteKit5173
MobileExpo-
LandingAstro-

Quick Start

Terminal window
# Start everything (auth + database + backend + web)
pnpm dev:chat:full
# Or individual components
pnpm dev:chat:backend
pnpm dev:chat:web
pnpm dev:chat:mobile

Architecture

┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Client │────>│ Backend │────>│ AI Models │
│ (Web/Mobile)│ │ (NestJS) │ │ Ollama/API │
└─────────────┘ └──────┬──────┘ └─────────────┘
┌─────────────┐
│ PostgreSQL │
└─────────────┘

API Endpoints

EndpointMethodDescription
/api/v1/healthGETHealth check
/api/v1/chat/modelsGETList available AI models
/api/v1/chat/completionsPOSTCreate chat completion
/api/v1/conversationsGETList user conversations
/api/v1/conversations/:idGETGet conversation details
/api/v1/conversations/:id/messagesGETGet conversation messages
/api/v1/conversationsPOSTCreate new conversation
/api/v1/conversations/:id/messagesPOSTAdd message to conversation

AI Models

Local Models (Ollama - Free)

ModelBest For
Gemma 3 4BEveryday tasks (default)
Llama 3.2General conversation
MistralCode assistance

Cloud Models (OpenRouter - Paid)

ModelPriceBest For
Llama 3.1 8B$0.05/MFast cloud alternative
Llama 3.1 70B$0.35/MComplex reasoning
DeepSeek V3$0.14/MReasoning at low cost
Claude 3.5 Sonnet$3/MBest quality
GPT-4o Mini$0.15/MBalanced performance

Environment Variables

Backend

# AI Models
OPENROUTER_API_KEY=sk-or-v1-xxx
OLLAMA_URL=http://localhost:11434
OLLAMA_TIMEOUT=120000
# Database
DATABASE_URL=postgresql://manacore:devpassword@localhost:5432/chat
# Auth
MANA_CORE_AUTH_URL=http://localhost:3001
# Server
PORT=3002

Web

PUBLIC_MANA_CORE_AUTH_URL=http://localhost:3001
PUBLIC_BACKEND_URL=http://localhost:3002

Database Schema

// Conversations
export 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(),
});
// Messages
export 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:

Terminal window
pnpm --filter @chat/backend db:push
pnpm --filter @chat/backend db:seed

Run Tests

Terminal window
pnpm --filter @chat/backend test
pnpm --filter @chat/backend test:e2e

Open Database GUI

Terminal window
pnpm --filter @chat/backend db:studio