Project Structure
How ChatJS is organized
Directory Overview
├── app/ # Next.js App Router
│ ├── (auth)/ # Auth routes (login, register)
│ ├── (chat)/ # Main chat interface
│ ├── api/ # API routes (EVE gateway, auth, tRPC)
│ └── actions/ # Server Actions
│
├── components/
│ ├── ai-elements/ # AI Elements registry components
│ ├── chat/ # Chat UI components
│ ├── part/ # Tool part renderers
│ ├── settings/ # Settings pages
│ └── ui/ # shadcn/ui components
│
├── lib/
│ ├── ai/ # AI SDK integration, tools, prompts
│ │ └── gateways/ # Gateway abstraction (Vercel, OpenRouter)
│ ├── db/ # Database schema, queries, and data access
│ ├── eve/ # EVE runtime integration
│ ├── models/ # Model types and utilities
│ └── artifacts/ # Client helpers for document artifacts
│
├── chatjs/
│ ├── core/ # Installed source: helpers and contracts
│ ├── providers/ # Installed source: providers and configuration
│ ├── plugins/<id>/ # Installed source: plugin implementations
│ ├── tools/<id>/ # Installed source: tools and renderers
│ ├── generated/ # Generated wiring; change its inputs
│ └── installed-source.json # Recorded installed-file hashes
├── integrations/ # Application composition, preserved by installation
│ ├── auth/
│ ├── chat/
│ ├── tools/
│ ├── documents/
│ ├── providers/
│ ├── billing.ts
│ ├── database.ts
│ └── …
├── agent/ # EVE agent channels, hooks, and tools
├── trpc/ # tRPC routers and procedures
├── hooks/ # React hooks
├── providers/ # React context providers
└── scripts/ # Build and dev scripts
Files have four lifecycle kinds: application, installed source, generated, and installation record. Scaffolded application code becomes yours, and add/remove/sync preserve its composition. Installed source can also be edited, with local changes tracked for replacement/removal. Generated files are rebuilt from inputs, while installation records are maintained by the CLI.
Some native files under app/ and agent/ belong to installed plugins or tools. Their short ChatJS source headers identify the exception. Plugin descriptors declare their external paths, and source receipts track files written by the CLI. Headers are explanatory, not an additional installation manifest.
Run chat-js status to inspect source states, framework-file ownership, and removal dependencies. Keep installation receipts in version control. See Customize plugin integrations for app-owned wrappers and local behavior.
Key Files
| File | Purpose |
|---|---|
chat.config.ts |
Central configuration (models, branding, tool options) |
lib/config.ts |
Parsed config export with defaults |
lib/env.ts |
Environment variable validation (t3-env) |
chatjs/providers/storage.ts |
Selected Files SDK adapter |
lib/file-storage.ts |
Provider-agnostic file operations |
lib/auth.ts |
Better Auth server configuration |
lib/auth-client.ts |
Better Auth client configuration |
lib/db/schema.ts |
Drizzle ORM database schema |
proxy.ts |
Route protection middleware |
App Router Structure
Route Groups
(auth)- Authentication pages, shared layout without chat UI(chat)- Main application, chat interface layout
API Routes
app/api/
├── auth/[...all]/ # Better Auth handler
├── eve/[...path]/ # Authenticated EVE gateway
├── agent-conversations/ # Conversation metadata operations
├── trpc/[trpc]/ # tRPC handler
└── cron/ # Scheduled tasks
Components Architecture
UI Layer
components/
├── ui/ # Base components (shadcn/ui)
│ └── extra/ # Local tweaks on shadcn components
├── ai-elements/ # AI Elements components
│ └── extra/ # Local tweaks on AI Elements
├── chat/ # Chat-specific components
└── part/ # Tool result renderers
Part Components
Shared message and tool presentation lives in components/part/. Installed tools can also provide their own renderers:
components/part/
├── web-search.tsx
├── document-common.tsx
└── ...
See Tool Part Pattern for implementation details.
Library Structure
AI Integration
lib/ai/
├── active-gateway.ts # Active gateway selection
├── gateways/registry.ts # Installed gateway registry
├── models.ts # Model fetching and caching
├── models.generated.ts # Fallback model list
└── prompts.ts # Shared prompts
EVE agent instructions, hooks, and tool integration live in agent/. Installed tools live in chatjs/tools/, with application support in tools/platform/.
Data Layer
lib/
├── db/
│ ├── schema.ts # Drizzle schema
│ ├── queries.ts # Database queries for application metadata
│ ├── eve-queries.ts # EVE conversation metadata and ownership queries
│ └── client.ts # Database connection
├── eve/ # Gateway, message, copy, and lifecycle contracts
└── artifacts/ # Client artifact metadata helpers
Credit balances live in chatjs/plugins/credits/. Core usage evidence and reconciliation stay in lib/db/eve-billing.ts and lib/eve/.
Configuration Flow
chat.config.ts # Define features, models, branding
↓
lib/config.ts # Parse defaults and export config
↓
lib/env.ts # Validate environment variables
↓
Runtime # Installed contributions and configured preferences
Data Flow
Browser UI or EVE gateway
↓
ChatJS metadata procedure
↓
Database Queries (lib/db/)
↓
Drizzle ORM
↓
PostgreSQL
AI Streaming Flow
Chat UI (EVE React integration)
↓
Authenticated ChatJS gateway
↓
EVE runtime and event stream
↓
Gateway Abstraction → Provider (OpenAI, Anthropic, etc.)
↓
Stream response with tool calls
↓
Tool execution (if needed)
↓
Client renders parts
Repository ownership
apps/chat is the reference consumer and core template source. Canonical installables live in packages/registry/src/. The CLI publishes explicit source mappings and generates composition files. Maintainer page captures live in packages/chat-visual-tests, outside scaffolded applications. Plugin routes in app/ and discoverable tools in agent/ delegate to the owning plugin.
See Authoring plugins for the contribution contract and Registry authoring for distribution and demo synchronization.