# Master → Template → Program → Registration: Architecture Overview

---

## 1. Who Are the Users?

```
┌─────────────────────────────────────────────────────────────┐
│                        USERS                                │
├───────────────┬─────────────────────────┬───────────────────┤
│  ROLE_ADMIN   │ ROLE_RELATIONAL_MANAGER │   ROLE_VIEWER     │
│               │                         │                   │
│ Creates        │ Manages seekers         │ The Seeker        │
│ everything     │                         │ programs          │
└───────────────┴─────────────────────────┴───────────────────┘
```

--- 

## 2. Single Program Flow (Foundation)

```
┌─────────────────────────────────────────────────────────────┐
│                 LAYER 1: MASTER FIELDS                      │
│            Global question library — set up once            │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   MasterSection                                             │
│     └── MasterQuestion                                      │
│           (Full Name, Age, City, Gender, Payment, DOB …)    │
│                                                             │
└─────────────────────────┬───────────────────────────────────┘
                          │ DEv team created templates
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                 LAYER 2: TEMPLATE                           │
│         Form blueprint — built once per Program Type        │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   ProgramTemplate  (e.g. "Entrainment Template v1")         │
│     └── TemplateSection                                     │
│           └── TemplateQuestion                              │
│                 (copied from Master + customised)           │
│                                                             │
└─────────────────────────┬───────────────────────────────────┘
                          │ Template attached to Program
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                 LAYER 3: PROGRAM                            │
│                One real batch / event                       │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   Program  (e.g. "Entrainment Jan 2026")                    │
│     └── FormSection  ← from Template                        │
│           └── Question  ← from Template                     │
│                 (can reorder / toggle per program)          │
│                                                             │
│   ProgramAccessUserMap                                      │
│     (controls who can VIEW or REGISTER)                     │
│                                                             │
└─────────────────────────┬───────────────────────────────────┘
                          │ Seeker fills the form
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                 LAYER 4: REGISTRATION                       │
│              One record per Seeker per Program              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   ProgramRegistration                                       │
│     ├── userId       → the Seeker (ROLE_VIEWER)             │
│     ├── ownerUserId  → who registered (self or RM)          │
│     ├── rmContact    → RM assigned to this seeker           │
│     └── Answers[]    → questionId + answerValue             │
│                                                             │
└─────────────────────────────────────────────────────────────┘
```

---

## 3. What If There Are 2 Programs? (Same Template, Different Batches)

> **The Template is shared. Each Program gets its own Questions and Registrations.**

```
                    MASTER FIELDS
                  (shared globally)
                         │
                         │
              ┌──────────▼──────────┐
              │   TEMPLATE          │
              │  "Entrainment v1"   │
              └──────┬──────────────┘
                     │ same template used for both
          ┌──────────┴──────────────┐
          │                         │
          ▼                         ▼
┌─────────────────┐       ┌─────────────────────┐
│   PROGRAM A     │       │     PROGRAM B        │
│ Entrainment     │       │  Entrainment         │
│  Jan 2026       │       │   Mar 2026           │
│                 │       │                      │
│ FormSections    │       │  FormSections        │
│ Questions       │       │  Questions           │
│ (own copy)      │       │  (own copy)          │
└────────┬────────┘       └──────────┬───────────┘
         │                           │
    ┌────▼────┐                 ┌────▼────┐
    │  Reg 1  │                 │  Reg 3  │
    │ Seeker A│                 │ Seeker A│  ← same seeker,
    ├─────────┤                 ├─────────┤    different program
    │  Reg 2  │                 │  Reg 4  │
    │ Seeker B│                 │ Seeker C│
    └─────────┘                 └─────────┘
```

### What is isolated per Program:
| Thing | Program A | Program B |
|-------|-----------|-----------|
| Questions (form copy) | Own set | Own set |
| Registrations | Only for Jan batch | Only for Mar batch |
| Seeker answers | Stored separately | Stored separately |
| Access control | Own ProgramAccessUserMap | Own ProgramAccessUserMap |

### What is shared:
| Thing | Shared? |
|-------|---------|
| Master Questions | Yes — global library |
| Template | Yes — both programs reference same template |
| User accounts | Yes — same seeker can register in both |

---

## 4. What If There Are 2 Programs of Different Types?

> **Each Program Type has its own Template. Masters are still shared.**

```
            MASTER FIELDS  (global, one library)
                 │                   │
       ┌─────────▼────┐     ┌────────▼──────────┐
       │  TEMPLATE A  │     │    TEMPLATE B      │
       │  Entrainment │     │    HDB / MSD       │
       │  (5 sections)│     │   (8 sections)     │
       └──────┬───────┘     └────────┬───────────┘
              │                      │
              ▼                      ▼
    ┌──────────────────┐   ┌──────────────────────┐
    │   PROGRAM A      │   │     PROGRAM B         │
    │ Entrainment 2026 │   │    HDB Jan 2026        │
    │                  │   │                        │
    │ - Online form    │   │  - Residential form    │
    │ - Basic details  │   │  - Travel details      │
    │ - Payment        │   │  - Room preference     │
    │                  │   │  - Payment             │
    └────────┬─────────┘   └──────────┬─────────────┘
             │                        │
     ┌───────▼──────┐        ┌────────▼───────┐
     │ Registrations│        │  Registrations │
     │ (own form    │        │  (own form     │
     │  answers)    │        │   answers)     │
     └──────────────┘        └────────────────┘
```

---

## 5. Summary in One Line Per Layer

| Layer | What it is | Created by | Reused? |
|-------|-----------|------------|---------|
| **Master Fields** | Global question library | Admin (one-time) | Yes — across all templates |
| **Template** | Form blueprint for a program type | Admin | Yes — across multiple programs of same type |
| **Program** | A real batch/event | Admin | No — one per batch |
| **Registration** | A seeker's filled form | Seeker / RM | No — one per seeker per program |

---

## 6. Seeker Journey Across 2 Programs

```
Seeker (ROLE_VIEWER)
   │
   ├──► Registers for Program A (Entrainment Jan 2026)
   │         └── Registration #1 created
   │               └── Answers saved for Program A's questions
   │
   └──► Registers for Program B (HDB Jan 2026)
             └── Registration #2 created
                   └── Answers saved for Program B's questions

Same User account. Two separate registrations. Answers never mixed.
```

---

## 7. When Admin Fetches User / Registration Details

> **Admin calls a single API → system joins all layers and returns the full picture.**

### 7a. How the Fetch Works (Data Flow)

```
ADMIN (ROLE_ADMIN)
   │
   │  GET /registration/:id          ← fetch one registration in detail
   │  GET /registration?programId=X  ← list all registrations for a program
   │  GET /registration/:id/questions← fetch seeker's form answers
   │
   ▼
┌─────────────────────────────────────────────────────────────┐
│                   REGISTRATION RECORD                       │
├─────────────────────────────────────────────────────────────┤
│  ProgramRegistration (id, status, registrationSeqNumber)    │
│     │                                                       │
│     ├──► User (seeker)                                      │
│     │      ├── fullName, phone, email, dob, gender          │
│     │      ├── profileExtension (GST, PAN, invoice addr)    │
│     │      └── programExperiences (past programs)           │
│     │                                                       │
│     ├──► Program + ProgramSession                           │
│     │      (which batch this registration belongs to)       │
│     │                                                       │
│     ├──► ownerUserId → User (who registered — self or RM)   │
│     ├──► rmContact   → User (RM assigned to this seeker)    │
│     │                                                       │
│     ├──► PaymentDetails + InvoiceDetails                    │
│     ├──► TravelInfo + TravelPlans                           │
│     ├──► Approvals                                          │
│     ├──► Preferences (preferred program/session)            │
│     ├──► Ratings                                            │
│     ├──► SwapRequests                                       │
│     ├──► Goodies                                            │
│     └──► Recommendation                                     │
└─────────────────────────────────────────────────────────────┘
```

### 7b. When Admin Fetches Form Answers (GET /registration/:id/questions)

```
Registration
   └── RegistrationQuestionAnswer[]
         ├── questionId  ──► Question
         │                     ├── questionText, questionType, answerType
         │                     └── formSection
         │                           └── sectionKey, name
         └── answerValue  (what the seeker filled in)
```

**Result the admin sees:**

```
Section: "Basic Details"
  ├── Full Name          → "Rahul Sharma"
  ├── Date of Birth      → "1990-05-12"
  └── Gender             → "Male"

Section: "Travel Info"
  ├── City of Travel     → "Mumbai"
  └── Mode of Travel     → "Flight"

Section: "Payment"
  └── Amount Paid        → ₹15,000
```

---

### 7c. Admin List View (GET /registration/list-view)

```
Admin Dashboard
   │
   ▼
┌──────────────────────────────────────────────────────────────┐
│  Response Shape                                              │
├──────────────────────────────────────────────────────────────┤
│  data[]          → flat list of registrations                │
│    each row:  name, phone, email, status, city,              │
│               rmName, paymentStatus, registrationDate        │
│                                                              │
│  tableHeaders[]  → column config for UI table                │
│  pagination      → total, limit, offset                      │
│  KPIs[]          → counts (Total / Confirmed / Pending…)     │
│  statusCounts    → breakdown by registration status          │
└──────────────────────────────────────────────────────────────┘
```

---

### 7d. Which Admin Endpoint Does What

| Endpoint | What admin gets | When to use |
| -------- | --------------- | ----------- |
| `GET /registration/:id` | Full detail — user, payment, travel, approvals, all relations | View one seeker's complete record |
| `GET /registration?programId=X` | Paginated list with filters | Quick lookup across registrations |
| `GET /registration/list-view` | Table-ready data + KPIs | Admin dashboard / reporting |
| `GET /registration/basic-list` | Name, phone, email only | Search / autocomplete |
| `GET /registration/:id/questions` | All Q&A answers section-wise | Review what seeker filled in the form |

---

### 7e. Full Picture: Admin View Across 2 Programs

```
ADMIN
  │
  ├── GET /registration?programId=A   → sees all seekers in Program A
  │       Reg 1: Seeker A — Confirmed — ₹10,000 paid
  │       Reg 2: Seeker B — Pending   — Payment due
  │
  └── GET /registration?programId=B   → sees all seekers in Program B
          Reg 3: Seeker A — Confirmed — ₹15,000 paid  ← same seeker
          Reg 4: Seeker C — Waitlist

Same Seeker A appears in both lists — but as two separate registrations
with their own answers, payment, and status in each program.
```

---

## 8. All Registrations of a Single User

> **One user can register for multiple programs. Each registration is independent and carries its own form answers, payment, and travel details.**

### 8a. Structure

```
User
  ├── Registration 1  (Program A — Entrainment Jan 2026)
  │     ├── Form Answers  (questions filled for this program)
  │     ├── Payment Details
  │     ├── Travel Info + Travel Plans
  │     └── Invoice Details
  │
  ├── Registration 2  (Program B — HDB Jan 2026)
  │     ├── Form Answers  (questions filled for this program)
  │     ├── Payment Details
  │     ├── Travel Info + Travel Plans
  │     └── Invoice Details
  │
  └── Registration 3  (Program C — Entrainment Mar 2026)
        ├── Form Answers
        ├── Payment Details
        └── Invoice Details
```

---

### 8b. What Each Registration Holds

#### Registration Card (Core Fields)

| Field | Description |
| ----- | ----------- |
| Registration ID | Unique ID for this registration |
| Registration Number | Human-readable sequence number (e.g. REG-001) |
| Program Name | Which program this is for |
| Program Batch / Session | Which batch/session |
| Registration Status | Confirmed / Pending / Waitlist / Cancelled |
| Registered On | Date of registration |
| Registered By | Self or by RM on seeker's behalf |
| RM Assigned | Relational Manager handling this seeker |
| Seat Allocated | Whether a seat is confirmed |

---

#### Form Answers (Questions as Fields)

Each program has its own set of questions. The seeker fills them during registration. Here is what each answer looks like:

| Question (Field) | Answer |
| ---------------- | ------ |
| Full Name | Rahul Sharma |
| Date of Birth | 12 May 1990 |
| Gender | Male |
| City | Mumbai |
| Mobile Number | +91 98765 43210 |
| Email Address | rahul at example.com |
| Last HDB Attended | HDB 2024 |
| HDB Association Since | 2018 |
| Profile Photo | (uploaded image) |
| … (any custom question from the program's template) | … |

> Every question in the list above is a `Question` record from the program's form.
> Every answer is stored as `RegistrationQuestionAnswer → answerValue` linked to that question.

---

#### Payment Details

| Field | Description |
| ----- | ----------- |
| Payment Status | Paid / Pending / Partially Paid |
| Payment Mode | Online / Offline |
| Amount Paid | ₹ value |
| GST Amount | Tax applied |
| TDS | TDS deducted (if applicable) |
| Payment Date | When payment was made |
| Razorpay ID | Gateway reference |

---

#### Invoice Details

| Field | Description |
| ----- | ----------- |
| Invoice Name | Name on the invoice |
| Invoice Address | Billing address |
| PAN Number | Tax identity |
| Is GST Registered | Yes / No |
| GST Number | GSTIN (if applicable) |
| Invoice Status | Issued / Pending |
| Invoice Date | Date of issue |

---

#### Travel Info

| Field | Description |
| ----- | ----------- |
| ID Type | Aadhar / Passport / Other |
| ID Number | Identity document number |
| T-Shirt Size | (for residential programs) |
| Travel Status | Filled / Pending |

---

#### Travel Plans

| Field | Description |
| ----- | ----------- |
| Travel Type | Flight / Train / Road |
| Airline / Train Name | Carrier name |
| Flight / Train Number | Service number |
| Arrival Date & Time | When reaching venue |
| Departure From | Origin city |
| Check-in Location | Where to check in at venue |
| Check-in Time | Scheduled time |
| Return Travel Type | Mode for return journey |
| Departure Date & Time | When leaving venue |
| Pickup Time & Location | If pickup arranged |

---

### 8c. Full User Registration Timeline (Example)

```
User: Rahul Sharma
─────────────────────────────────────────────────────────────

Registration 1 — Entrainment Jan 2026
  Status     : Confirmed
  Questions answered:
    Full Name        → Rahul Sharma
    City             → Mumbai
    Gender           → Male
    Date of Birth    → 12 May 1990
  Payment    : ₹12,000 paid (Online)
  Travel     : Flight — AI 202 — Arrives 10 Jan 2026 @ 2 PM
  Invoice    : Issued to Rahul Sharma, PAN: ABCDE1234F

Registration 2 — HDB Jan 2026
  Status     : Waitlist (Seat not yet allocated)
  Questions answered:
    Full Name        → Rahul Sharma
    City             → Mumbai
    Last HDB Attended→ HDB 2023
    Room Preference  → Shared
  Payment    : ₹15,000 pending
  Travel     : Not filled yet
  Invoice    : Not issued yet

Registration 3 — Entrainment Mar 2026
  Status     : Cancelled
  Cancelled On: 15 Feb 2026
  Questions answered:
    Full Name        → Rahul Sharma
    City             → Mumbai
  Payment    : Refunded
```

---

## 9. Complete Architecture Diagram

```
╔══════════════════════════════════════════════════════════════════════════════════╗
║                            USERS & ROLES                                        ║
╠══════════════════════════════════════════════════════════════════════════════════╣
║                                                                                  ║
║   ┌─────────────────┐    ┌────────────────────────────┐    ┌─────────────────┐  ║
║   │   ROLE_ADMIN    │    │  ROLE_RELATIONAL_MANAGER   │    │  ROLE_VIEWER    │  ║
║   │                 │    │                            │    │   (Seeker)      │  ║
║   │ Creates master  │    │ Manages seekers            │    │ Registers for   │  ║
║   │ templates       │    │ Registers on their behalf  │    │ programs        │  ║
║   │ programs        │    │                            │    │ Fills forms     │  ║
║   └────────┬────────┘    └──────────────┬─────────────┘    └────────┬────────┘  ║
╚════════════╪══════════════════════════════╪═══════════════════════════╪══════════╝
             │                              │                           │
             ▼                              │                           │
╔════════════════════════════════╗          │                           │
║   LAYER 1: MASTER FIELDS       ║          │                           │
║   (Global — set up once)       ║          │                           │
╠════════════════════════════════╣          │                           │
║                                ║          │                           │
║  MasterSection                 ║          │                           │
║    └── MasterQuestion          ║          │                           │
║          Full Name             ║          │                           │
║          Date of Birth         ║          │                           │
║          Gender                ║          │                           │
║          City                  ║          │                           │
║          Payment               ║          │                           │
║          Travel Preference     ║          │                           │
║          … (any field)         ║          │                           │
╚════════════╤═══════════════════╝          │                           │
             │ Admin selects questions       │                           │
             ▼                              │                           │
╔════════════════════════════════╗          │                           │
║   LAYER 2: TEMPLATE            ║          │                           │
║   (One per Program Type)       ║          │                           │
╠════════════════════════════════╣          │                           │
║                                ║          │                           │
║  ┌─────────────────────────┐   ║          │                           │
║  │  Template A             │   ║          │                           │
║  │  "Entrainment v1"       │   ║          │                           │
║  │   └── Section           │   ║          │                           │
║  │         └── Question    │   ║          │                           │
║  └─────────────────────────┘   ║          │                           │
║                                ║          │                           │
║  ┌─────────────────────────┐   ║          │                           │
║  │  Template B             │   ║          │                           │
║  │  "HDB / MSD v1"         │   ║          │                           │
║  │   └── Section           │   ║          │                           │
║  │         └── Question    │   ║          │                           │
║  └─────────────────────────┘   ║          │                           │
║                                ║          │                           │
╚════════════╤═══════════════════╝          │                           │
             │ Template applied to Program  │                           │
             ▼                              ▼                           │
╔════════════════════════════════════════════════════════════╗          │
║   LAYER 3: PROGRAMS                                         ║          │
║   (One per real batch / event)                              ║          │
╠════════════════════════════════════════════════════════════╣          │
║                                                             ║          │
║  ┌─────────────────────────┐  ┌─────────────────────────┐  ║          │
║  │  Program A              │  │  Program B              │  ║          │
║  │  Entrainment Jan 2026   │  │  Entrainment Mar 2026   │  ║          │
║  │  (uses Template A)      │  │  (uses Template A)      │  ║          │
║  │   └── FormSection       │  │   └── FormSection       │  ║          │
║  │         └── Question    │  │         └── Question    │  ║          │
║  │  ProgramAccessUserMap   │  │  ProgramAccessUserMap   │  ║          │
║  └────────────┬────────────┘  └────────────┬────────────┘  ║          │
║               │                             │               ║          │
║  ┌────────────▼────────────┐  ┌────────────▼────────────┐  ║          │
║  │  Program C              │  │  Program D              │  ║          │
║  │  HDB Jan 2026           │  │  TAT 2026               │  ║          │
║  │  (uses Template B)      │  │  (uses Template C)      │  ║          │
║  │   └── FormSection       │  │   └── FormSection       │  ║          │
║  │         └── Question    │  │         └── Question    │  ║          │
║  └─────────────────────────┘  └─────────────────────────┘  ║          │
╚════════════════════════════════════════════════════════════╝          │
             │  Seeker fills the form (via RM or self)  ◄───────────────┘
             ▼
╔════════════════════════════════════════════════════════════════════════════════╗
║   LAYER 4: REGISTRATIONS  (One per Seeker per Program)                        ║
╠════════════════════════════════════════════════════════════════════════════════╣
║                                                                                ║
║   User: Rahul Sharma                                                           ║
║   │                                                                            ║
║   ├── Registration 1 — Program A (Entrainment Jan 2026) — Confirmed            ║
║   │     ├── Questions & Answers                                                ║
║   │     │     Full Name        → Rahul Sharma                                  ║
║   │     │     City             → Mumbai                                        ║
║   │     │     Gender           → Male                                          ║
║   │     │     Date of Birth    → 12 May 1990                                   ║
║   │     │     … (all questions from Program A's form)                          ║
║   │     ├── Payment            → ₹12,000 paid · Online                         ║
║   │     ├── Invoice            → Issued · PAN: ABCDE1234F                      ║
║   │     └── Travel             → Flight AI-202 · Arrives 10 Jan 2026           ║
║   │                                                                            ║
║   ├── Registration 2 — Program B (Entrainment Mar 2026) — Confirmed            ║
║   │     ├── Questions & Answers                                                ║
║   │     │     Full Name        → Rahul Sharma                                  ║
║   │     │     City             → Mumbai                                        ║
║   │     │     … (all questions from Program B's form)                          ║
║   │     ├── Payment            → ₹12,000 paid · Online                         ║
║   │     ├── Invoice            → Issued                                        ║
║   │     └── Travel             → Train · Arrives 14 Mar 2026                   ║
║   │                                                                            ║
║   └── Registration 3 — Program C (HDB Jan 2026) — Waitlist                    ║
║         ├── Questions & Answers                                                ║
║         │     Full Name        → Rahul Sharma                                  ║
║         │     Last HDB Attended→ HDB 2023                                      ║
║         │     Room Preference  → Shared                                        ║
║         │     … (all questions from Program C's form)                          ║
║         ├── Payment            → ₹15,000 pending                               ║
║         ├── Invoice            → Not issued yet                                ║
║         └── Travel             → Not filled yet                                ║
║                                                                                ║
╚════════════════════════════════════════════════════════════════════════════════╝
             │
             │  Admin views any registration
             ▼
╔════════════════════════════════════════════════════════════════════════════════╗
║   ADMIN VIEW                                                                   ║
╠════════════════════════════════════════════════════════════════════════════════╣
║                                                                                ║
║   List View  →  All seekers for a program                                      ║
║                   Name · Phone · Status · Payment · RM · Registered On         ║
║                   + KPIs (Total / Confirmed / Pending / Waitlist)              ║
║                                                                                ║
║   Detail View → One seeker's full record                                       ║
║                   User info · All Q&A answers · Payment · Invoice              ║
║                   Travel info · Travel plans · Approvals · Ratings             ║
║                   Swap requests · Goodies · Recommendations · RM               ║
║                                                                                ║
╚════════════════════════════════════════════════════════════════════════════════╝
```

---

### Key Relationships at a Glance

```text
MasterQuestion  ──(referenced by)──►  TemplateQuestion
TemplateQuestion ──(instantiated as)──► Question  (per Program)
Question        ──(answered in)──────► RegistrationQuestionAnswer
Registration    ──(belongs to)───────► User  +  Program
Program         ──(uses)─────────────► Template
Template        ──(built from)───────► MasterSection / MasterQuestion
```
