refactor: migrate templates and static files to self-contained modules

Templates Migration:
- Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.)
- Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.)
- Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms)
- Migrate public templates to modules (billing, marketplace, cms)
- Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/)
- Migrate letzshop partials to marketplace module

Static Files Migration:
- Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file)
- Migrate vendor JS to modules: tenancy (4 files), core (2 files)
- Migrate shared JS: vendor-selector.js to core, media-picker.js to cms
- Migrate storefront JS: storefront-layout.js to core
- Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/)
- Update all template references to use module_static paths

Naming Consistency:
- Rename static/platform/ to static/public/
- Rename app/templates/platform/ to app/templates/public/
- Update all extends and static references

Documentation:
- Update module-system.md with shared templates documentation
- Update frontend-structure.md with new module JS organization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-01 14:34:16 +01:00
parent 843703258f
commit 4e28d91a78
542 changed files with 11603 additions and 9037 deletions

View File

@@ -78,56 +78,99 @@ The Wizamart platform has been migrating from a monolithic structure with code i
- Created `app/modules/billing/routes/api/vendor_addons.py`
- Deleted legacy billing routes from `app/api/v1/vendor/`
### Phase 6: Remaining Vendor Routes (2026-01-31)
### Phase 6: Vendor Routes Migration (2026-01-31)
#### Current Changes - Migrate analytics, usage, onboarding
- **Deleted**: `app/api/v1/vendor/analytics.py` (duplicate - analytics module already auto-discovered)
- **Created**: `app/modules/billing/routes/api/vendor_usage.py` (usage limits/upgrades)
- **Created**: `app/modules/marketplace/routes/api/vendor_onboarding.py` (onboarding wizard)
- **Deleted**: `app/api/v1/vendor/usage.py` (migrated to billing)
- **Deleted**: `app/api/v1/vendor/onboarding.py` (migrated to marketplace)
- Migrated remaining vendor routes to respective modules
### Phase 7: Admin Routes Migration (2026-01-31)
Major admin route migration to modules.
### Phase 8: Storefront Routes Auto-Discovery (2026-01-31)
- Updated `app/modules/routes.py` to discover `storefront.py` files
- Added `get_storefront_api_routes()` function
- Updated `app/api/v1/storefront/__init__.py` to use auto-discovery
- 37 storefront routes now auto-discovered from 7 modules:
- cart, catalog, checkout, cms, customers, messaging, orders
**Admin routes migrated to modules:**
**Tenancy Module** (auth, users, companies, platforms, vendors):
- `admin_auth.py`, `admin_users.py`, `admin_admin_users.py`
- `admin_companies.py`, `admin_platforms.py`, `admin_vendors.py`
- `admin_vendor_domains.py`
**Core Module** (dashboard, settings):
- `admin_dashboard.py`, `admin_settings.py`
**Messaging Module** (messages, notifications, email templates):
- `admin_messages.py`, `admin_notifications.py`, `admin_email_templates.py`
**Monitoring Module** (logs, tasks, tests, code quality, audit, platform health):
- `admin_logs.py`, `admin_tasks.py`, `admin_tests.py`
- `admin_code_quality.py`, `admin_audit.py`, `admin_platform_health.py`
**CMS Module** (content pages, images, media, vendor themes):
- `admin_content_pages.py`, `admin_images.py`
- `admin_media.py`, `admin_vendor_themes.py`
**Billing Module** (subscriptions, invoices, payments, features):
- `admin_subscriptions.py`, `admin_invoices.py`, `admin_features.py`
**Inventory Module** (stock management):
- `admin.py` (inventory admin routes)
**Orders Module** (order management, exceptions):
- `admin_orders.py`, `admin_order_item_exceptions.py`
**Marketplace Module** (letzshop integration):
- `admin_letzshop.py`, `admin_marketplace.py`
## Current State
### Migrated to Modules (Auto-Discovered)
### ✅ Fully Migrated to Modules (Auto-Discovered)
| Module | Routes | Services | Models | Schemas | Tasks |
|--------|--------|----------|--------|---------|-------|
| analytics | API | Stats | Report | Stats | - |
| billing | API | Billing, Subscription | Tier, Subscription, Invoice | Billing | Subscription |
| catalog | API | Product | Product, Category | Product | - |
| cart | API | Cart | Cart, CartItem | Cart | Cleanup |
| checkout | API | Checkout | - | Checkout | - |
| cms | API, Pages | ContentPage | ContentPage, Section | CMS | - |
| customers | API | Customer | Customer | Customer | - |
| inventory | API | Inventory | Stock, Location | Inventory | - |
| marketplace | API | Import, Export, Sync | ImportJob | Marketplace | Import, Export |
| messaging | API | Message | Message | Message | - |
| orders | API | Order | Order, OrderItem | Order | - |
| payments | API | Payment, Stripe | Payment | Payment | - |
| Module | Admin Routes | Vendor Routes | Services | Models | Schemas | Tasks |
|--------|--------------|---------------|----------|--------|---------|-------|
| analytics | - | ✅ API | Stats | Report | Stats | - |
| billing | ✅ subscriptions, invoices, features | ✅ checkout, addons, usage | Billing, Subscription | Tier, Subscription, Invoice | Billing | Subscription |
| catalog | ✅ products | ✅ products | Product | Product, Category | Product | - |
| cart | - | ✅ API | Cart | Cart, CartItem | Cart | Cleanup |
| checkout | - | ✅ API | Checkout | - | Checkout | - |
| cms | ✅ content-pages, images, media, vendor-themes | ✅ content-pages, media | ContentPage | ContentPage, Section | CMS | - |
| core | ✅ dashboard, settings | ✅ dashboard, settings | - | - | - | - |
| customers | - | ✅ API | Customer | Customer | Customer | - |
| inventory | ✅ stock | ✅ stock | Inventory | Stock, Location | Inventory | - |
| marketplace | ✅ letzshop, marketplace | ✅ onboarding, letzshop | Import, Export, Sync | ImportJob | Marketplace | Import, Export |
| messaging | ✅ messages, notifications, email-templates | ✅ messages, notifications, email | Message | Message | Message | - |
| monitoring | ✅ logs, tasks, tests, code-quality, audit, platform-health | - | - | TestRun, CodeQuality | - | - |
| orders | ✅ orders, exceptions | ✅ orders | Order | Order, OrderItem | Order | - |
| payments | - | ✅ API | Payment, Stripe | Payment | Payment | - |
| tenancy | ✅ auth, users, admin-users, companies, platforms, vendors | ✅ auth, profile, team, info | - | - | - | - |
### 🔒 Legacy Routes (Super Admin Only - Intentionally Kept)
These files remain in `app/api/v1/admin/` as they are super-admin framework configuration:
| File | Purpose | Why Legacy |
|------|---------|------------|
| `menu_config.py` | Navigation configuration | Framework-level config |
| `module_config.py` | Module settings | Framework-level config |
| `modules.py` | Module management | Framework-level config |
**Note:** These are intentionally kept in legacy location as they configure the module system itself.
### Still in Legacy Locations (Need Migration)
#### Vendor Routes (`app/api/v1/vendor/`)
- `auth.py` - Authentication (belongs in core/tenancy)
- `dashboard.py` - Dashboard (belongs in core)
- `email_settings.py` - Email settings (belongs in messaging)
- `email_templates.py` - Email templates (belongs in messaging)
- `info.py` - Vendor info (belongs in tenancy)
- `media.py` - Media library (belongs in cms)
- `messages.py` - Messages (belongs in messaging)
- `notifications.py` - Notifications (belongs in messaging)
- `profile.py` - Profile (belongs in core/tenancy)
- `settings.py` - Settings (belongs in core)
- `team.py` - Team management (belongs in tenancy)
#### Admin Routes (`app/api/v1/admin/`)
- Most files still in legacy location
- Target: Move to respective modules or tenancy module
#### Services (`app/services/`)
- 61 files still in legacy location
- Many are re-exports from modules
- Many files still in legacy location
- Some are re-exports from modules
- Target: Move actual code to modules, delete re-exports
#### Tasks (`app/tasks/`)
@@ -146,10 +189,50 @@ The following rules enforce the module-first architecture:
| MOD-018 | ERROR | Tasks must be in modules, not `app/tasks/` |
| MOD-019 | WARNING | Schemas should be in modules, not `models/schema/` |
## Route Auto-Discovery Pattern
### Admin Routes Structure
Each module aggregates its admin routes in `routes/api/admin.py`:
```python
# app/modules/{module}/routes/api/admin.py
from fastapi import APIRouter, Depends
from app.api.deps import require_module_access
from .admin_feature1 import admin_feature1_router
from .admin_feature2 import admin_feature2_router
admin_router = APIRouter(
dependencies=[Depends(require_module_access("{module}"))],
)
admin_router.include_router(admin_feature1_router, tags=["admin-feature1"])
admin_router.include_router(admin_feature2_router, tags=["admin-feature2"])
```
### Vendor Routes Structure
Similar pattern for vendor routes in `routes/api/vendor.py`:
```python
# app/modules/{module}/routes/api/vendor.py
from fastapi import APIRouter, Depends
from app.api.deps import require_module_access
from .vendor_feature1 import vendor_feature1_router
vendor_router = APIRouter(
dependencies=[Depends(require_module_access("{module}"))],
)
vendor_router.include_router(vendor_feature1_router, tags=["vendor-feature1"])
```
## Next Steps
1. **Migrate remaining vendor routes** to appropriate modules
2. **Migrate admin routes** to modules
1. ~~Migrate remaining vendor routes~~ - COMPLETE
2. ~~Migrate admin routes~~ - COMPLETE (except super-admin framework config)
3. **Move services** from `app/services/` to module `services/`
4. **Move tasks** from `app/tasks/` to module `tasks/`
5. **Clean up re-exports** once all code is in modules
@@ -168,3 +251,17 @@ Check for legacy location violations:
python scripts/validate_architecture.py -d app/api/v1/vendor
python scripts/validate_architecture.py -d app/services
```
Verify route count:
```bash
python -c "
from main import app
routes = [r for r in app.routes if hasattr(r, 'path')]
print(f'Total routes: {len(routes)}')
admin = [r for r in routes if '/admin/' in r.path]
vendor = [r for r in routes if '/vendor/' in r.path]
print(f'Admin routes: {len(admin)}')
print(f'Vendor routes: {len(vendor)}')
"
```