# Article Relationship Model & Integrity Specification

## 1. Domain Entities & Cardinalities

```
+-----------------------+          1:N          +-----------------------+
|        Issue          |<----------------------|        Article        |
| (جلد، شمارہ، پی ڈی ایف)|                      | (مضمون / مقالہ / نظم) |
+-----------------------+                       +-----------------------+
            ^                                               |
            |                                      N:1      |       N:1
            | N:1                                           v        v
+-----------------------+                      +----------------+  +----------------+
|      Publication      |                      | EditorialSection|  |     Author     |
| (ماہنامہ حیاتِ نو)    |                      | (حرف آغاز، فکر) |  | (مصنف / قلم کار)|
+-----------------------+                      +----------------+  +----------------+
                                                        |                  |
                                                        v N:M              v
                                               +----------------+  +----------------+
                                               |     Topic      |  |  Legacy WP Post|
                                               | (موضوعات / ٹیگز)|  | (161 اصل ریکارڈ)|
                                               +----------------+  +----------------+
```

---

## 2. Entity Schema Contracts

### 2.1 Article (`src/types/index.ts`)
```typescript
export interface Article {
  id: string;                 // e.g. "art-1782" (art-{wpPostId})
  slug: string;               // e.g. "social-media-aur-tehzeebi-yalghar"
  titleUrdu: string;          // Full normalized Urdu title
  subtitleUrdu?: string;      // Optional explanatory subtitle
  authorId: string;           // Foreign Key -> Author.id
  authorNameUrdu: string;     // Denormalized for display resilience
  authorAffiliation?: string; // e.g. "جامعۃ الفلاح / علی گڑھ"
  issueId: string;            // Foreign Key -> Issue.id
  issueTitleUrdu: string;     // Denormalized issue title
  sectionId: string;          // Foreign Key -> EditorialSection.id
  sectionNameUrdu: string;    // Denormalized section title
  topicIds: string[];         // Foreign Keys -> Topic.id[]
  publicationDate: string;    // ISO "YYYY-MM" or "YYYY-MM-DD"
  readingTimeMinutes: number; // Computed based on 180 words/min
  excerptUrdu: string;        // 1-2 sentence lead summary
  bodyUrdu: string;           // Full clean Urdu prose (semantic paragraphs)
  quranicVerses?: Verse[];    // Structured Arabic + Urdu + Surah:Ayah
  poetryCouplets?: Couplet[]; // Metrical couplets [Misra 1, Misra 2]
  footnotes?: Footnote[];     // Numbered citations and scholarly references
  featuredMedia?: Media;      // Calligraphic header or portrait
  pdfResource?: Resource;     // Direct offprint PDF if available
  isFeatured?: boolean;       // Curated showcase flag
}
```

---

## 3. Relational Foreign Key Integrity Constraints

1. **Issue Referential Integrity**: Every `article.issueId` MUST match an existing `issue.id` in `issuesData`.
2. **Author Referential Integrity**: Every `article.authorId` MUST match an existing `author.id` in `authorsData`.
3. **Section Referential Integrity**: Every `article.sectionId` MUST match an existing `section.id` in `editorialSectionsData`.
4. **Unique Slug Constraint**: Article, Issue, Section, and Author slugs MUST be globally unique within their namespace.
5. **No Broken Links**: Cross-references rendered in templates MUST only link to valid routes.

---

## 4. Current Integrity Audit Status
- **Articles Verified**: 34
- **Broken Issue Foreign Keys**: 0
- **Broken Author Foreign Keys**: 0
- **Broken Section Foreign Keys**: 0
- **Integrity Assertion**: PASSED (Verified via compile-time TypeScript checks and schema validation).
