Getting Started

Project Structure

Learn about the project structure of OpenChat.

Overview

OpenChat is a Next.js (App Router) application with Prisma for data access and optional real‑time collaboration for documents. The repository is organized to keep routes, API handlers, database schema, and UI components clear and discoverable.

Key endpoints (local development)

Repository layout

openchat/
├── app/                    # Next.js App Router (routes, layouts, server actions)
   ├── (main)/             # Main UI group
   ├── page.tsx        # Landing / home
   ├── chat/           # Chat interface
   ├── admin/          # Admin panel
   └── docs/           # Collaborative documents
       ├── page.tsx    # Document list
       └── [id]/page.tsx # Document editor
   ├── api/                # API routes (auth, providers, tools)
   ├── auth/           # Auth endpoints (NextAuth)
   └── ...             # Model/provider webhooks & utilities
   └── layout.tsx          # Root layout
├── components/             # Reusable UI components
   ├── editor/             # Rich‑text editor & extensions
   └── ui/                 # Design system components
├── lib/                    # Shared server/client utilities, provider clients
├── prisma/                 # Prisma schema and migrations
   └── schema.prisma
├── public/                 # Static assets
├── scripts/                # Local/dev scripts (optional)
├── .env.example            # Environment variable template
├── package.json
└── README.md

Notable directories

  • app/: All routes and server logic using Next.js App Router. UI lives under (main); API handlers under app/api.
  • components/: Modular UI pieces; includes the collaborative editor.
  • lib/: Configuration, provider integrations, and shared helpers.
  • prisma/: Database schema and migrations. Defaults to SQLite; supports PostgreSQL.
  • public/: Static assets served at the root.

Data & persistence

OpenChat uses Prisma. By default, SQLite is persisted to the project (or Docker volume). To use PostgreSQL, set DB=postgres and provide DATABASE_URL (or POSTGRES_URL / POSTGRES_DIRECT_URL).

Realtime collaboration

Document editing can use a Hocuspocus WebSocket server (ws://localhost:1234) for multi‑user, real‑time updates in the /docs section.

Development scripts

  • npm run db:push: Apply schema to the database
  • npm run dev: Start the Next.js dev server
  • npm run serve: Run migrations, build, and start the server