# Standalone Architecture - Ordio Loop Affiliate Partner System

**Last Updated:** 2026-01-30

Complete documentation of the standalone architecture decision and implementation for the Ordio Loop affiliate partner system.

## Overview

The affiliate partner system is completely separated from the main marketing website, functioning as its own standalone product. This architectural decision provides significant benefits in terms of maintainability, performance, and code clarity.

## Why Standalone Architecture?

### Benefits

1. **Separation of Concerns**
   - Partner system is independent from marketing site
   - Changes to marketing site don't affect partner pages
   - Clear boundaries between systems

2. **Performance**
   - No unnecessary scripts/styles loading
   - Faster page load times
   - Reduced bundle sizes

3. **Maintainability**
   - Easier to update partner system without affecting main site
   - No conflicts between marketing and partner code
   - Cleaner codebase

4. **Security**
   - No tracking scripts in partner dashboard
   - Reduced attack surface
   - Better privacy for partners

5. **Future-Proof**
   - Can evolve independently
   - Easier to migrate or refactor
   - Clear upgrade paths

## Architecture Components

### Standalone Head Section

**File:** `v2/base/affiliate-head.php`

The standalone head section includes only what's necessary for partner pages:

**Included:**
- Essential meta tags (charset, viewport, robots)
- Favicon links
- Font preloads (Inter, Gilroy) - minimal set
- Font face definitions with `font-display: swap`
- Minimal CSS reset
- `affiliate-dashboard.css` (automatically included)
- Optional Chart.js (if `$chartJs = "true"`)
- Optional Alpine.js (if `$alpineJs = "true"`)

**Excluded (Separated from Marketing Site):**
- Google Analytics / HubSpot tracking scripts
- AOS animations library
- Swiper carousel library
- Tailwind CSS
- Marketing site critical CSS
- Service worker registration
- SEO meta tags (hreflang, canonical)
- DNS prefetch for marketing resources
- Alpine.js mobile navigation scripts

### Usage Pattern

```php
<!DOCTYPE html>
<html lang="de">
<head>
    <title>Page Title - <?php echo AFFILIATE_PROGRAM_NAME; ?></title>
    <meta name="robots" content="noindex, nofollow">
    
    <?php
    // Optional: Enable Chart.js for dashboard pages with charts
    $chartJs = "true"; // or "false" (default)
    
    // Optional: Enable Alpine.js if needed for interactivity
    $alpineJs = "false"; // or "true" (default: false)
    
    include '../base/affiliate-head.php';
    ?>
    
    <!-- Page-specific styles can go here -->
    <style>
        /* Custom styles */
    </style>
</head>
<body>
    <!-- Page content -->
</body>
</html>
```

## Pages Using Standalone Architecture

### Partner Dashboard Pages (All Standalone)

- `partner-dashboard.php` - Main dashboard (uses Chart.js)
- `partner-leads.php` - Leads management
- `partner-earnings.php` - Earnings overview (uses Chart.js)
- `partner-referral-urls.php` - URL generation
- `partner-leaderboard.php` - Leaderboard
- `partner-settings.php` - Settings
- `partner-login.php` - Login page
- `partner-register.php` - Registration form
- `partner-reset-password.php` - Password reset

### Pages Keeping Marketing Integration

- `partner-program.php` - Public marketing landing page
  - Uses `base/head.php` (marketing site head)
  - Includes header and footer
  - Uses marketing site styles and scripts
  - This is intentional - it's a public-facing marketing page

## CSS Architecture

### Partner platform CSS files

All partner pages use **minified** CSS (`.min.css`) with `filemtime()` for cache busting. Run `npm run minify` after editing any `v2/css/affiliate-*.css`.

| File | Loaded | Purpose |
|------|--------|---------|
| `affiliate-shared.min.css` | `affiliate-head.php` | Design tokens, sidebar, cards, tables, buttons, empty/loading states, responsive breakpoints |
| `affiliate-dashboard.min.css` | `affiliate-head.php` | Dashboard page overrides |
| `affiliate-levels.min.css` | `partner-levels.php` (customHead) | Levels page only |
| `affiliate-referral-urls.min.css` | `partner-referral-urls.php` (customHead) | Referral URLs page (UTM form, sitemap table) |

- No Tailwind dependencies; self-contained styles; responsive without external frameworks.
- Minimal CSS reset and font definitions are inline in `affiliate-head.php`.
- **Page-specific styles use dedicated CSS files**, not inline `<style>` blocks (except minimal one-offs where necessary).

## JavaScript Architecture

### Standalone JavaScript

**File:** `v2/js/affiliate-dashboard.js`

- Vanilla JavaScript (no framework dependencies)
- Chart.js integration (loaded via CDN when needed)
- No Alpine.js dependencies (despite comment mentioning it)
- No marketing site script dependencies

### Chart.js Integration

Chart.js is loaded conditionally via `affiliate-head.php`:

```php
<?php
$chartJs = "true"; // Enable Chart.js
include '../base/affiliate-head.php';
?>
```

The Chart.js library is then available globally for use in dashboard pages.

## Dependencies

### Required Dependencies

- **PHP:** Server-side processing
- **Fonts:** Inter (400, 500, 600), Gilroy (700)
- **CSS:** `affiliate-dashboard.css` (standalone styles)

### Optional Dependencies

- **Chart.js:** For dashboard charts (loaded from CDN when `$chartJs = "true"`)
- **Alpine.js:** For interactivity (loaded when `$alpineJs = "true"`, currently unused)

### No Dependencies On

- Tailwind CSS
- AOS animations
- Swiper carousel
- Google Analytics
- HubSpot tracking scripts
- Marketing site CSS/JS
- Service workers

## Migration Guide

### For New Partner Pages

When creating a new partner page:

1. **Use Standalone Head:**
   ```php
   <?php include '../base/affiliate-head.php'; ?>
   ```

2. **Don't Include Marketing Head:**
   ```php
   // ❌ DON'T DO THIS
   include '../base/head.php';
   ```

3. **Don't Include Header/Footer:**
   ```php
   // ❌ DON'T DO THIS
   include '../base/header.php';
   include '../base/footer.php';
   ```

4. **Use Standalone CSS:**
   ```php
   // ✅ CSS is automatically included via affiliate-head.php
   // Add page-specific styles inline if needed
   ```

5. **Enable Chart.js Only If Needed:**
   ```php
   <?php
   $chartJs = "true"; // Only if page has charts
   include '../base/affiliate-head.php';
   ?>
   ```

### For Existing Pages

To migrate an existing partner page to standalone:

1. Replace `include '../base/head.php'` with `include '../base/affiliate-head.php'`
2. Remove `$aosScript` and `$swiperScript` variables (not needed)
3. Remove header/footer includes (if present)
4. Remove manual Chart.js script tag (if using `$chartJs = "true"`)
5. Remove manual CSS link for `affiliate-dashboard.css` (automatically included)
6. Test page functionality
7. Verify no console errors
8. Check visual appearance

## Testing Checklist

When creating or updating partner pages:

- [ ] Page uses `affiliate-head.php` (not `base/head.php`)
- [ ] No header/footer includes
- [ ] No `$aosScript` or `$swiperScript` variables
- [ ] Chart.js enabled only if needed (`$chartJs = "true"`)
- [ ] No manual CSS links (handled by `affiliate-head.php`)
- [ ] No console errors
- [ ] No missing resources (404s)
- [ ] Visual appearance correct
- [ ] Responsive design works
- [ ] All functionality works

## Performance Considerations

### Font Loading

- Fonts are preloaded for better performance
- `font-display: swap` ensures text is visible immediately
- Only necessary font weights are loaded

### CSS Loading

- CSS is loaded synchronously (critical for rendering)
- No additional HTTP requests for styles
- Inline styles reduce render-blocking

### JavaScript Loading

- Chart.js loaded from CDN (cached across sites)
- JavaScript is deferred where possible
- No blocking scripts

## Security Considerations

### No Tracking Scripts

- Partner dashboard has no tracking scripts
- Better privacy for partners
- Reduced data collection

### No External Dependencies (Except CDN)

- Chart.js from CDN (trusted source)
- No third-party tracking
- Reduced attack surface

## Maintenance

### Updating Styles

- Update `affiliate-dashboard.css` for shared styles
- Update inline styles in pages for page-specific styles
- No need to worry about Tailwind or marketing site CSS

### Adding New Features

- Add JavaScript to `affiliate-dashboard.js` or page-specific scripts
- No conflicts with marketing site scripts
- Easier to test and debug

### Updating Dependencies

- Chart.js version updated in `affiliate-head.php`
- No need to update marketing site
- Independent version management

## Related Documentation

- **[Architecture](./ARCHITECTURE.md)** - Complete system architecture
- **[Dashboard Guide](./DASHBOARD_GUIDE.md)** - Dashboard usage
- **[Partner Guide](./PARTNER_GUIDE.md)** - User guide
- **[API Reference](./API_REFERENCE.md)** - API endpoints
- **[Cursor Rules](../../../.cursor/rules/affiliate-dashboard.mdc)** - Development patterns

## Future Considerations

### Potential Enhancements

1. **CSS Minification:** Minify `affiliate-dashboard.css` for production
2. **JavaScript Bundling:** Bundle JavaScript if it grows significantly
3. **Component Library:** Create reusable components if patterns emerge
4. **Design System:** Formalize design tokens if system grows

### Migration Paths

- Can easily migrate to separate subdomain if needed
- Can integrate with different frontend framework if desired
- Can add build process if complexity increases
