How gptplusplus/salesclaw works
1. Overall shape
SalesClaw is a two-tier product: a FastAPI backend that owns domain data, reasoning, actions, and realtime coordination, and a React + TypeScript frontend that presents decision workflows, analysis panels, and agent-facing UI. The repository is centered on a closed-loop architecture: perception → reasoning → planning → execution → learning.
2. Primary system boundary
The backend is the authoritative application core. It exposes REST endpoints, WebSocket streams, and LLM-backed chat/inference endpoints. The frontend is a consumer of those APIs and also contains some client-side reasoning/analysis modules for interactive visualization and recommendation UX.
3. Data and persistence layer
Persistence is based on SQLite with SQLAlchemy models and Alembic migrations. The backend models directory shows the main persisted concepts: ontology objects, domain entities, inference results, execution logs, actions, memory, notifications, reminders, scenarios, permissions, audits, and users. The schema is organized around a unified ontology/object model rather than many unrelated CRUD tables.
4. Domain model and ontology core
The dominant business abstraction is the ontology/object layer. Domain objects such as doctors, hospitals, products, sales targets, and compliance-related entities are represented through a unified object model and typed relationships. This is the foundation for graph-like reasoning and for presenting contextual views in the UI.
5. Backend service layer
The backend’s services/ package is the main orchestration layer. It separates concerns such as ontology management, reasoning, inference, chat, memory, permissions, scenario simulation, notifications, action execution, effect tracking, and lifecycle management. The routers are thin API adapters; the services contain the real application logic and cross-model coordination.
6. Reasoning and inference subsystem
A major architectural feature is the reasoning stack. There are dedicated routers and services for causal, temporal, consistency, implicit-relation, abductive, analogical, counterfactual, hierarchical, multi-step, constraint-checking, and coordinated reasoning. This subsystem consumes ontology and domain data and produces inference artifacts that are surfaced in the UI and used by suggestion/insight features.
7. Agent execution loop
The backend/agents/ package and corresponding frontend agent/ modules represent the agent-centric workflow. The backend agent layer defines state, tools, and a cognitive graph; it drives tool-using behavior such as fetching context, assessing compliance risk, executing actions, and sending notifications. This is tied to an execution log and approval lifecycle, so agent decisions are traceable rather than directly mutating state.
8. Actions, approvals, and auditability
Action handling is a distinct subsystem, not just another CRUD path. Actions move through a lifecycle such as pending → approved → executed, with execution logs persisted for audit and effect tracking. This creates a governance boundary between “recommendation” and “system action,” which is important in regulated sales/medical contexts.
9. Perception, suggestions, and insights
The system includes a realtime analytical layer that turns raw synchronized business data into higher-level judgments: anomaly detection, risk scoring, loyalty/perception signals, proactive suggestions, and aggregated insights. These features are exposed via dedicated routers/services and feed the decision UI, giving the platform a monitoring/early-warning function in addition to reasoning.
10. Chat and realtime communication
There is a conversational interface backed by the backend chat service and optional OpenAI-compatible LLM integration. Realtime updates are delivered through a WebSocket manager and /api/ws/{user_id}, which the frontend uses for alerts, action-status changes, and reminder updates. This makes the system event-driven at the user interaction layer even though the core persistence is relational.
11. Frontend architecture
The frontend is structured around feature-aligned modules rather than only page-based routing. It contains contexts for auth, ontology, perception, object state, and cognitive interaction; API hooks; domain-specific engines for perception, planning, inference, decision, interaction, and scenario simulation; and many focused UI panels for reasoning, ontology graphs, suggestions, reminders, and execution tracking. Tauri packaging indicates the same frontend can be delivered as a desktop app.
12. External dependencies and integration boundaries
SalesClaw does not appear to own source data ingestion; it assumes upstream systems like ERP/CRM/work collaboration tools populate the database. LLM usage is optional and behind an OpenAI-compatible interface, with fallback behavior when not configured. The key external boundary is therefore: enterprise source systems → SalesClaw database → reasoning/decision services → human review/execution.
13. Operational and delivery structure
The repo includes tests, seed data, environment templates, and build configuration for both backend and frontend. Alembic migrations define the persistence contract, backend tests cover the service/router layers, and frontend tests focus on core decision logic. The architecture is designed to be deployable as a standard web stack or as a desktop-capable client layered over the same backend.
14. What to show in an architecture diagram
The most important boxes are: external business systems, SQLite database, FastAPI backend, service subsystems (ontology/reasoning/perception/actions/chat/agent/event-bus), WebSocket channel, and the React/Tauri frontend. The central data flow should emphasize that domain objects feed reasoning, reasoning feeds suggestions/actions, actions emit execution logs and realtime updates, and the frontend reads both the analytical results and the live event stream.
Main entry points: services Service Layer · App.tsx React Client · action_service.py Actions & Effects · models ORM Models
Components 23
External Systems
Upstream business sources and human operators that interact with SalesClaw.
- Business Systems · ERP, CRM, and other enterprise systems that populate the SalesClaw domain store.
- Human Reviewers · Users who review reasoning, approve actions, and monitor live updates.
Backend
FastAPI application core with data, services, agents, and realtime coordination.
- FastAPI Core · Application entrypoint exposing REST, WebSocket, and orchestration endpoints.
backend/main.py - API Routers · Thin route layer for ontology, reasoning, inference, actions, chat, insights, perception, and events.
backend/routers - Service Layer · Main application logic for ontology, reasoning, inference, memory, permissions, scenarios, actions, and effects.
backend/services - Agent Runtime · Tool-using agent loop with state, tools, and a cognitive graph for traceable execution.
backend/agents - Chat & LLM · Chat service and optional OpenAI-compatible LLM integration with guardrails.
backend/llm.py - Realtime Bus · WebSocket coordination and event delivery for alerts, reminders, and action updates.
backend/services/ws_manager.py - Event Bus · Internal event dispatch used to connect action execution, inference, and notifications.
backend/services/event_bus.py - Reasoning Stack · Causal, temporal, abductive, analogical, counterfactual, hierarchical, and multi-step reasoning.
backend/services/reasoning_service.py - Perception & Insights · Anomaly detection, risk scoring, proactive suggestions, and insight generation from synchronized business data.
backend/routers/perception.py - Actions & Effects · Action lifecycle, approval, execution, and effect tracking with auditability.
backend/services/action_service.py - Ontology Core · Unified ontology and object model for domain entities, typed relationships, and contextual views.
backend/services/ontology_service.py - Memory & Context · Memory, ontology context, lifecycle, and domain mapping used to enrich reasoning and UI context.
backend/services/memory_service.py
Frontend
React + TypeScript client for decision workflows, analysis, and agent UI.
- React Client · TypeScript frontend that assembles decision, ontology, perception, and agent workflows.
frontend/src/App.tsx - App Contexts · Auth, ontology, perception, object, and cognitive interaction state shared across the UI.
frontend/src/contexts - Feature Engines · Perception, planning, inference, decision, interaction, scenario, and ontology logic used by the UI.
frontend/src/perception - Decision Panels · Reasoning, suggestion, execution, chat, ontology graph, reminders, and detail views.
frontend/src/components - Agent Modules · Client-side agent learning, memory, and cognitive coordination modules.
frontend/src/agent - API Client · Typed client and hooks for consuming backend REST and realtime APIs.
frontend/src/api
Persistence
SQLite schema, ORM models, and migrations.
- ORM Models · Persisted concepts including ontology objects, domain entities, inference, execution, memory, notifications, reminders, scenarios, permissions, audits, and users.
backend/models - Migrations · Database migration history defining the SQLite persistence contract.
backend/alembic - SQLite DB · Local relational database backing domain data, logs, and derived artifacts.
backend/salesclaw.db-wal
Connections 27
- Business Systems → SQLite DB: populate · Upstream operational systems feed SalesClaw's persisted domain store.
- Human Reviewers → React Client: use · Humans interact with the decision UI and approve or review actions.
- React Client → App Contexts: composes · The app is structured around shared UI state providers.
- React Client → Feature Engines: uses · Client-side reasoning and planning modules drive interactive UX.
- React Client → Decision Panels: renders · Decision and analysis panels present ontology, reasoning, and execution state.
- React Client → Agent Modules: includes · Agent-facing modules support learning and cognitive workflows.
- React Client → API Client: calls · The frontend consumes backend REST and realtime endpoints through a typed client.
- API Client → FastAPI Core: requests · Client API traffic reaches the FastAPI core.
- FastAPI Core → API Routers: mounts · The application delegates HTTP surface area to focused routers.
- API Routers → Service Layer: delegates · Routers hand off business logic to services.
- Service Layer → Ontology Core: reads/writes · Ontology services manage the unified domain object graph.
- Service Layer → Reasoning Stack: invokes · Reasoning services compute inferences and consistency checks.
- Service Layer → Perception & Insights: produces · Perception and insight services generate anomaly and suggestion outputs.
- Service Layer → Actions & Effects: executes · Action services govern approval, execution, and effect tracking.
- Service Layer → Memory & Context: enriches · Memory and context services supply conversational and operational state.
- Service Layer → Chat & LLM: uses · Chat service provides conversational access and LLM-backed assistance.
- Service Layer → Event Bus: publishes · Services emit internal events for downstream consumers.
- Event Bus → Realtime Bus: delivers · Events are pushed to connected clients over realtime channels.
- Actions & Effects → Realtime Bus: notifies · Action status changes are broadcast to the UI.
- Reasoning Stack → Agent Runtime: supports · Agent behavior relies on reasoning outputs and tool orchestration.
- Agent Runtime → Actions & Effects: triggers · Agents propose or initiate governed actions through the action layer.
- Ontology Core → ORM Models: persists · Ontology objects and relationships are stored via ORM models.
- Actions & Effects → ORM Models: persists · Action lifecycle, execution logs, and audit data are recorded in the schema.
- Memory & Context → ORM Models: persists · Memory, notifications, reminders, and related context are stored in the database.
- ORM Models → Migrations: evolves via · Alembic migrations define and update the schema.
- FastAPI Core → SQLite DB: connects · The backend uses SQLite as the relational persistence layer.
- Realtime Bus → Decision Panels: streams · Realtime updates feed alerts, execution tracking, and reminder UI.