Self-Hosting Guide

Dochat can be self-hosted on your own infrastructure. This guide covers setup, configuration, and deployment.

Note: Self-hosting requires experience with Node.js, PostgreSQL, and cloud infrastructure. For most users, the hosted version at dochat.site is recommended.

Prerequisites

  • Node.js 20+ and pnpm
  • PostgreSQL 14+
  • DigitalOcean account with GenAI API access
  • Clerk account for authentication
  • Domain with SSL

Clone & Install

git clone https://github.com/dimasna/dochat.git
cd dochat
pnpm install

Environment Variables

Create a .env file at the project root:

.env
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/dochat"

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_..."
CLERK_SECRET_KEY="sk_..."
NEXT_PUBLIC_CLERK_SIGN_IN_URL="/sign-in"
NEXT_PUBLIC_CLERK_SIGN_UP_URL="/sign-up"

# DigitalOcean GenAI
DIGITALOCEAN_API_TOKEN="your_do_api_token"
DO_AGENT_MODEL_UUID="uuid_of_ai_model"

# App URLs
NEXT_PUBLIC_APP_URL="https://app.yourdomain.com"
NEXT_PUBLIC_WIDGET_URL="https://widget.yourdomain.com"

# File Storage (DigitalOcean Spaces / S3)
AWS_ACCESS_KEY_ID="your_access_key"
AWS_SECRET_ACCESS_KEY="your_secret_key"
AWS_REGION="us-east-1"
AWS_S3_BUCKET_NAME="dochat-uploads"

Database Setup

Create database
createdb dochat
Run migrations
cd packages/db
pnpm prisma migrate deploy
pnpm prisma generate

Build

# Build all packages and apps
pnpm build

This builds the shared packages (packages/db, packages/ui) and both apps (apps/web, apps/widget).

Run

# Start the web app (default port 3005)
pnpm --filter @dochat/web start

# Start the widget app (default port 3006)
pnpm --filter widget start

Docker Deployment

Dockerfile
FROM node:20-alpine AS base
RUN npm install -g pnpm

FROM base AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/ ./packages/
COPY apps/web/package.json ./apps/web/
RUN pnpm install --frozen-lockfile

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/packages ./packages
COPY . .
RUN pnpm build --filter=@dochat/web

FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app ./
EXPOSE 3005
CMD ["pnpm", "--filter", "@dochat/web", "start"]
docker build -t dochat-web .
docker run -p 3005:3005 --env-file .env dochat-web

DigitalOcean App Platform

  1. Create a new App in DigitalOcean App Platform
  2. Connect your GitHub repository
  3. Set build command: pnpm build
  4. Set run command: pnpm --filter @dochat/web start
  5. Add all environment variables
  6. Deploy

App Platform provides automatic SSL, scaling, and deployment on push.

Widget Deployment

The widget app should be deployed separately at a different subdomain (e.g., widget.yourdomain.com). It's a standard Next.js app that can be deployed the same way as the web app.

Make sure NEXT_PUBLIC_WIDGET_URL in the web app matches the widget's URL.

DigitalOcean GenAI Setup

Dochat uses DigitalOcean's GenAI platform for AI agents and knowledge base search:

  1. Enable GenAI in your DigitalOcean account
  2. Create a project and note the project ID
  3. Get your API token from the DigitalOcean dashboard
  4. Find the model UUID from the available models list
Agents and knowledge bases are provisioned automatically through the app when users create them from the dashboard.

Updating

git pull origin main
cd packages/db && pnpm prisma migrate deploy
cd ../.. && pnpm build
# Restart your services

Troubleshooting

Database connection errors

  • Verify DATABASE_URL format and credentials
  • Check firewall rules allow connections from the app
  • Ensure SSL mode matches your database configuration

Agent provisioning failures

  • Verify DIGITALOCEAN_API_TOKEN is valid and has GenAI access
  • Check API quotas and rate limits
  • Knowledge bases must be fully indexed before attaching to agents

Widget not connecting

  • Verify NEXT_PUBLIC_WIDGET_URL matches the deployed widget URL
  • Check CORS — the widget iframe must be able to reach the web app APIs
  • Ensure both apps have valid SSL certificates