# Ollama Chat

A polished, ChatGPT-style web interface for your local Ollama runtime. Multi-user, streaming, model management, thinking display, and a warm claude.ai-inspired design.

![screenshot placeholder](docs/screenshot-light.png)
![screenshot placeholder](docs/screenshot-dark.png)

## Features

- **Streaming chat** via Server-Sent Events
- **Thinking display** — parses `<think>...</think>` and Ollama's `thinking` field, shows a collapsible "Thought for Xs" block
- **Model management** — pull (with live progress bar), list, delete from inside the app
- **Multi-user** — admin can create users; non-admins only see their own chats
- **Per-chat config** — model, context window (8K → 1M or custom), system prompt, temperature, thinking toggle
- **Auto-title** chats after the first exchange
- **Auth** with NextAuth credentials + bcrypt, JWT sessions, httpOnly cookies
- **Dark/light mode**, mobile-responsive, smooth animations
- **Markdown + syntax highlighting** via react-markdown + shiki, copy buttons everywhere
- **Keyboard shortcuts**: `⌘K` new chat, `⌘/` focus input, `⌘B` toggle sidebar, `Esc` stop generation

## Stack

- Next.js 15 (App Router) + TypeScript (strict) + Tailwind CSS v4
- Prisma + SQLite
- NextAuth.js v5 (credentials provider)
- shadcn/ui primitives (Radix)
- TanStack Query (server state) + Zustand (client state)
- react-markdown, shiki, sonner, lucide-react

## Quick start

```bash
# 1. Install dependencies
npm install

# 2. Set up environment
cp .env.example .env
# (.env is already created with dev defaults — edit NEXTAUTH_SECRET for production)

# 3. Run migrations + seed the admin account
npx prisma migrate dev --name init
npm run db:seed

# 4. Start the dev server
npm run dev
```

Open <http://localhost:3000> and sign in with:

- **Username:** `admin`
- **Password:** `Floppa.100`

## Running Ollama

If you don't already have Ollama installed, grab it at <https://ollama.com/download>. Once installed, start the daemon (`ollama serve` on Linux/Mac, or just launch the app on Windows/Mac) and pull a model from inside this app: **Settings → Models → Pull** (e.g. `llama3.2:3b` is a great starter).

The default Ollama URL is `http://localhost:11434`. You can override it per user in **Settings → General**.

## Production

```bash
npm run build
npm start
```

For production:

- Set a real `NEXTAUTH_SECRET` (`openssl rand -base64 32`)
- Set `NEXTAUTH_URL` to your actual URL
- Consider PostgreSQL — change the `provider` in `prisma/schema.prisma` and rerun migrations

## Project layout

```
src/
├── app/             # App Router pages + API routes
│   ├── api/         # /chat, /chats, /models, /users, /me, /auth
│   ├── chat/        # /chat and /chat/[id]
│   ├── settings/    # tabbed settings page
│   └── login/
├── components/
│   ├── ui/          # shadcn primitives
│   ├── chat/        # chat-view, message, thinking-block, code-block, input, header
│   ├── settings/    # general, models, users, account
│   └── sidebar/
├── lib/             # auth, prisma, ollama client, utils, stores
├── hooks/           # keyboard shortcuts
└── middleware.ts    # auth gate
prisma/
├── schema.prisma
└── seed.ts          # creates admin / Floppa.100 on first run
```

## License

MIT
