# Projects/Manuals Architecture Analysis

## Current Structure

### 1. Data Organization
The plugin organizes educational content into three layers:

#### Layer 1: Manuals/Paths (Categories)
- Defined in `core.php::wp4t_get_manuals_by_type()`
- Two groups:
  - **Pathways Program** (10 active paths with 5 levels each): Dynamic Leadership, Effective Coaching, Engaging Humor, etc.
  - **Legacy Manuals** (optional, behind `show_legacy_manuals` setting): Traditional Toastmasters manuals

#### Layer 2: Levels (Subcategories)
- Pathways: 5 levels per path (e.g., "Level 1 Mastering Fundamentals" through "Level 5 Demonstrating Expertise")
- Legacy: Single level per manual
- **The Problem**: Successful Club, Better Speaker, and Leadership Excellence series don't fit neatly here

#### Layer 3: Projects (Individual items)
- Defined in `projects_array.php`
- Currently organized as:
  - Static arrays (lines 363-460): Old series with fixed indices
  - Dynamic loop (lines 3302-3345): Generates manual-specific projects by iterating through manuals

### 2. React Frontend Flow
```
ProjectChooser.js (React component)
  ↓ Fetches: rsvptm/v1/paths_and_projects
  ↓
api.php::WP4T_Paths_and_Projects::handle()
  ↓ Calls: wp4t_program()
  ↓
api.php::wp4t_program()
  ↓ Calls: wp4t_get_manuals_by_type()
  ↓ Calls: wp4t_get_projects_array()
  ↓
Returns: $program array with structure:
  {
    "paths": [...],
    "manuals": { "Path Name": [{label, value}] },
    "projects": { "Manual Name": [{label, value}] },
    "maxtime": {...},
    "display_time": {...}
  }
```

### 3. Project Key Format
Projects are keyed as: `"{ManualName} {ProjectName} {OptionalIndex}"`

Examples:
- `"Dynamic Leadership Level 1 Mastering Fundamentals 5"` → "Evaluation and Feedback - First Speech"
- `"BETTER SPEAKER SERIES 0"` → "Beginning Your Speech"
- `"BETTER SPEAKER SERIES 4"` → "Selecting Your Topic"

The React component extracts the manual name via regex: `preg_replace('/([\s0-9]+)$/', '', $key)`

## Current Problems

### Problem 1: Series Don't Fit 5-Level Structure
The three series (Successful Club, Better Speaker, Leadership Excellence) have:
- 7-11 individual projects each
- No logical "levels" structure
- Currently grouped under manual names that DON'T appear in `wp4t_get_manuals_by_type()`

### Problem 2: Series Not Appearing in Dropdown
Because they're not in `wp4t_get_manuals_by_type()`, they never appear in:
- The "paths" dropdown
- The "manuals" dropdown for that path
- Therefore, their projects don't populate in the projects dropdown

### Problem 3: Manual Name Parsing Issues
The regex extraction assumes manual names follow patterns like:
- `"{PathName} Level {N} {LevelName}"`
- `"{ManualName} {Count}"`

But the series keys don't match this pattern consistently, causing extraction failures.

### Problem 4: Data Organization Inconsistency
- Pathways data: Organized hierarchically in `wp4t_get_manuals_by_type()`
- Legacy series data: Only in static/dynamic arrays in `projects_array.php`
- No unified metadata structure for time, difficulty, etc.

## Recommended Solutions

### OPTION A: Create "Series Track" as a Special Category (RECOMMENDED)
**Status**: Adds a new organizational layer without breaking existing structure

#### Structure:
```php
// In wp4t_get_manuals_by_type():
'Series Track' => array(
    'Better Speaker Series' => 'Better Speaker Series',
    'Successful Club Series' => 'Successful Club Series',
    'Leadership Excellence Series' => 'Leadership Excellence Series',
)
```

#### Advantages:
- ✅ Preserves Pathways structure completely
- ✅ No changes to legacy manual handling
- ✅ All three series become discoverable via frontend dropdown
- ✅ Matches UI expectations (Path → Level → Project)
- ✅ No breaking changes to existing project keys
- ✅ Simple to implement (~10 lines of code change)

#### Disadvantages:
- Series are presented as "Level 1 Category" in the UI, which may confuse users
- Still doesn't perfectly capture the "series" concept semantically

#### Implementation:
1. Add "Series Track" category to `wp4t_get_manuals_by_type()` with 3 "levels"
2. Update `projects_array.php` dynamic loop to ensure series projects are keyed correctly
3. No REST API changes needed

---

### OPTION B: Create Metadata Structure (Complex, Future-Proof)
**Status**: Significant refactor, more maintainable long-term

#### Structure:
Replace key-value projects with rich objects:
```php
$projects = array(
    'manual' => array(
        'name' => 'BETTER SPEAKER SERIES',
        'type' => 'series', // or 'pathways', 'legacy'
        'items' => array(
            array('index' => 0, 'name' => 'Beginning Your Speech', 'duration' => 15),
            array('index' => 1, 'name' => 'Concluding Your Speech', 'duration' => 15),
            // ...
        )
    )
);
```

#### Advantages:
- ✅ Clean semantic representation
- ✅ Extensible for future fields (difficulty level, prerequisites, etc.)
- ✅ Easier to add new project types without hacks
- ✅ Better for API/data contracts
- ✅ Solves manual name parsing issues

#### Disadvantages:
- ❌ Breaking change to all code consuming `$projects` (projectChooser, agenda, etc.)
- ❌ Requires updates to ~5-10 PHP files
- ❌ Requires updates to React components (ProjectChooser, EvaluationProjectChooser)
- ❌ Database lookups and cache invalidation needed
- ❌ 1-2 days work

#### Implementation:
Not recommended at this time due to scope.

---

### OPTION C: Treat Series as Special "Paths" (Hacky)
**Status**: Quick fix, but not semantically correct

Add series directly to paths in `wp4t_get_manuals_by_type()` without level structure:
```php
'Better Speaker Series' => array(
    'Better Speaker Series 0' => 'Beginning Your Speech',
    'Better Speaker Series 1' => 'Concluding Your Speech',
    // ...
)
```

#### Advantages:
- ✅ Very quick to implement
- ✅ Works immediately

#### Disadvantages:
- ❌ Series show as "paths" in UI, confusing users
- ❌ No "level" grouping in dropdowns
- ❌ Inconsistent with actual Pathways structure
- ❌ Semantic mismatch

---

### OPTION D: Create Separate "Series" Dropdown (UI Redesign)
**Status**: Best UX, requires frontend changes

Modify React form to have three parallel dropdown categories:
1. "Pathways" (existing)
2. "Legacy Manuals" (existing, optional)
3. "Series Programs" (new)

#### Advantages:
- ✅ Perfect semantic clarity
- ✅ Best user experience
- ✅ No hacks or workarounds

#### Disadvantages:
- ❌ Requires React component changes
- ❌ More complex frontend logic
- ❌ API response structure changes
- ❌ 4-6 hours work

---

## Recommendation: Use OPTION A

**Why Option A:**
1. **Minimal code changes**: ~10 lines in `wp4t_get_manuals_by_type()`
2. **No breaking changes**: All existing projects continue to work
3. **Solves the immediate problem**: Series appear in dropdown
4. **Preserves legacy handling**: Optional `show_legacy_manuals` still works
5. **Path for improvement**: Can iterate to Option D later if needed
6. **Maintains data consistency**: Projects already keyed correctly in `projects_array.php`

**Implementation Steps:**
1. Add "Series Track" entry to `wp4t_get_manuals_by_type()` in core.php
2. Verify that series projects in projects_array.php are correctly keyed
3. Test dropdown displays all three series
4. Test project selection works correctly for each series

**Future Improvements** (can be done separately):
- Rename "Series Track" to something better in settings
- Create specialized UI for series if needed (Option D)
- Migrate to metadata structure when business logic stabilizes (Option B)

---

## Files to Modify (Option A)
1. **core.php** (1 change):
   - Add "Series Track" to `wp4t_get_manuals_by_type()`

2. **projects_array.php** (verify existing):
   - Confirm series projects are in the dynamic loop
   - Ensure keys match expected format

3. **Verify no additional changes needed** (due to existing structure):
   - `api.php::wp4t_program()` should handle it automatically
   - React components should work without changes
