# sheily899/feishu-sales-dealtrace architecture

> Architecture diagram of the GitHub repository sheily899/feishu-sales-dealtrace, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sheily899/feishu-sales-dealtrace
- Repository: https://github.com/sheily899/feishu-sales-dealtrace

## Overview

#### Purpose and Entry Points
DealTrace is a Python prototype for tracking customer issues across Feishu sales-group conversations. It normalizes messages, uses an LLM to propose structured changes, validates those changes against source evidence and prior state, then renders a local workbench. Primary runtime entry points are `src/dealtrace/__main__.py` and `src/dealtrace/cli.py`; the browser-only offline demo is published from `docs/index.html`.

#### Conversation Ingestion Boundary
Feishu integration receives group-message events, enforces configured group/role boundaries, and converts events into internal message representations. Local fixtures support offline/demo input. The external-system boundary is isolated in `src/dealtrace/feishu.py`, while core entities are defined in `src/dealtrace/models.py`; recorder/transcript import formats are handled under `src/dealtrace/adapters/`.

#### Analysis Pipeline and LLM Boundary
The processing pipeline takes normalized message batches plus the prior customer snapshot, invokes prompt-guided LLM analysis, and converts returned content into state operations. LLM output is advisory, not canonical: model access and request behavior belong in `src/dealtrace/llm.py`, orchestration in `src/dealtrace/pipeline.py`, and prompt contracts in `prompts/system.md`, `prompts/outcome_inference.md`, and `prompts/rubric_scoring.md`. Live analysis uses a DeepSeek API key; offline demo mode uses precomputed data and avoids model calls.

#### Canonical Customer-State Engine
State is the central integrity boundary. It parses proposed issue changes, links updates to historical `issue_id`s, retains unresolved issues, and rejects unsupported transitions while preserving the previous state. This logic is concentrated in `src/dealtrace/customer_state.py`, with evidence/ownership attribution support in `src/dealtrace/attribution.py`. The intended flow is: new normalized messages → proposed issue operations → historical linking and evidence validation → accepted snapshot/change set or recorded rejection.

#### Persistence and Workbench Delivery
Accepted analysis, message history, state versions, and rejection reasons are persisted in a single-machine SQLite store; the live default is `data/workbench.sqlite3` (runtime-created). `src/dealtrace/workbench_store.py` owns storage concerns, and `src/dealtrace/workbench.py` exposes the local UI/workflow for chat inspection, triggering analysis, viewing issues, and navigating evidence. There is no stated authentication, multi-tenancy, or production-grade authorization boundary.

#### Configuration-Driven Sales Semantics
Schemas constrain interchange formats for transcripts, extracted reports, scorecards, CRM mappings, and inbox data. Key contracts are `schemas/transcript.schema.json`, `schemas/coaching_report.schema.json`, and `schemas/rubric_report.schema.json`. Domain behavior is parameterized through scorecards, sales frameworks, rubrics, CRM stage mappings, and outcome/call-type definitions: `scorecards/`, `frameworks/`, `rubrics/`, and `config/crm/`. CRM mapping/writing is a separate integration layer in `src/dealtrace/crm/mapping.py` and `src/dealtrace/crm/writers.py`.

#### Agent and Automation Distribution Layer
Alongside the executable DealTrace package, the repository distributes reusable sales/RevOps agent specifications across business domains. Each agent typically has a human-readable specification, structured descriptor, and implementation targets for Claude, LangGraph, n8n, Zapier, and Activepieces—for example `agents/revenue-operations/deal-stage-clarity.md`, `agents/revenue-operations/deal-stage-clarity.json`, and `agents/revenue-operations/deal-stage-clarity.builds/langgraph.py`. Claude-native commands and agent definitions under `.claude/commands/` and `.claude/agents/` are another invocation surface; they are distribution/orchestration assets rather than the core Feishu workbench runtime.

Main entry points: [`src/dealtrace/pipeline.py`](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/pipeline.py) (Analysis pipeline), [`src/dealtrace/customer_state.py`](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/customer_state.py) (Customer-state engine), [`src/dealtrace/workbench.py`](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/workbench.py) (Local workbench), [`src/dealtrace/workbench_store.py`](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/workbench_store.py) (SQLite workbench store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["DealTrace runtime"]
  node_entrypoints["CLI entry points<br/>Python entry<br/>[cli.py]"]
  node_feishu{{"Feishu boundary<br/>integration adapter<br/>[feishu.py]"}}
  node_adapters["Transcript adapters<br/>input adapters"]
  node_models["Core message models<br/>domain models<br/>[models.py]"]
  node_workbench["Local workbench<br/>local UI<br/>[workbench.py]"]
  node_store[("SQLite workbench store<br/>persistence<br/>[workbench_store.py]")]
  node_offline_demo["Offline browser demo<br/>static demo<br/>[index.html]"]
end

subgraph group_analysis["Analysis and state"]
  node_pipeline["Analysis pipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_llm{{"LLM client<br/>model gateway<br/>[llm.py]"}}
  node_prompts["Prompt contracts<br/>prompt templates<br/>[system.md]"]
  node_state["Customer-state engine<br/>integrity boundary<br/>[customer_state.py]"]
  node_attribution["Evidence attribution<br/>validation support<br/>[attribution.py]"]
end

subgraph group_contracts["Contracts and semantics"]
  node_schemas["Interchange schemas<br/>JSON schemas"]
  node_sales_semantics["Sales semantics<br/>domain configuration"]
  node_crm_mapping{{"CRM mapping<br/>CRM integration<br/>[mapping.py]"}}
  node_crm_writers{{"CRM writers<br/>CRM integration<br/>[writers.py]"}}
end

subgraph group_distribution["Automation distribution"]
  node_agent_specs["Sales agent specs<br/>automation assets"]
  node_langgraph_build["LangGraph build target<br/>agent implementation<br/>[langgraph.py]"]
  node_claude_assets["Claude commands and agents<br/>invocation assets"]
end

node_entrypoints -->|"receives events"| node_feishu
node_entrypoints -->|"starts"| node_workbench
node_feishu -->|"normalizes"| node_models
node_adapters -->|"imports"| node_models
node_models -->|"message batches"| node_pipeline
node_workbench -->|"triggers analysis"| node_pipeline
node_store -->|"prior snapshot and history"| node_pipeline
node_pipeline -->|"analysis request"| node_llm
node_prompts -->|"guides"| node_llm
node_llm -->|"advisory output"| node_pipeline
node_pipeline -->|"proposed operations"| node_state
node_attribution -->|"evidence support"| node_state
node_state -->|"accepted snapshots or rejections"| node_store
node_store -->|"history and state"| node_workbench
node_schemas -.->|"validates formats"| node_adapters
node_sales_semantics -.->|"scoring and outcomes"| node_pipeline
node_state -->|"canonical changes"| node_crm_mapping
node_crm_mapping -->|"mapped updates"| node_crm_writers
node_agent_specs -.->|"implementation target"| node_langgraph_build
node_claude_assets -.->|"invokes distributed agents"| node_agent_specs
node_offline_demo -.->|"demo counterpart"| node_workbench

click node_entrypoints "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/cli.py"
click node_feishu "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/feishu.py"
click node_models "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/models.py"
click node_workbench "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/workbench.py"
click node_store "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/workbench_store.py"
click node_offline_demo "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/docs/index.html"
click node_pipeline "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/pipeline.py"
click node_llm "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/llm.py"
click node_prompts "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/prompts/system.md"
click node_state "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/customer_state.py"
click node_attribution "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/attribution.py"
click node_schemas "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/schemas/transcript.schema.json"
click node_crm_mapping "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/crm/mapping.py"
click node_crm_writers "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/crm/writers.py"
click node_agent_specs "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/agents/revenue-operations/deal-stage-clarity.md"
click node_langgraph_build "https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/agents/revenue-operations/deal-stage-clarity.builds/langgraph.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entrypoints,node_feishu,node_adapters,node_models,node_workbench,node_store,node_offline_demo toneBlue
class node_pipeline,node_llm,node_prompts,node_state,node_attribution toneAmber
class node_schemas,node_sales_semantics,node_crm_mapping,node_crm_writers toneMint
class node_agent_specs,node_langgraph_build,node_claude_assets toneRose
```

## Components

### DealTrace runtime

- [CLI entry points](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/cli.py): Python entry · Starts live and local workflows. · `src/dealtrace/cli.py`
- [Feishu boundary](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/feishu.py): integration adapter · Filters group events and normalizes them. · `src/dealtrace/feishu.py`
- **Transcript adapters**: input adapters · Imports recorder and transcript formats.
- [Core message models](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/models.py): domain models · `src/dealtrace/models.py`
- [Local workbench](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/workbench.py): local UI · Inspects chat, issues, and evidence; triggers analysis. · `src/dealtrace/workbench.py`
- [SQLite workbench store](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/workbench_store.py): persistence · Persists messages, snapshots, accepted changes, and rejections. · `src/dealtrace/workbench_store.py`
- [Offline browser demo](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/docs/index.html): static demo · Uses precomputed data without model calls. · `docs/index.html`

### Analysis and state

- [Analysis pipeline](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/pipeline.py): orchestrator · Turns normalized batches and prior snapshots into proposed operations. · `src/dealtrace/pipeline.py`
- [LLM client](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/llm.py): model gateway · DeepSeek request behavior; output is advisory. · `src/dealtrace/llm.py`
- [Prompt contracts](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/prompts/system.md): prompt templates · `prompts/system.md`
- [Customer-state engine](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/customer_state.py): integrity boundary · Links history, validates evidence, and preserves prior state on rejection. · `src/dealtrace/customer_state.py`
- [Evidence attribution](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/attribution.py): validation support · Supports evidence and ownership attribution. · `src/dealtrace/attribution.py`

### Contracts and semantics

- [Interchange schemas](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/schemas/transcript.schema.json): JSON schemas · Constrain transcript, coaching, and rubric reports. · `schemas/transcript.schema.json`
- **Sales semantics**: domain configuration · Scorecards, frameworks, rubrics, and CRM stage mappings.
- [CRM mapping](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/crm/mapping.py): CRM integration · Maps canonical state to CRM fields. · `src/dealtrace/crm/mapping.py`
- [CRM writers](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/src/dealtrace/crm/writers.py): CRM integration · Writes mapped changes to CRM. · `src/dealtrace/crm/writers.py`

### Automation distribution

- [Sales agent specs](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/agents/revenue-operations/deal-stage-clarity.md): automation assets · Reusable RevOps agent specifications and descriptors. · `agents/revenue-operations/deal-stage-clarity.md`
- [LangGraph build target](https://github.com/sheily899/feishu-sales-dealtrace/blob/experiment/supplemental-review/agents/revenue-operations/deal-stage-clarity.builds/langgraph.py): agent implementation · `agents/revenue-operations/deal-stage-clarity.builds/langgraph.py`
- **Claude commands and agents**: invocation assets · Separate distribution and orchestration surface.

## Connections

- CLI entry points → Feishu boundary: receives events
- CLI entry points → Local workbench: starts
- Feishu boundary → Core message models: normalizes
- Transcript adapters → Core message models: imports
- Core message models → Analysis pipeline: message batches
- Local workbench → Analysis pipeline: triggers analysis
- SQLite workbench store → Analysis pipeline: prior snapshot and history
- Analysis pipeline → LLM client: analysis request
- Prompt contracts → LLM client: guides
- LLM client → Analysis pipeline: advisory output
- Analysis pipeline → Customer-state engine: proposed operations
- Evidence attribution → Customer-state engine: evidence support
- Customer-state engine → SQLite workbench store: accepted snapshots or rejections
- SQLite workbench store → Local workbench: history and state
- Interchange schemas → Transcript adapters: validates formats
- Sales semantics → Analysis pipeline: scoring and outcomes
- Customer-state engine → CRM mapping: canonical changes
- CRM mapping → CRM writers: mapped updates
- Sales agent specs → LangGraph build target: implementation target
- Claude commands and agents → Sales agent specs: invokes distributed agents
- Offline browser demo → Local workbench: demo counterpart
