# Task D.5.1: Lead Foundation Stabilization & Output Completion

## Status

Planned

## Objective

Complete and stabilize the Lead Foundation introduced by Task D.5 Phase 1.

This task must not recreate existing schema objects that already exist.

The objective is to:

* verify completed D.5 foundation work
* document missing outputs
* complete missing seeds
* complete foundation registration
* establish migration verification
* prepare the platform for D.5.2 Lead API Foundation

---

# Mandatory Review

Review:

* AGENTS.md
* Project Foundations Registry
* Task Catalog
* ADR-0018 Lead / Enquiry Domain Separation
* Existing D.5 implementation summary
* Current schema.ts
* Current migration history
* Current seed files

---

# Required Historical Verification

Before writing any code verify whether the following already exist:

## Schema

```txt
crm_leads
crm_enquiries.lead_id
```

---

## ADR

```txt
ADR-0018
```

---

## Seed Categories

```txt
crm_lead_awareness
crm_lead_status
crm_lead_followup_status
crm_lead_lost_reason
```

---

## Document Sequences

```txt
crm_lead
crm_enquiry
```

---

# Rule

If an item already exists:

```txt
DO NOT recreate it
DO NOT generate duplicate migrations
DO NOT rename existing objects
```

Document the existing implementation instead.

---

# Scope D5.1.1 Foundation Audit

Create a verification report.

Document:

```txt
What already exists
What is missing
What is partially implemented
```

---

# Scope D5.1.2 Seed Completion

Verify all Lead master options exist.

Missing options only:

```txt
create missing records
```

Existing options:

```txt
leave unchanged
```

---

# Scope D5.1.3 Document Sequence Audit

Verify:

```txt
crm_lead
crm_enquiry
```

exist in document sequence configuration.

If missing:

```txt
add only missing configuration
```

---

# Scope D5.1.4 Foundation Registration

Update:

```txt
docs/standards/project-foundations.md
```

Add:

```txt
Lead Foundation
```

Purpose:

Marketing-owned lead domain.

---

# Scope D5.1.5 Task Catalog Registration

Update:

```txt
docs/standards/task-catalog.md
```

Register:

```txt
Task D.5
Task D.5.1
```

---

# Scope D5.1.6 Output Documentation

Create:

```txt
docs/implementation/task-d51-lead-foundation-stabilization.md
```

Document:

* schema created
* seeds created
* sequence configuration
* compatibility status

---

# Scope D5.1.7 Compatibility Verification

Verify:

Current CRM still works:

```txt
Customer
Contact
Enquiry
Quotation
Dashboard
Reports
```

No behavior changes allowed.

---

# Deliverables

## New Documentation

* task-d51-lead-foundation-stabilization.md

---

## Updated Documentation

* project-foundations.md
* task-catalog.md

---

## Verification Output

Produce:

### Existing Foundation

```txt
crm_leads
crm_enquiries.lead_id
ADR-0018
```

### Missing Foundation

```txt
...
```

### Completed Foundation

```txt
...
```

---

# Explicit Non-Scope

Do NOT:

* create Lead APIs
* create Lead UI
* create Lead Assignment workflow
* migrate records
* update dashboard datasets
* update report datasets
* remove pipeline_stage

Those belong to D.5.2+

---

# Definition of Done

Task is complete when:

* no duplicate schema is created
* existing D.5 work is audited
* missing seed/configuration is completed
* foundation registry is updated
* task catalog is updated
* D.5 foundation state is documented

Result:

Lead Foundation = Stabilized

Lead Foundation Outputs = Recorded

Ready for D.5.2 Lead API Foundation
