SPEC-DDD-CEC Rev 0.3.1 · 2026-08-03

Cane Agency · DDD Seriesสถาบันอ้อย · ชุดเอกสาร DDD

Department Design — Contractor (ผู้รับเหมา) Perspectiveการออกแบบหน่วยงาน — มุมมองผู้รับเหมา

Documentเอกสาร
SPEC-DDD-CEC
Versionversion (เวอร์ชัน)
0.3.1 · Draftฉบับร่าง
Updatedปรับปรุงล่าสุด
2026-08-03
Parentเอกสารแม่
SPEC-DDD
Source of truthแหล่งความจริง
docs/graph/spec-graph.json v5.0

1. Bounded contexts1. บริบทขอบเขต

ContextบริบทOwnsเป็นเจ้าของPurposeหน้าที่
service_marketplace
ตลาดบริการ
ServiceOffering · ServiceRequest · ServiceQuote · ServicePaymentDemand↔supply matching: directory (M1), RFQ (M2), broadcast instant dispatch จองด่วน (M2i), forecast matching (M3). Reads land_crop_registry and quota_planning to anchor demand to real fields and harvest windows. Owns the four payment rails.จับคู่อุปสงค์↔อุปทาน: ไดเรกทอรี (M1), RFQ (M2), จองด่วนแบบกระจาย (M2i), จับคู่จากพยากรณ์ (M3) อ่าน land_crop_registry และ quota_planning เพื่อยึดอุปสงค์กับแปลงและช่วงเก็บเกี่ยวจริง เป็นเจ้าของการชำระสี่ช่องทาง
work_dispatch
การจัดงานภาคสนาม
Contractor · WorkOrder · WorkAssignment · MachineThe operating business, fleet, the work-order contract of record and per-operator assignments with the append-only work_log — publishes WorkVerified, the single gate for payment, reviews, agronomy auto-log and books.กิจการที่ดำเนินงาน เครื่องจักร ใบสั่งงานหลักฐาน และการมอบหมายรายผู้ปฏิบัติงานพร้อม work_log แบบต่อท้าย — เผยแพร่ WorkVerified ประตูเดียวของการจ่าย รีวิว บันทึกเกษตรอัตโนมัติ และบัญชี
reputation
ชื่อเสียง
Review · EndorsementDownstream consumer of verified completions; three-dimension reviews (NFR-10) + institutional endorsements; aggregates feed marketplace ranking (NFR-12).ผู้บริโภคปลายน้ำของงานที่ตรวจรับ; รีวิวสามมิติ (NFR-10) + การรับรองเชิงสถาบัน; ค่าสรุปป้อนอันดับตลาด (NFR-12)
books
สมุดบัญชี
LedgerAccount · JournalEntryDouble-entry ledger + P&L: auto-posts from WorkVerified and ServicePaymentPosted; manual expenses from crew/dispatch; machine profitability via line tags; statements to lending only under ConsentGrant scope books (NFR-13). Tenant-agnostic by design.บัญชีคู่ + งบกำไรขาดทุน: ลงอัตโนมัติจาก WorkVerified และ ServicePaymentPosted; รายจ่ายมือจาก crew/dispatch; กำไรรายเครื่องจักรผ่าน tag (แท็ก) รายการ; งบถึง lending เฉพาะใต้ ConsentGrant scope books (NFR-13) ออกแบบไม่ผูกกลุ่ม
receivables · cash_management
ลูกหนี้/เจ้าหนี้ · เงินสด/ธนาคาร v9.0
Invoice · Receipt · PaymentVoucher · CashAccount · BankTransaction · Reconciliation v9.0PROP-010 widens my books into a full financial system: AR/AP (Invoice/Receipt/PaymentVoucher), cash/bank reconciliation, and the books-family ChartTemplate/FiscalPeriod/FinancialStatement — the payer side of ServicePayment now auto-posts uniformly (NFR-24). Statements to a bank only under ConsentGrant scope books.PROP-010 ขยาย books เป็นระบบการเงินเต็ม: AR/AP (Invoice/Receipt/PaymentVoucher) การกระทบยอดเงินสด/ธนาคาร และ ChartTemplate/FiscalPeriod/FinancialStatement — ด้านผู้จ่ายของ ServicePayment ลงอัตโนมัติเป็นหนึ่งเดียว (NFR-24) งบถึงธนาคารเฉพาะใต้ ConsentGrant scope books

Neighbors: network_identity covers the contractor tenant type and the freelance account; financing publishes the credit_financed contract (CreditItem.work_order_id); settlement publishes the settlement_offset contract (PaymentItem → ServicePayment); farm_agronomy consumes the verification auto-log; credit_risk / lending extend their subject universe to contractors.

บริบทข้างเคียง: network_identity ครอบคลุม tenant ผู้รับเหมาและบัญชีฟรีแลนซ์; financing เผยแพร่สัญญา credit_financed (CreditItem.work_order_id); settlement เผยแพร่สัญญา settlement_offset (PaymentItem → ServicePayment); farm_agronomy บริโภคบันทึกอัตโนมัติจากการตรวจรับ; credit_risk / lending ขยายจักรวาลผู้ถูกประเมินถึงผู้รับเหมา

2. Aggregates & invariants2. แอกกริเกตและกฎคงที่

Aggregate rootรากแอกกริเกตInvariants (never violated)กฎคงที่ (ห้ามละเมิด)
ContractorExactly one of user_id / tenant_id; rating_avg, rating_count, jobs_completed recomputed from Review only; freelance→org upgrade preserves contractor_id and history.user_id / tenant_id อย่างใดอย่างหนึ่ง; ค่าสรุปคำนวณใหม่จาก Review เท่านั้น; อัปเกรดคง contractor_id และประวัติ
ServiceRequestAt most one accepted quote (awarded_quote_id); acceptance creates the WorkOrder atomically; broadcast requests award to the first qualified acceptance at the fixed reference price.ใบเสนอราคาที่ตอบรับได้อย่างมากหนึ่งใบ (awarded_quote_id); การตอบรับสร้าง WorkOrder แบบ atomic; คำขอ broadcast มอบงานแก่รายแรกที่ผ่านเกณฑ์ที่ราคาอ้างอิงคงที่
WorkOrderCreated only by quote acceptance; escrow gate: payment_method = escrow blocks scheduling until escrow_state = funded; verification gates payment release, review eligibility, FarmActivity auto-log and books posting; disputes freeze escrow and never edit ratings.เกิดจากการตอบรับใบเสนอราคาเท่านั้น; ประตู escrow: payment_method = escrow ห้ามจัดคิวจน escrow_state = funded; การตรวจรับเป็นประตูปล่อยเงิน สิทธิ์รีวิว บันทึกเกษตร และการลงบัญชี; ข้อพิพาทแช่ escrow และไม่แตะคะแนน
ServicePaymentOne rail per payment; fee_amount only when method = escrow; escrow money movements append-only, segregated, licensed (NFR-11); cash is recorded, never processed.หนึ่งช่องทางต่อการชำระ; fee_amount เฉพาะ method = escrow; การเคลื่อนไหว escrow ต่อท้าย แยกบัญชี มีใบอนุญาต (NFR-11); เงินสดบันทึกอย่างเดียว
ReviewExactly one per verified work order, authored by its requester; append-only after publication; one public reply; no other creation path exists (NFR-10).หนึ่งรีวิวต่อใบสั่งงานที่ตรวจรับ เขียนโดยผู้ว่าจ้าง; ต่อท้ายหลังเผยแพร่; ตอบกลับหนึ่งครั้ง; ไม่มีเส้นทางสร้างอื่น (NFR-10)
JournalEntryLines balance (Σdebit = Σcredit) within one owner's accounts; append-only, corrections via reversal_of; auto-postings idempotent per source event (NFR-13).รายการสมดุล (Σเดบิต = Σเครดิต) ในบัญชีเจ้าของเดียว; ต่อท้าย แก้ผ่าน reversal_of; การลงอัตโนมัติ idempotent ต่อเหตุการณ์ต้นทาง (NFR-13)

3. Aggregate boundaries & transaction rules3. ขอบเขต aggregate และกติกา transaction

The normative consistency boundaries of this perspective's home contexts (service_marketplace · work_dispatch · reputation), rendered from graph dataModeling.aggregates (v0.4.0, PROP-018). The prose invariants above stay explanatory; the rules here are the transactional contract an implementation must enforce. Column-level persistence for every member entity lives in the sibling SPEC-ERD family (see the Data column).

ขอบเขตความสอดคล้องเชิงบรรทัดฐานของ context ที่ home อยู่มุมมองนี้ (service_marketplace · work_dispatch · reputation) render จาก dataModeling.aggregates ใน graph (v0.4.0, PROP-018) คำอธิบาย invariant ข้างบนคงไว้เพื่อความเข้าใจ; กติกาในส่วนนี้คือสัญญาเชิง transaction ที่ implementation ต้องบังคับใช้ ส่วน persistence ระดับ column ของ entity สมาชิกทุกตัวอยู่ในตระกูล SPEC-ERD พี่น้อง (ดู column ข้อมูล)

service_marketplacework_dispatchreputationServiceRequestคำขอบริการServiceQuoteContractorผู้รับเหมาServiceOfferingMachineWorkOrderใบสั่งงานWorkAssignmentServicePaymentReviewรีวิวEndorsementการรับรอง
Fig. 1 — Consistency boundaries of service_marketplace · work_dispatch · reputation: one box per aggregate — title = root, rows = member entities. Everything inside a box commits in one database transaction; everything between boxes flows through domain events.ภาพที่ 1 — ขอบเขตความสอดคล้องของ service_marketplace · work_dispatch · reputation: หนึ่งกล่องต่อ aggregate — ชื่อกล่อง = root, รายการในกล่อง = entity สมาชิก ทุกอย่างในกล่อง commit ใน database transaction เดียว; ระหว่างกล่องไหลผ่าน domain event
Aggregate rootMembersสมาชิกContextTransaction ruleกติกา transactionDataข้อมูล
ContractorContractor · ServiceOffering · Machinework_dispatchProfile, offerings and machines mutate under the contractor's verification status; rating_avg/rating_count are denormalized from Review events (eventual).โปรไฟล์ บริการ และเครื่องจักรแก้ภายใต้สถานะการยืนยันของผู้รับเหมา; rating_avg/rating_count denormalize จาก Review event (eventual)ERD-CEC
ServiceRequestServiceRequest · ServiceQuoteservice_marketplaceAwarding sets awarded_quote_id and flips winning/losing quote statuses in one transaction.การมอบงานตั้ง awarded_quote_id และสลับสถานะ quote ที่ชนะ/แพ้ใน transaction เดียวERD-CEC
WorkOrderWorkOrder · WorkAssignment · ServicePaymentwork_dispatchTransitions follow the work-order state machine; escrow state changes commit with the order status; verified completion gates review eligibility (FR-55).เปลี่ยนสถานะตาม state machine ของ work order; สถานะ escrow commit พร้อมสถานะงาน; การจบงานที่ยืนยันแล้วเป็นเงื่อนไขให้รีวิวได้ (FR-55)ERD-CEC
ReviewReviewreputationOne review per work order; reply/status only after creation.หนึ่งรีวิวต่อ work order; ตอบกลับ/สถานะแก้ได้หลังสร้างเท่านั้นERD-CEC
EndorsementEndorsementreputationOne endorsement per endorser per contractor per season; revocation is a status change.หนึ่งการรับรองต่อผู้รับรองต่อผู้รับเหมาต่อฤดู; การถอนเป็นการเปลี่ยนสถานะERD-CEC

4. Component lifetime map4. ผัง lifetime ของ component

The DI registration contract for this perspective's contexts, from graph dataModeling.lifecycles — vocabulary singleton | scoped (per request / unit of work) | transient (.NET, per the PROP-005 ASP.NET Core foundation). Platform-wide conventions (DbContext, repositories, handlers, caches, hosted jobs) are stated once in SPEC-DDD and bind here unless a row below overrides them; the rows list the notable components an implementation must wire per context.

สัญญาการลงทะเบียน DI ของ context ในมุมมองนี้ จาก dataModeling.lifecycles ใน graph — ใช้ศัพท์ singleton | scoped (ต่อคำขอ / unit of work) | transient (.NET ตามรากฐาน ASP.NET Core ของ PROP-005) กติการวมทั้ง platform (DbContext, repository, handler, cache, hosted job) ประกาศครั้งเดียวใน SPEC-DDD และมีผลที่นี่เว้นแต่แถวด้านล่างกำหนดต่าง; แถวในตารางคือ component สำคัญที่ implementation ต้องต่อสายราย context

service_marketplace ตลาดบริการ

events producedevent ที่ผลิต OfferingPublished · ServiceRequestOpened · QuoteSubmitted · WorkOrderAwarded · InstantJobBroadcast · InstantJobAccepted · EscrowFunded · EscrowReleased · EscrowRefunded · ServicePaymentPosted

ComponentKindชนิดLifetimeRationaleเหตุผล
ServiceRequest/Quote repositoriesrepositoryscoped—
AwardServiceapp_servicescopedawarded_quote_id + quote status flips in one transaction.ตั้ง awarded_quote_id + สลับสถานะ quote ใน transaction เดียว
ForecastMatcherhosted_servicesingletonM3 matching; scoped unit per run.การจับคู่ M3; scope ต่อรอบทำงาน
InstantDispatchServiceapp_servicescopedจองด่วน M2i path.เส้นทางจองด่วน M2i

work_dispatch การจัดงานภาคสนาม

events producedevent ที่ผลิต ContractorOnboarded · WorkDispatched · WorkProgressLogged · WorkCompleted · WorkVerified · WorkDisputed · DisputeResolved

ComponentKindชนิดLifetimeRationaleเหตุผล
WorkOrderRepositoryrepositoryscoped—
WorkOrderStateGuarddepartment_policysingletonPure work-order state machine.state machine ของ work order แบบ pure
CrewSchedulerapp_servicescoped—
EscrowCoordinatorapp_servicescopedEscrow state commits with order status; four payment rails.สถานะ escrow commit พร้อมสถานะงาน; สี่ช่องทางจ่ายเงิน

reputation ชื่อเสียง

events producedevent ที่ผลิต ReviewPublished · ReviewReplied · EndorsementGranted

ComponentKindชนิดLifetimeRationaleเหตุผล
ReviewRepositoryrepositoryscoped—
RatingAggregatorevent_handlerscopedRecomputes Contractor.rating_avg/rating_count on ReviewPublished (eventual).คำนวณ rating_avg/rating_count ใหม่เมื่อ ReviewPublished (eventual)
VerifiedReviewPolicydepartment_policysingletonOnly verified completions may review (FR-55).เฉพาะงานที่จบและยืนยันแล้วจึงรีวิวได้ (FR-55)

5. Domain events5. เหตุการณ์โดเมน

Eventเหตุการณ์Producerผู้ผลิตConsumersผู้บริโภค
ContractorOnboarded · OfferingPublishedwork_dispatch · service_marketplacewebsite, mobile, portal
ServiceRequestOpened · QuoteSubmitted · WorkOrderAwardedservice_marketplacedispatch, work_dispatch, financing, notifications
InstantJobBroadcast · InstantJobAcceptedservice_marketplacecrew, dispatch, mobile, notifications
EscrowFunded · EscrowReleased · EscrowRefundedservice_marketplacework_dispatch, dispatch, mobile, statements, books
WorkDispatched · WorkProgressLogged · WorkCompletedwork_dispatchcrew, mobile, portal, service_marketplace
WorkVerifiedwork_dispatchservice_marketplace (payment gate), reputation, farm_agronomy, books
WorkDisputed · DisputeResolvedwork_dispatchservice_marketplace, dispatch, mobile, notifications
ServicePaymentPostedservice_marketplacefinancing, books, dispatch, mobile, reports
ReviewPublished · ReviewReplied · EndorsementGrantedreputationservice_marketplace (ranking), website, dispatch
JournalPosted · StatementSharedbooksdispatch, crew, finance (consent-gated)

PaymentPosted (settlement) additionally triggers ServicePaymentPosted when the settled PaymentItem carries a settlement_offset service deduction — the existing event keeps its contract, exactly as PROP-003 did for loan repayments.

PaymentPosted (การปิดงวด) กระตุ้น ServicePaymentPosted เพิ่มเมื่อ PaymentItem ที่ปิดงวดมีการหักค่าบริการแบบ settlement_offset — เหตุการณ์เดิมคงสัญญาเดิม เช่นเดียวกับที่ PROP-003 ทำกับการชำระคืนสินเชื่อ

6. Glossary slice6. ส่วนอภิธาน

ผู้รับเหมา (contractor) · รายการบริการ (service offering) · คำขอบริการ (service request / RFQ) · ใบเสนอราคา (quote) · ใบสั่งงาน (work order) · การจัดคิวงาน (dispatch) · ชุดงาน (crew) · จองด่วน (instant dispatch) · ช่วงราคาอ้างอิง (reference price band) · escrow (บัญชีพักเงิน) · การตรวจรับงาน (work verification) · รีวิวจากงานจริง (verified review) · การรับรอง (endorsement) · อัตราการใช้เครื่องจักร (utilization) · ค่าคอมมิชชัน (take rate) · สมุดบัญชีแยกประเภท (general ledger) · งบกำไรขาดทุน (P&L) · กำไรรายเครื่องจักร (machine profitability). Full definitions: the graph glossary / SPEC-DDD ข้อ 6.

ผู้รับเหมา · รายการบริการ · คำขอบริการ (RFQ) · ใบเสนอราคา · ใบสั่งงาน · การจัดคิวงาน (dispatch) · ชุดงาน (crew) · จองด่วน · ช่วงราคาอ้างอิง · escrow (บัญชีพักเงิน) · การตรวจรับงาน · รีวิวจากงานจริง · การรับรอง · อัตราการใช้เครื่องจักร · ค่าคอมมิชชัน · สมุดบัญชีแยกประเภท · งบกำไรขาดทุน · กำไรรายเครื่องจักร นิยามเต็ม: อภิธานของ graph (กราฟ) / SPEC-DDD ข้อ 6

7. Revision history7. ประวัติการแก้ไข

RevDateวันที่Changeการเปลี่ยนแปลง
1.02026-07-08Initial document — renders the contractor perspective from spec-graph v5.0 (PROP-004 accepted): four contexts, aggregates & invariants, event contracts, glossary slice.ฉบับแรก — เรนเดอร์มุมมองผู้รับเหมาจาก spec-graph v5.0 (PROP-004 อนุมัติ): สี่บริบท แอกกริเกตและกฎคงที่ สัญญาเหตุการณ์ ส่วนอภิธาน
1.12026-07-08PROP-005 (FED, spec v6.0): perspective re-keyed from customer group to capacity (document code unchanged); identity defers to the federation context (Person · Tenant · TenantCapacity · Membership); every *_tenant_type + *_tenant_id pair collapses to tenant_id.PROP-005 (FED, spec (สเปก) v6.0): มุมมองเปลี่ยนคีย์จากกลุ่มลูกค้าเป็น capacity (รหัสเอกสารคงเดิม); อัตลักษณ์อ้างอิงบริบท federation (Person · Tenant · TenantCapacity · Membership); คู่ *_tenant_type + *_tenant_id ทั้งหมดยุบเป็น tenant_id
1.22026-07-09PROP-010 (GL, spec v9.0): the contractor's books widen into a full financial system — new receivables & cash_management contexts (Invoice/Receipt/PaymentVoucher/CashAccount/BankTransaction/Reconciliation) + the books-family ChartTemplate/FiscalPeriod/FinancialStatement; the payer side of ServicePayment now auto-posts uniformly (NFR-24); statements to a bank only via ConsentGrant scope books (NFR-26).PROP-010 (GL, spec v9.0): books ของผู้รับเหมาขยายเป็นระบบการเงินเต็ม — บริบท receivables และ cash_management ใหม่ + ChartTemplate/FiscalPeriod/FinancialStatement; ด้านผู้จ่าย ServicePayment ลงอัตโนมัติเป็นหนึ่งเดียว (NFR-24); งบถึงธนาคารผ่าน ConsentGrant scope books (NFR-26)
0.1.02026-07-11PROP-014 (spec v0.1.0): semantic versioning restarted at 0.1.0 (was Rev 1.2 · 2026-07-09); docnav updated for the gov_cluster split — GOV re-homed to docs/gov/ocsb/, new BOARD (กอน.) sibling added.PROP-014 (spec v0.1.0): รีสตาร์ท semantic versioning ที่ 0.1.0 (เดิม Rev 1.2 · 2026-07-09); ปรับ docnav ตามการแยก gov_cluster — ย้าย GOV ไป docs/gov/ocsb/ เพิ่มพี่น้อง BOARD (กอน.)
0.2.02026-07-13PROP-018 P2 (spec v0.4.0): aggregate map figure + normative aggregate boundaries & transaction rules (Section 3) and the DI component lifetime map (Section 4) for service_marketplace · work_dispatch · reputation — rendered from the graph's dataModeling block (aggregates · lifecycles).PROP-018 P2 (spec v0.4.0): ภาพผัง aggregate + ขอบเขต aggregate และกติกา transaction เชิงบรรทัดฐาน (ข้อ 3) และผัง lifetime ของ component แบบ DI (ข้อ 4) ของ service_marketplace · work_dispatch · reputation — render จาก block dataModeling ใน graph (aggregates · lifecycles)
0.3.02026-08-03PROP-073 (spec v0.47.0): one word — Tenant. Party → Tenant, party_id (and every prefixed form) → tenant_id, PartyCapacity/PartyQualification/PartyFounded → Tenant*, party context/switcher → tenant context/switcher, cross-party → cross-tenant, organisation → organization, and ผู้เล่น retired as the Thai gloss (the Latin word tenant instead, R-THAI). Hold list untouched: counterparty · third party · tripartite working group · Person*/person_id; display codes and token claims were held by R-NULL for one release and then MOVED at v0.47.1 on client decision (C-1), because no token has ever been SIGNED — no auth exists in the built ocsb/ocsf prototypes — and the only printed codes were eight fixture strings in apps/ocsf/fund-shell.jsx, swept in the same pass: PTY- → TNT-, TCA- → TCA-, TQL- → TQL-, claim tnt → tnt, claim dep → dep. Carried in the same pass: the PROP-075 rectification — the retired directory noun domain becomes department (A-82 R-ONETREE) and the dangling A-86/A-87/A-88 citations are re-pointed at the ids they were actually given, A-81/A-82/A-83.PROP-073 (spec v0.47.0): คำเดียว — Tenant Party → Tenant, party_id ทุกรูป → tenant_id, PartyCapacity/PartyQualification/PartyFounded → Tenant*, cross-party → cross-tenant และเลิกใช้ ผู้เล่น เป็นคำแทนวัตถุนี้ในภาษาไทย (ใช้คำละติน tenant ตาม R-THAI) รายการห้ามแตะไม่ถูกแตะ: คู่สัญญา · third party · คณะทำงานไตรภาคี · Person*/person_id รอบเดียวกันแก้ค้างจาก PROP-075: domain → department (A-82) และแก้การอ้าง A-86/A-87/A-88 ที่ไม่มีอยู่จริงเป็น A-81/A-82/A-83
0.3.12026-08-03PROP-073 PATCH 1 (spec v0.47.1 / v0.47.2 / v0.47.3 as applicable): the identifiers v0.47.0 had held, moved on client decision. PTY-######## → TNT-######## · PCA-######## → TCA-######## · PQL-######## → TQL-######## · token claim pty → tnt · token claim dom → dep (v0.47.1, C-1 — R-NULL had held them as a stored VALUE and a wire format; reversed because no token has ever been signed and the only printed codes were fixture strings). quota_org_officer → quota_officer · lead_org_officer → lead_officer (v0.47.2, C-2 — org is organization abbreviated, not a resemblance). The retired role LABEL swept as a phrase family and quota organization naming the tenant → quota group / กลุ่มโควตา (v0.47.3). All retired forms are in the FR-396 crosswalk and refused in new text by NFR-142.PROP-073 PATCH 1 (spec v0.47.1 / v0.47.2 / v0.47.3 ตามที่เกี่ยวข้อง): ตัวระบุที่ v0.47.0 คงไว้ ถูกย้ายตามการตัดสินของลูกค้า PTY- → TNT- · PCA- → TCA- · PQL- → TQL- · claim pty → tnt · claim dom → dep (v0.47.1, C-1) · quota_org_officer → quota_officer · lead_org_officer → lead_officer (v0.47.2, C-2) · ป้ายชื่อบทบาทที่เลิกใช้และ องค์กรโควตา ที่เรียก tenant → กลุ่มโควตา (v0.47.3) ทุกรูปที่เลิกใช้อยู่ในตารางแปลง FR-396