AI Chat is an Angular and Electron framework for building desktop conversations backed by scripted agents, state machines, or local AI models. Its chat domain is independent of persistence: agents own conversation decisions, while providers and managers own storage, authentication, and synchronization.
The current application includes:
- an Angular 22 messaging interface;
- Electron IPC with a context-isolated preload bridge;
- local PowerSync SQLite storage;
- optional authenticated synchronization with a self-hosted PowerSync and PostgreSQL backend;
- scripted, XState, and local-AI agent examples;
- validation, possible answers, attachments, editing, deletion, retry, search, and lazy history loading.
Start with the documentation index or the getting-started guide.
| Area | Guide |
|---|---|
| System boundaries | Architecture |
| Creating agents | Agent introduction |
| Agent overrides | Agent lifecycle functions |
| Guided XState flows | State-machine agents |
| Chats and participants | Chat introduction |
| Messages and statuses | Message documentation |
| Persistence behavior | Signals and persistence |
| Languages and RTL | Localization |
| Storage integrations | Chat providers |
| Authentication and sync | Authentication |
| Test strategy | Testing |
| Backend requirements | PowerSync backend contract |
The renderer and main process have separate responsibilities:
- Angular renders chats and owns the in-memory domain objects.
Clientappends user questions or answers.ChatManagertranslates message operations into provider calls and statuses.ChatProviderpersists chats, supporters, and messages.Supporterinvokes the currentAgentafter a successful client message.- The agent decides which supporter message, question, or answer comes next.
- Electron IPC connects the renderer provider to local database, authentication, and synchronization services.
Older message history is loaded lazily. A MessageLoader exhausts each registered MessageSource before moving to the next source, allowing multiple history segments to be chained in a predictable order.
The application explicitly registers three agents in src/app/app-agents.module.ts:
| Agent | Purpose |
|---|---|
AiAgent |
Sends the latest client message to a local OpenAI-compatible endpoint. |
MockAgent |
Demonstrates a scripted support questionnaire with validators and possible answers. |
FlowAgent |
Demonstrates an XState-driven, persistable conversation flow. |
Agent registration keys are persisted names. Keep them stable or migrate stored chats when renaming an agent.
SqliteProvider is currently registered through the Angular CHAT_PROVIDER multi token. Its public integration is presented as PowerSync and combines:
PowerSyncAuthenticationServicefor authentication and synchronization state;DbServiceand Electron IPC for local database operations;SqliteManagerfor message and chat mutations;SqliteMessagesSourcefor paginated history hydration.
The database supports local operations without an authenticated session. When a session exists, PowerSync connects and uploads queued local changes. Logging out follows the provider's explicit local-data policy.
- Node.js
- npm
- Windows desktop environment for the current Electron setup
- native build tooling supported by Electron when rebuilding
better-sqlite3
Remote synchronization additionally requires the PowerSync and backend services described by the repository configuration and backend contract.
npm installThe post-install script rebuilds better-sqlite3 for the installed Electron version.
Build the Angular application and Electron process, then open the desktop app:
npm startFor an Angular development build followed by Electron:
npm run devnpm run watch watches the Angular renderer only; it does not restart Electron.
AiAgent currently calls the OpenAI-compatible endpoint configured in src/services/ai.service.ts:
http://localhost:1234/v1/chat/completions
The configured model is:
google/gemma-3-4b
Start LM Studio or another compatible local server with that model before using AiAgent. MockAgent and FlowAgent do not require an AI server.
npm run build
npm test -- --watch=false
npm run test:electronnpm run buildbuilds Angular and compiles Electron TypeScript.- Angular tests cover domain helpers and standalone components.
- Electron Vitest suites cover database behavior, authentication, synchronization, connector outcomes, and production contracts.
On Windows automation, use npm.cmd if the shell does not resolve npm's PowerShell shim.
src/
agents/ Conversation implementations
app/ Angular UI and registration modules
authenticators/ Renderer-side authentication providers
chat-managers/ Mutation and status policies
chat-providers/ Chat persistence integrations
classes/ Chat, message, participant, and agent domain classes
message-sources/ Lazy history sources
services/ Angular services and Electron bridge wrappers
signals/ Persistence-aware signal helpers
testing/ Shared renderer test doubles
ipc/ Electron IPC handlers
services/ Electron database, auth, sync, and upload services
shared/ Contracts shared by renderer and main process
tests/electron/ Node-based Electron and integration tests
docs/ Framework and backend documentation
powersync/ PowerSync service and sync configuration
- Add conversation behavior by extending
Agentand registering it inAppAgentsModule. - Add a backend by implementing
ChatProvider, pairing it with aChatManager, and registering it withmulti: true. - Add older history by extending
MessageSourceand appending it to a chat's loader. - Add provider authentication by implementing
AuthenticationProviderand supplying an authentication component in provider metadata.
The documentation index contains the complete contracts and examples for each extension point.