docs: update documentation for /platforms/ URL routing strategy
- Add multi-platform URL routing section to url-routing/overview.md - Update multi-platform-cms.md with new request flow diagrams - Add PlatformContextMiddleware documentation to middleware.md - Update middleware execution order diagram - Add Phase 7 (Platform URL Routing Strategy) to implementation plan - Update platform URL summary tables across all docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,61 @@ This middleware layer is **system-wide** and enables the multi-tenant architectu
|
||||
|
||||
## Middleware Components
|
||||
|
||||
### 1. Logging Middleware
|
||||
### 1. Platform Context Middleware
|
||||
|
||||
**Purpose**: Detect which platform (OMS, Loyalty, Main) the request is for
|
||||
|
||||
**What it does**:
|
||||
- Detects platform from:
|
||||
- Custom domain (e.g., `oms.lu`, `loyalty.lu`)
|
||||
- Path prefix in development (e.g., `/platforms/oms/`, `/platforms/loyalty/`)
|
||||
- Default to `main` platform for localhost without prefix
|
||||
- Rewrites path for platform-prefixed requests (strips `/platforms/{code}/`)
|
||||
- Queries database to find platform by domain or code
|
||||
- Injects platform object into `request.state.platform`
|
||||
|
||||
**URL Detection Logic**:
|
||||
```
|
||||
Request arrives
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────┐
|
||||
│ Production domain? (oms.lu, etc.) │
|
||||
└─────────────────────────────────────┘
|
||||
│ YES → Use that platform
|
||||
│
|
||||
▼ NO (localhost)
|
||||
┌─────────────────────────────────────┐
|
||||
│ Path starts with /platforms/{code}? │
|
||||
└─────────────────────────────────────┘
|
||||
│ YES → Strip prefix, use platform
|
||||
│ /platforms/oms/pricing → /pricing
|
||||
│
|
||||
▼ NO
|
||||
┌─────────────────────────────────────┐
|
||||
│ Use 'main' platform (DEFAULT) │
|
||||
│ Path unchanged │
|
||||
└─────────────────────────────────────┘
|
||||
```
|
||||
|
||||
**Example**:
|
||||
```
|
||||
Request: https://localhost:9999/platforms/oms/pricing
|
||||
↓
|
||||
Middleware detects: platform_code = "oms"
|
||||
↓
|
||||
Rewrites path: /platforms/oms/pricing → /pricing
|
||||
↓
|
||||
Queries database: SELECT * FROM platforms WHERE code = 'oms'
|
||||
↓
|
||||
Injects: request.state.platform = <Platform object>
|
||||
```
|
||||
|
||||
**Why it's critical**: Without this, the system wouldn't know which platform's content to serve
|
||||
|
||||
**Configuration**: Runs BEFORE VendorContextMiddleware (sets platform context first)
|
||||
|
||||
### 2. Logging Middleware
|
||||
|
||||
**Purpose**: Request/response logging and performance monitoring
|
||||
|
||||
@@ -221,13 +275,14 @@ from middleware import context_middleware
|
||||
```mermaid
|
||||
graph TD
|
||||
A[Client Request] --> B[1. LoggingMiddleware]
|
||||
B --> C[2. VendorContextMiddleware]
|
||||
C --> D[3. ContextDetectionMiddleware]
|
||||
D --> E[4. ThemeContextMiddleware]
|
||||
E --> F[5. FastAPI Router]
|
||||
F --> G[Route Handler]
|
||||
G --> H[Response]
|
||||
H --> I[Client]
|
||||
B --> C[2. PlatformContextMiddleware]
|
||||
C --> D[3. VendorContextMiddleware]
|
||||
D --> E[4. ContextDetectionMiddleware]
|
||||
E --> F[5. ThemeContextMiddleware]
|
||||
F --> G[6. FastAPI Router]
|
||||
G --> H[Route Handler]
|
||||
H --> I[Response]
|
||||
I --> J[Client]
|
||||
```
|
||||
|
||||
### Why This Order Matters
|
||||
@@ -238,21 +293,27 @@ graph TD
|
||||
- Needs to wrap everything to measure total time
|
||||
- Must log errors from all other middleware
|
||||
|
||||
2. **VendorContextMiddleware second**
|
||||
2. **PlatformContextMiddleware second**
|
||||
- Must run before VendorContextMiddleware (sets platform context)
|
||||
- Rewrites path for `/platforms/{code}/` prefixed requests
|
||||
- Sets `request.state.platform` for downstream middleware
|
||||
|
||||
3. **VendorContextMiddleware third**
|
||||
- Uses rewritten path from PlatformContextMiddleware
|
||||
- Must run before ContextDetectionMiddleware (provides vendor and clean_path)
|
||||
- Must run before ThemeContextMiddleware (provides vendor_id)
|
||||
|
||||
3. **ContextDetectionMiddleware third**
|
||||
4. **ContextDetectionMiddleware fourth**
|
||||
- Uses clean_path from VendorContextMiddleware
|
||||
- Provides context_type for ThemeContextMiddleware
|
||||
|
||||
4. **ThemeContextMiddleware last**
|
||||
5. **ThemeContextMiddleware last**
|
||||
- Depends on vendor from VendorContextMiddleware
|
||||
- Depends on context_type from ContextDetectionMiddleware
|
||||
|
||||
**Breaking this order will break the application!**
|
||||
|
||||
**Note:** Path-based routing (e.g., `/vendors/{code}/shop/*`) is handled by double router mounting in `main.py`, not by middleware.
|
||||
**Note:** Path-based routing (e.g., `/vendors/{code}/shop/*`) is handled by double router mounting in `main.py`, not by middleware. Platform path-based routing (e.g., `/platforms/oms/`) IS handled by PlatformContextMiddleware which rewrites the path.
|
||||
|
||||
## Request State Variables
|
||||
|
||||
@@ -260,6 +321,8 @@ Middleware components inject these variables into `request.state`:
|
||||
|
||||
| Variable | Set By | Type | Used By | Description |
|
||||
|----------|--------|------|---------|-------------|
|
||||
| `platform` | PlatformContextMiddleware | Platform | Routes, Content | Current platform object (main, oms, loyalty) |
|
||||
| `platform_context` | PlatformContextMiddleware | dict | Routes | Platform detection details (method, paths) |
|
||||
| `vendor` | VendorContextMiddleware | Vendor | Theme, Templates | Current vendor object |
|
||||
| `vendor_id` | VendorContextMiddleware | int | Queries, Theme | Current vendor ID |
|
||||
| `clean_path` | VendorContextMiddleware | str | Context | Path without vendor prefix (for context detection) |
|
||||
|
||||
@@ -113,13 +113,29 @@ ALTER TABLE content_pages ADD COLUMN is_platform_page BOOLEAN DEFAULT FALSE;
|
||||
|
||||
## Request Flow
|
||||
|
||||
### URL Routing Structure
|
||||
|
||||
The system uses different URL patterns for development vs production:
|
||||
|
||||
**Development (localhost):**
|
||||
- Main marketing site: `localhost:9999/` (no prefix) → `main` platform
|
||||
- Platform sites: `localhost:9999/platforms/{code}/` → specific platform
|
||||
|
||||
**Production (custom domains):**
|
||||
- Main marketing site: `wizamart.lu/` → `main` platform
|
||||
- Platform sites: `oms.lu/`, `loyalty.lu/` → specific platform
|
||||
|
||||
### Request Processing
|
||||
|
||||
```
|
||||
Request: GET /oms/vendors/shopname/about
|
||||
Request: GET /platforms/oms/vendors/shopname/about
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ PlatformContextMiddleware │
|
||||
│ - Detects platform from path prefix (/oms) or domain │
|
||||
│ - Detects platform from /platforms/{code}/ prefix or domain │
|
||||
│ - Rewrites path: /platforms/oms/vendors/shopname/about │
|
||||
│ → /vendors/shopname/about │
|
||||
│ - Sets request.state.platform = Platform(code='oms') │
|
||||
│ - Sets request.state.platform_clean_path = /vendors/shopname/about │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
@@ -127,7 +143,7 @@ Request: GET /oms/vendors/shopname/about
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ VendorContextMiddleware │
|
||||
│ - Uses platform_clean_path for vendor detection │
|
||||
│ - Uses rewritten path for vendor detection │
|
||||
│ - Sets request.state.vendor = Vendor(subdomain='shopname') │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
@@ -142,6 +158,30 @@ Request: GET /oms/vendors/shopname/about
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### Main Marketing Site (No Platform Prefix)
|
||||
|
||||
For requests without the `/platforms/` prefix (e.g., `localhost:9999/about`):
|
||||
|
||||
```
|
||||
Request: GET /about
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ PlatformContextMiddleware │
|
||||
│ - No /platforms/ prefix detected │
|
||||
│ - Uses DEFAULT_PLATFORM_CODE = 'main' │
|
||||
│ - Sets request.state.platform = Platform(code='main') │
|
||||
│ - Path unchanged: /about │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ Route Handler (platform_pages.py) │
|
||||
│ - Gets platform_id from request.state.platform (main) │
|
||||
│ - Loads CMS content for main marketing site │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Admin Interface
|
||||
|
||||
### Platform Management (`/admin/platforms`)
|
||||
@@ -218,8 +258,8 @@ Request: GET /oms/vendors/shopname/about
|
||||
|
||||
1. Insert platform record:
|
||||
```sql
|
||||
INSERT INTO platforms (code, name, description, path_prefix)
|
||||
VALUES ('loyalty', 'Loyalty Program', 'Customer loyalty and rewards', '/loyalty');
|
||||
INSERT INTO platforms (code, name, description, domain, path_prefix)
|
||||
VALUES ('loyalty', 'Loyalty Program', 'Customer loyalty and rewards', 'loyalty.lu', 'loyalty');
|
||||
```
|
||||
|
||||
2. Create platform-specific content pages:
|
||||
@@ -228,8 +268,10 @@ Request: GET /oms/vendors/shopname/about
|
||||
VALUES (2, 'home', 'Loyalty Program', '<h1>Welcome</h1>', TRUE);
|
||||
```
|
||||
|
||||
3. Configure routing (if using path prefix):
|
||||
- Platform detected by `PlatformContextMiddleware`
|
||||
3. Configure routing:
|
||||
- **Development:** Access at `localhost:9999/platforms/loyalty/`
|
||||
- **Production:** Access at `loyalty.lu/`
|
||||
- Platform detected automatically by `PlatformContextMiddleware`
|
||||
- No additional route configuration needed
|
||||
|
||||
4. Assign vendors to platform:
|
||||
@@ -237,3 +279,11 @@ Request: GET /oms/vendors/shopname/about
|
||||
INSERT INTO vendor_platforms (vendor_id, platform_id)
|
||||
VALUES (1, 2);
|
||||
```
|
||||
|
||||
### Platform URL Summary
|
||||
|
||||
| Platform | Code | Dev URL | Prod URL |
|
||||
|----------|------|---------|----------|
|
||||
| Main Marketing | `main` | `localhost:9999/` | `wizamart.lu/` |
|
||||
| OMS | `oms` | `localhost:9999/platforms/oms/` | `oms.lu/` |
|
||||
| Loyalty | `loyalty` | `localhost:9999/platforms/loyalty/` | `loyalty.lu/` |
|
||||
|
||||
@@ -37,6 +37,78 @@ http://localhost:8000/vendors/techpro/shop/checkout
|
||||
|
||||
---
|
||||
|
||||
## Multi-Platform URL Routing
|
||||
|
||||
Wizamart supports multiple platforms (OMS, Loyalty, Site Builder), each with its own marketing site and vendor ecosystem.
|
||||
|
||||
### Platform URL Structure
|
||||
|
||||
#### Development Mode (localhost)
|
||||
|
||||
| URL | What it serves |
|
||||
|-----|----------------|
|
||||
| `/` | Main marketing site homepage (`main` platform) |
|
||||
| `/about` | Main marketing site about page |
|
||||
| `/platforms/oms/` | OMS platform homepage |
|
||||
| `/platforms/oms/pricing` | OMS platform pricing page |
|
||||
| `/platforms/oms/vendors/{code}/` | Vendor storefront on OMS |
|
||||
| `/platforms/loyalty/` | Loyalty platform homepage |
|
||||
| `/platforms/loyalty/features` | Loyalty platform features page |
|
||||
|
||||
#### Production Mode (custom domains)
|
||||
|
||||
| URL | What it serves |
|
||||
|-----|----------------|
|
||||
| `wizamart.lu/` | Main marketing site homepage |
|
||||
| `wizamart.lu/about` | Main marketing site about page |
|
||||
| `oms.lu/` | OMS platform homepage |
|
||||
| `oms.lu/pricing` | OMS platform pricing page |
|
||||
| `oms.lu/vendors/{code}/` | Vendor storefront on OMS |
|
||||
| `loyalty.lu/` | Loyalty platform homepage |
|
||||
|
||||
### Platform Routing Logic
|
||||
|
||||
```
|
||||
Request arrives
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────┐
|
||||
│ Check: Is this production domain? │
|
||||
│ (oms.lu, loyalty.lu, etc.) │
|
||||
└─────────────────────────────────────┘
|
||||
│
|
||||
├── YES → Route to that platform
|
||||
│
|
||||
▼ NO (localhost)
|
||||
┌─────────────────────────────────────┐
|
||||
│ Check: Does path start with │
|
||||
│ /platforms/{code}/ ? │
|
||||
└─────────────────────────────────────┘
|
||||
│
|
||||
├── YES → Strip prefix, route to platform
|
||||
│ /platforms/oms/pricing → /pricing on OMS
|
||||
│
|
||||
▼ NO
|
||||
┌─────────────────────────────────────┐
|
||||
│ Route to MAIN MARKETING SITE │
|
||||
│ (no platform context) │
|
||||
│ /faq → Main site FAQ page │
|
||||
└─────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### Platform Codes
|
||||
|
||||
| Platform | Code | Dev URL | Prod Domain |
|
||||
|----------|------|---------|-------------|
|
||||
| Main Marketing | `main` | `localhost:9999/` | `wizamart.lu` |
|
||||
| OMS | `oms` | `localhost:9999/platforms/oms/` | `oms.lu` |
|
||||
| Loyalty | `loyalty` | `localhost:9999/platforms/loyalty/` | `loyalty.lu` |
|
||||
| Site Builder | `site-builder` | `localhost:9999/platforms/site-builder/` | `sitebuilder.lu` |
|
||||
|
||||
**See:** [Multi-Platform CMS Architecture](../multi-platform-cms.md) for content management details.
|
||||
|
||||
---
|
||||
|
||||
## Three Deployment Modes Explained
|
||||
|
||||
### 1. SUBDOMAIN MODE (Production - Recommended)
|
||||
|
||||
Reference in New Issue
Block a user