Skip to content

Commit 7ba260b

Browse files
xuyushun441-sysos-zhuangclaude
authored
docs: reconcile AGENTS.md to flat src/ + add maintenance & requirements management (#405)
- AGENTS.md: replace the retired packages/* monorepo description with the real single-app flat src/{type}/ layout; add *.flow.ts to the file-suffix protocol; fix stale example paths and the dependencies note - docs/MAINTENANCE.md: platform-upgrade + seed-staleness + version-alignment playbook - docs/requirements/: file-based, AI-native requirements log mapping a raw customer requirement to a standard-product disposition (A/B/C/D), with the overlay-vs-core seam; includes TEMPLATE.md and an illustrative REQ-0001 - wire the new docs into docs/README.md nav and .github/tasks/new-feature.md Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b2e7815 commit 7ba260b

7 files changed

Lines changed: 347 additions & 29 deletions

File tree

.github/tasks/new-feature.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
**Goal**: Add a functional vertical slice (Object + Logic + UI).
44

5+
**Start from the requirement**: this feature should trace to a record under
6+
[`docs/requirements/`](../../docs/requirements/README.md). Read its **disposition**
7+
first — `B` (standard enhancement) lands in core `src/{type}/`; `C`
8+
(customer-specific) belongs in an overlay/extension package, **not** in HotCRM core.
9+
510
**Prompt**:
611
```markdown
7-
I want to add a `[FEATURE_NAME]` feature to the `[PACKAGE_NAME]` package.
12+
I want to add a `[FEATURE_NAME]` feature to HotCRM (single app, namespace `crm`),
13+
implementing requirement `REQ-[NNNN]`.
814

915
**Requirements**:
10-
1. **Model**: Create `[OBJECT_NAME].object.ts` with fields: [LIST_FIELDS].
11-
2. **Logic**: Create `[OBJECT_NAME].hook.ts` to implement: [DESCRIBE_LOGIC].
12-
3. **UI**: Create `[OBJECT_NAME].page.ts` for a standard record layout.
16+
1. **Model**: Create `src/objects/[OBJECT_NAME].object.ts` with fields: [LIST_FIELDS]. Use the `crm_` prefix.
17+
2. **Logic**: Create `src/objects/[OBJECT_NAME].hook.ts` to implement: [DESCRIBE_LOGIC].
18+
3. **UI**: Create `src/views/[OBJECT_NAME].view.ts` and `src/pages/[OBJECT_NAME].page.ts` for a standard record layout.
1319

1420
Please follow the strictly typed metadata standards in `.github/instructions/metadata.md`.
1521
```

AGENTS.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Enterprise CRM built on the **@objectstack/runtime** engine. Tool-specific files
55
(e.g. `.github/copilot-instructions.md`) point here.
66

77
You are an expert developer working on HotCRM, delivering business capabilities
8-
through modular packages on top of the ObjectStack platform.
8+
as metadata on top of the ObjectStack platform.
99

1010
## 🗣️ 沟通语言 / Communication Language
1111

@@ -18,25 +18,37 @@ commit messages, PR titles/bodies, and code comments in English.
1818

1919
## 🏗️ Project Architecture
2020

21-
HotCRM follows a **Plugin-Based Monorepo** structure:
21+
HotCRM is a **single ObjectStack marketplace app**, not a multi-package monorepo.
22+
The source of truth is `objectstack.config.ts`, which registers all metadata from a
23+
flat `src/` tree organised **by metadata type** (not by business package).
2224

2325
- **Engine**: We DO NOT build the core engine. We use `@objectstack/runtime` as the platform dependency.
24-
- **Business Packages** (`packages/*`): We develop independent functional modules here.
25-
- **Apps** (`apps/*`): Deployable applications (Documentation, Admin Portal).
26+
- **Metadata** (`src/{type}/`): All business capability lives here as typed metadata files.
27+
- **Product docs** (`content/docs/`): User/admin/marketplace documentation (Fumadocs).
28+
- **Internal docs** (`docs/`): Architecture, status, release, and maintenance notes.
2629

27-
**Directory Structure**:
30+
**Directory Structure** (see `docs/README.md` for the full map):
2831
```
2932
hotcrm/
30-
├── packages/ # Business Capabilities (Plugins)
31-
│ ├── crm/ # Sales Cloud (Account, Opportunity)
32-
│ ├── finance/ # Revenue Cloud (Contract, Invoice)
33-
│ ├── products/ # CPQ Product Catalog
34-
│ └── ...
35-
36-
└── apps/
37-
└── docs/ # Official Documentation
33+
├── objectstack.config.ts # App manifest — registers metadata from src/
34+
├── src/
35+
│ ├── objects/ # *.object.ts schemas + *.hook.ts lifecycle hooks
36+
│ ├── views/ pages/ # App UI metadata (*.view.ts / *.page.ts)
37+
│ ├── flows/ # Automation (*.flow.ts)
38+
│ ├── actions/ # UI actions + AI-callable tools (*.action.ts)
39+
│ ├── dashboards/ reports/ datasets/ cubes/ # Analytics metadata
40+
│ ├── agents/ skills/ # AI agent + skill metadata
41+
│ ├── profiles/ sharing/ # Permission sets, role hierarchy, sharing rules
42+
│ ├── translations/ # Locale bundles (en / zh-CN / es-ES / ja-JP)
43+
│ └── data/ # Seed data (defineDataset)
44+
├── content/docs/ # Product documentation site content
45+
└── docs/ # Internal maintainer documentation
3846
```
3947

48+
> The retired multi-package (`packages/*`) direction is archived under
49+
> `docs/archive/`. Do NOT create `packages/<x>/src/` paths — everything lives in the
50+
> flat `src/{type}/` tree above.
51+
4052
## 💻 Tech Stack & Protocol
4153

4254
1. **Metadata-First (`*object.ts`)**:
@@ -60,12 +72,12 @@ hotcrm/
6072
When asked to implement a feature, you MUST follow this **Thinking Process**:
6173

6274
### Phase 1: Architecture & Planning
63-
1. **Analyze**: Identify the Business Package (e.g., `packages/hr`) and Dependencies.
75+
1. **Analyze**: Identify the domain area (e.g., sales, service, marketing) and the metadata it touches.
6476
2. **Schema Design**: List all necessary Objects, Fields, and Relationships.
6577
3. **File Inventory**: List exact file paths to be created.
66-
* `src/candidate.object.ts` (Data)
67-
* `src/candidate.workflow.ts` (Automation)
68-
* `src/candidate.page.ts` (UI)
78+
* `src/objects/candidate.object.ts` (Data)
79+
* `src/flows/candidate.flow.ts` (Automation)
80+
* `src/pages/candidate.page.ts` (UI)
6981

7082
### Phase 2: Implementation (Iterative)
7183
1. **Metadata First**: Create `*.object.ts` files first. They are the source of truth.
@@ -81,12 +93,13 @@ After generating code, ask yourself:
8193

8294
## 📝 Coding Standards (The "File Suffix Protocol")
8395

84-
We enforce strict file naming to separate concerns. Files should be located in `packages/{package_name}/src/`.
96+
We enforce strict file naming to separate concerns. Files live under `src/{type}/`, grouped by metadata type (e.g. `src/objects/`, `src/flows/`, `src/views/`).
8597

8698
### Core File Types
8799
- `*.object.ts`: Data Model (Schema) — validated with `ObjectSchema.parse()`
88100
- `*.hook.ts`: Server-side Business Logic (Triggers)
89101
- `*.action.ts`: API Endpoints & AI Tools
102+
- `*.flow.ts`: Automation Flows — typed as `Automation.Flow` from `@objectstack/spec/automation`
90103
- `*.page.ts`: UI Page Layouts — validated with `PageSchema` from `@objectstack/spec/ui`
91104
- `*.view.ts`: List View Configurations — validated with `ViewSchema` from `@objectstack/spec/ui`
92105

@@ -130,19 +143,19 @@ Use the most specific `Field` type available from `@objectstack/spec/data`:
130143

131144
## 🚀 Development Workflow
132145

133-
1. **Define Object**: Create `packages/{pkg}/src/{entity}.object.ts`.
134-
2. **Add Logic**: Create `packages/{pkg}/src/{entity}.hook.ts`.
135-
3. **Expose Action**: Create `packages/{pkg}/src/{action}.action.ts` if external API/AI needed.
136-
4. **Config UI**: Create `packages/{pkg}/src/{entity}.page.ts`.
146+
1. **Define Object**: Create `src/objects/{entity}.object.ts`.
147+
2. **Add Logic**: Create `src/objects/{entity}.hook.ts`.
148+
3. **Expose Action**: Create `src/actions/{action}.action.ts` if external API/AI needed.
149+
4. **Config UI**: Create `src/views/{entity}.view.ts` and `src/pages/{entity}.page.ts`.
137150

138151
## ⚠️ Constraint Checklist
139152

140153
- **Object Naming**: All HotCRM business objects MUST be prefixed with `crm_` (e.g., `crm_account`, `crm_opportunity`, `crm_case`, `crm_lead`, `crm_campaign`, `crm_contact`, `crm_contract`, `crm_product`, `crm_quote`, `crm_quote_line_item`, `crm_opportunity_line_item`, `crm_task`, `crm_campaign_member`, `crm_knowledge_article`, `crm_forecast`). All references — `reference_to`, `lookup`, `masterDetail`, cube `sql`, view `data.object`, hook `object`, navigation `objectName`, action `objectName`, dashboard `object` — MUST use the prefixed form. Platform objects keep their existing `sys_*` prefix.
141154
- **i18n**: Every new object must have entries in all 4 locale files (`src/translations/{en,zh-CN,es-ES,ja-JP}.ts`) — label, pluralLabel, all field labels + option labels, view labels, navigation labels. No new feature ships without all 4 locales.
142-
- **Docs**: Every new object/feature requires user-facing documentation under `content/docs/{sales|service|marketing|...}/` written for business users + admins (not developers).
155+
- **Docs**: Every new object/feature requires user-facing documentation under `content/docs/` (e.g. `getting-started/`, `guides/`, `marketing/`, `analytics/`, `administration/`) written for business users + admins (not developers).
143156
- **Documentation**: All documentation MUST be in English.
144157
- **No Engine Code**: Do not try to modify the core runtime code. Focus on the *usage* of the runtime.
145-
- **Dependencies**: HotCRM packages should depend on `@objectstack/runtime` (as peerDependency) and other sibling packages if structure allows.
158+
- **Dependencies**: HotCRM depends on the published `@objectstack/*` packages (runtime, spec, drivers, services) declared in `package.json`. Keep `specVersion` in `objectstack.manifest.json` aligned with the installed `@objectstack/spec`.
146159
- **Tone**: Act as a Senior 10x Engineer. Be concise, professional, and technically accurate.
147160

148161
> **Naming note (ADR-0048):** the `crm_` prefix above is a deliberate HotCRM
@@ -162,7 +175,7 @@ The following are **NOT** in HotCRM's scope — they are platform-level features
162175
- **Low-level services**: database engine, auth (OAuth/SAML/SSO), multi-tenancy, encryption, API gateway, caching, message queue, file storage.
163176
- **Dev tools**: schema migration, CLI scaffolding, metadata deployment pipeline, VCS integration, IDE extensions.
164177

165-
**Focus Area**: HotCRM focuses exclusively on **business domain packages** (CRM, Finance, HR, Marketing, Products, Support) and their **business logic, data models, and AI capabilities**.
178+
**Focus Area**: HotCRM focuses exclusively on **business domains** (CRM, Finance, HR, Marketing, Products, Support) and their **business logic, data models, and AI capabilities** — authored as metadata in `src/`.
166179

167180
---
168181

docs/MAINTENANCE.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# HotCRM Maintenance & Upgrade Playbook
2+
3+
> Scope: how to keep this single ObjectStack marketplace app healthy over time —
4+
> the everyday change loop, platform (`@objectstack/*`) upgrades, seed-data
5+
> verification, and version alignment.
6+
>
7+
> HotCRM is a **consumer** of the ObjectStack platform, not the platform itself.
8+
> It therefore does **not** keep an ADR log (those live in the `framework` repo).
9+
> Its decisions are business/domain decisions captured as metadata in `src/`,
10+
> plus a changeset per change. See [README.md](README.md) for the doc map.
11+
12+
## 1. How HotCRM is managed
13+
14+
There is no separate "project management" system — the repo files **are** the
15+
management surface. Know which file owns which fact:
16+
17+
| Concern | Source of truth |
18+
| --- | --- |
19+
| Conventions for humans + AI agents | [`AGENTS.md`](../AGENTS.md) |
20+
| Customer requirements → product disposition | [`docs/requirements/`](requirements/README.md) |
21+
| App identity (id, namespace, version) | [`objectstack.config.ts`](../objectstack.config.ts) + [`objectstack.manifest.json`](../objectstack.manifest.json) |
22+
| What metadata exists (live counts) | [`docs/STATUS.md`](STATUS.md) — regenerated from `pnpm validate` |
23+
| How it ships | [`docs/RELEASE_STRATEGY.md`](RELEASE_STRATEGY.md) |
24+
| What changed, per release | [`CHANGELOG.md`](../CHANGELOG.md) + `.changeset/` |
25+
| Architecture overview | [`docs/ARCHITECTURE.md`](ARCHITECTURE.md) |
26+
| User/admin docs | [`content/docs/`](../content/docs/) |
27+
28+
## 2. Everyday change loop (per PR)
29+
30+
1. Author metadata under the correct `src/{type}/` folder (see `AGENTS.md`).
31+
2. Keep all 4 locale bundles in sync (`src/translations/{en,zh-CN,es-ES,ja-JP}.ts`).
32+
3. Add the matching user doc under `content/docs/` if behaviour changed.
33+
4. Add a changeset describing the change.
34+
5. Run the full gate and make sure it is green:
35+
36+
```bash
37+
pnpm verify # = validate && typecheck && build && test
38+
```
39+
40+
6. Open the PR. **Merge only after remote CI is fully green** — never `--auto`
41+
ahead of CI, and never edit on a shared `main` checkout (use a worktree).
42+
43+
## 3. Platform upgrade checklist (`@objectstack/*` bump)
44+
45+
This is the single riskiest routine operation, because a platform contract change
46+
can silently invalidate existing metadata or **seed data** (see §4). Treat every
47+
`@objectstack/*` version bump as a verification event, not a dependency tweak.
48+
49+
1. Bump all `@objectstack/*` deps in [`package.json`](../package.json) together —
50+
they are released in lockstep, so keep them on one version line.
51+
2. Update `specVersion` in [`objectstack.manifest.json`](../objectstack.manifest.json)
52+
to match the installed `@objectstack/spec` (e.g. `^9.11.0`).
53+
3. `pnpm install`.
54+
4. `pnpm verify`. Validation failures here are usually metadata that a new
55+
platform contract just started enforcing — fix the metadata, do not pin back.
56+
5. **Reset and reseed**, then smoke-test in the Console (see §4):
57+
58+
```bash
59+
pnpm demo:reset # wipes .objectstack/data, rebuilds; seeds reload on first boot
60+
pnpm dev # then open the Console and eyeball the seeded app
61+
```
62+
63+
6. If `better-sqlite3` floods `NODE_MODULE_VERSION ... requires ...` on boot, the
64+
native binary was built for a different Node ABI — `pnpm rebuild better-sqlite3`
65+
and restart. This is an environment issue, not an app change.
66+
7. Note the new platform version in `CHANGELOG.md`.
67+
68+
## 4. Seed-data staleness — the #1 HotCRM pitfall
69+
70+
Stale seed data is the most common cause of "Studio shows a red
71+
'metadata is invalid' banner" or "the home page lists pending issues." It is
72+
**almost always the seed, not a designer bug**: a platform contract changed
73+
(a validation rule was retired, a dashboard now requires a `dataset` + values),
74+
and the fixtures in `src/data/` were never updated to match.
75+
76+
After any platform upgrade, or whenever Studio shows validation banners:
77+
78+
1. `pnpm validate` — confirm the **metadata** itself is clean.
79+
2. `pnpm demo:reset && pnpm dev` — reseed from a clean DB.
80+
3. Open the Console and visually verify the seeded records, dashboards, and
81+
views render. For dashboards, **wait for the lazy-loaded chart bundle** before
82+
judging an empty card (see `AGENTS.md` → "Verifying UI in the browser").
83+
4. If a banner persists, fix the offending fixture in `src/data/`, not the
84+
designer or the platform.
85+
86+
## 5. Releasing
87+
88+
HotCRM ships as **one** app package (`hotcrm` / `app.objectstack.hotcrm`). Before
89+
publishing, keep the version aligned across all four places:
90+
91+
- `package.json` `version`
92+
- `objectstack.config.ts` manifest `version`
93+
- `CHANGELOG.md`
94+
- the marketplace publish note
95+
96+
Full procedure (build artifact, dry-run, publish) lives in
97+
[`RELEASE_STRATEGY.md`](RELEASE_STRATEGY.md). Do not duplicate it here.
98+
99+
> **Keep `STATUS.md` honest.** It is a snapshot, not live — regenerate its counts
100+
> and version from `pnpm validate` whenever they drift from `package.json`.
101+
102+
## 6. When HotCRM actually needs a design doc
103+
104+
Rarely. HotCRM does not use the platform's ADR-NNNN system. Reach for a short
105+
design note (placed in `docs/`, archived to `docs/archive/` when superseded) only
106+
when a decision is **cross-cutting and hard to reverse** and a future maintainer
107+
would need the "why" — e.g. the explicit `crm_` prefix convention already
108+
recorded in `AGENTS.md`. Routine "added an object / view / flow" work needs a
109+
changeset, not a design doc.

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ HotCRM also has product-facing documentation under [`content/docs/`](../content/
1313
| Runtime and metadata architecture | [ARCHITECTURE.md](ARCHITECTURE.md) |
1414
| Local, artifact, and marketplace deployment | [DEPLOYMENT.md](DEPLOYMENT.md) |
1515
| Versioning and distribution | [RELEASE_STRATEGY.md](RELEASE_STRATEGY.md) |
16+
| Upgrade, seeding, and version alignment | [MAINTENANCE.md](MAINTENANCE.md) |
17+
| Customer requirements and product disposition | [requirements/README.md](requirements/README.md) |
1618
| Object field reference | [developers/api_reference.md](developers/api_reference.md) |
1719
| ObjectStack code examples | [developers/code_examples.md](developers/code_examples.md) |
1820

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# REQ-0001: Auto-tag leads by the customer's agency-tier hierarchy
2+
3+
> **Illustrative example** — a worked sample showing the record format and the
4+
> disposition framework. Replace or delete it when the first real requirement lands.
5+
6+
- **Status**: Triaged
7+
- **Source**: Example customer — mid-market manufacturer
8+
- **Raised**: 2026-06-21
9+
- **Disposition**: C customer-overlay
10+
- **Traceability**: (example) overlay package `hotcrm-ext-acme` — not yet built
11+
12+
## Raw requirement (verbatim)
13+
14+
> 我们所有线索都来自代理商,代理商分 8 个等级(S/A/B/C/D/E/F/观察)。线索进来要按
15+
> 来源代理商的等级自动打标;S/A 级线索自动分配给大客户销售组,其它按区域轮询。
16+
17+
## Standard product analysis
18+
19+
HotCRM core has `crm_lead` with owner assignment driven by a routing flow
20+
(`src/flows/*`). It has **no** concept of an "agency tier" — that 8-level taxonomy
21+
is **this customer's partner-org structure**, not a general CRM primitive. Core
22+
already supports region / round-robin routing.
23+
24+
## Disposition & rationale
25+
26+
**C — customer-specific.** The 8-tier agency taxonomy and the S/A → key-account
27+
routing rule encode one customer's go-to-market structure. Baking an 8-level enum
28+
and a bespoke routing branch into core `crm_lead` would impose one customer's
29+
model on every other install.
30+
31+
**Re-triage trigger → B:** if multiple customers ask for configurable
32+
lead-tiering, promote a *generic* `lead_tier` picklist + a configurable routing
33+
rule into core, and retire this overlay.
34+
35+
## Product response
36+
37+
Author a customer overlay / extension package on top of HotCRM — do **not** edit core:
38+
39+
- Extend `crm_lead` with an overlay field `agency_tier` (select) via the
40+
customization overlay (framework ADR-0005), not a core schema edit.
41+
- Add an overlay flow that sets `agency_tier` from the source agency and routes
42+
S/A tiers to the key-account group.
43+
- Ship it as its own `packageId` so it coexists with HotCRM (framework ADR-0048)
44+
and leaves base metadata protected (framework ADR-0010).
45+
46+
## Acceptance
47+
48+
In a HotCRM instance with the overlay installed: importing a lead from an S-tier
49+
agency sets `agency_tier = S` and assigns the key-account group; a C-tier lead
50+
falls through to regional round-robin. Core HotCRM (without the overlay) is
51+
unchanged.

0 commit comments

Comments
 (0)