# Entity Relationship Diagram (ERD) — SCMS

## Supply Chain Management System for SupplyNet Ltd

---

## Entities and Attributes

### 1. SUPPLIER
| Attribute      | Type         | Key |
|----------------|--------------|-----|
| supplierCode   | VARCHAR(20)  | PK  |
| supplierName   | VARCHAR(100) |     |
| telephone      | VARCHAR(20)  |     |
| address        | VARCHAR(255) |     |
| email          | VARCHAR(100) |     |

### 2. SHIPMENT
| Attribute       | Type         | Key |
|-----------------|--------------|-----|
| shipmentNumber  | VARCHAR(20)  | PK  |
| shipmentDate    | DATE         |     |
| shipmentStatus  | ENUM         |     |
| destination     | VARCHAR(255) |     |
| supplierCode    | VARCHAR(20)  | FK → Supplier |

### 3. DELIVERY
| Attribute         | Type        | Key |
|-------------------|-------------|-----|
| deliveryCode      | VARCHAR(20) | PK  |
| deliveryDate      | DATE        |     |
| quantityDelivered | INT         |     |
| deliveryStatus    | ENUM        |     |
| shipmentNumber    | VARCHAR(20) | FK → Shipment |

### 4. USER (Authentication)
| Attribute | Type         | Key |
|-----------|--------------|-----|
| id        | INT          | PK  |
| username  | VARCHAR(50)  | UK  |
| password  | VARCHAR(255) |     |

---

## Relationships

```
┌─────────────────┐         1         N         ┌─────────────────┐
│    SUPPLIER     │◄─────────────────────────────│    SHIPMENT     │
│                 │    supplies / has many       │                 │
│ PK: supplierCode│                              │ PK: shipmentNum │
└─────────────────┘                              │ FK: supplierCode│
                                                 └────────┬────────┘
                                                          │
                                                          │ 1
                                                          │
                                                          │ has many
                                                          │ N
                                                 ┌────────▼────────┐
                                                 │    DELIVERY     │
                                                 │                 │
                                                 │ PK: deliveryCode│
                                                 │ FK: shipmentNum │
                                                 └─────────────────┘
```

### Cardinalities

| Relationship              | Cardinality | Description                                      |
|---------------------------|-------------|--------------------------------------------------|
| Supplier → Shipment       | **1 : N**   | One supplier can have many shipments             |
| Shipment → Delivery       | **1 : N**   | One shipment can have many deliveries            |

### Relationship Symbols (Chen / Crow's Foot notation)

- **Supplier — Shipment**: One-to-Many (1:N)
  - One supplier supplies zero or more shipments
  - Each shipment belongs to exactly one supplier

- **Shipment — Delivery**: One-to-Many (1:N)
  - One shipment has zero or more deliveries
  - Each delivery belongs to exactly one shipment

---

## ERD Diagram (Mermaid — for draw.io / Lucidchart reference)

```mermaid
erDiagram
    SUPPLIER ||--o{ SHIPMENT : "supplies"
    SHIPMENT ||--o{ DELIVERY : "has"

    SUPPLIER {
        varchar supplierCode PK
        varchar supplierName
        varchar telephone
        varchar address
        varchar email
    }

    SHIPMENT {
        varchar shipmentNumber PK
        date shipmentDate
        enum shipmentStatus
        varchar destination
        varchar supplierCode FK
    }

    DELIVERY {
        varchar deliveryCode PK
        date deliveryDate
        int quantityDelivered
        enum deliveryStatus
        varchar shipmentNumber FK
    }

    USER {
        int id PK
        varchar username UK
        varchar password
    }
```

---

## How to Draw on Paper (Exam Step 1)

1. Draw three rectangles: **SUPPLIER**, **SHIPMENT**, **DELIVERY**
2. Write attributes inside each rectangle; underline primary keys (PK)
3. Draw a line from SUPPLIER to SHIPMENT with:
   - "1" near Supplier side
   - "N" (many) near Shipment side
4. Draw a line from SHIPMENT to DELIVERY with:
   - "1" near Shipment side
   - "N" near Delivery side
5. Mark `supplierCode` as FK in Shipment, `shipmentNumber` as FK in Delivery

## Digital Tools

Recreate this diagram using:
- [draw.io](https://app.diagrams.net/)
- Lucidchart
- Edraw Max

Use **Crow's Foot notation** for cardinalities as required by the exam.
