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

@@ -50,8 +50,8 @@ app/
**Purpose:** Public-facing platform pages (marketing, info pages)
**Location:**
- Templates: `app/templates/platform/`
- Static: `static/platform/`
- Templates: `app/templates/public/`
- Static: `static/public/`
**Pages:**
- Homepage (multiple layouts: default, minimal, modern)
@@ -163,7 +163,7 @@ app/
Each frontend has its own static directory for frontend-specific assets. Use the appropriate directory based on which frontend the asset belongs to.
### Platform Static Assets (`static/platform/`)
### Platform Static Assets (`static/public/`)
**JavaScript Files:**
```html
@@ -270,7 +270,7 @@ Each frontend has its own static directory for frontend-specific assets. Use the
Icon system (used by all 4 frontends) → static/shared/js/icons.js
Admin dashboard chart → static/admin/js/charts.js
Vendor product form → static/vendor/js/product-form.js
Platform hero image → static/platform/img/hero.jpg
Platform hero image → static/public/img/hero.jpg
Storefront product carousel → static/storefront/js/carousel.js
```
@@ -338,31 +338,18 @@ app.mount("/static/modules/orders", StaticFiles(directory="app/modules/orders/st
| **marketplace** | marketplace*.js, letzshop*.js | letzshop.js, marketplace.js, onboarding.js | - |
| **monitoring** | monitoring.js, background-tasks.js, imports.js, logs.js | - | - |
| **dev_tools** | testing-*.js, code-quality-*.js, icons-page.js, components.js | - | - |
| **cms** | content-pages.js, content-page-edit.js | content-pages.js, content-page-edit.js, media.js | - |
| **cms** | content-pages.js, content-page-edit.js | content-pages.js, content-page-edit.js, media.js | media-picker.js |
| **analytics** | - | analytics.js | - |
| **tenancy** | companies*.js, vendors*.js, platforms*.js, admin-users*.js, users*.js | login.js, team.js, profile.js, settings.js | - |
| **core** | dashboard.js, settings.js, my-menu-config.js, login.js, init-alpine.js | dashboard.js, init-alpine.js | vendor-selector.js |
### Platform Static Files (Not in Modules)
These files remain in `static/` because they're platform-level, not module-specific:
Only framework-level files remain in `static/`:
**Admin Core (`static/admin/js/`):**
- `init-alpine.js` - Admin layout initialization
- `dashboard.js` - Main admin dashboard
- `login.js` - Admin authentication
- `platforms.js`, `platform-*.js` - Platform management (6 files)
- `vendors.js`, `vendor-*.js` - Vendor management at platform level (6 files)
- `companies.js`, `company-*.js` - Company management (3 files)
- `admin-users.js`, `admin-user-*.js` - Admin user management (3 files)
- `users.js`, `user-*.js` - Platform user management (4 files)
- `settings.js` - Platform settings
**Vendor Core (`static/vendor/js/`):**
- `init-alpine.js` - Vendor layout initialization
- `dashboard.js` - Vendor main dashboard
- `login.js` - Vendor authentication
- `profile.js` - Vendor account settings
- `settings.js` - Vendor configuration
- `team.js` - Team member management
**Admin Framework (`static/admin/js/`):**
- `module-config.js` - Module system configuration UI
- `module-info.js` - Module information display
**Shared Utilities (`static/shared/js/`):**
- `api-client.js` - Core HTTP client with auth
@@ -370,8 +357,7 @@ These files remain in `static/` because they're platform-level, not module-speci
- `money.js` - Money/currency handling
- `icons.js` - Heroicons SVG definitions
- `log-config.js` - Centralized logging
- `vendor-selector.js` - Vendor autocomplete component
- `media-picker.js` - Media picker component
- `lib/` - Third-party libraries (Alpine.js, Chart.js, etc.)
### User Type Distinction
@@ -379,13 +365,13 @@ The codebase distinguishes between three types of users:
| Type | Management JS | Location | Description |
|------|---------------|----------|-------------|
| **Admin Users** | admin-users.js | `static/admin/js/` | Platform administrators (super admins, platform admins) |
| **Platform Users** | users.js | `static/admin/js/` | Vendor/company users who log into the platform |
| **Admin Users** | admin-users.js | `app/modules/tenancy/static/admin/js/` | Platform administrators (super admins, platform admins) |
| **Platform Users** | users.js | `app/modules/tenancy/static/admin/js/` | Vendor/company users who log into the platform |
| **Shop Customers** | customers.js | `app/modules/customers/static/` | End customers who buy from vendors |
This distinction is important:
- `admin-users.js` and `users.js` manage **internal platform users** → Stay in `static/admin/js/`
- `customers.js` manages **storefront customers** → Lives in the customers module
All user management JS is now in self-contained modules:
- `admin-users.js` and `users.js` are in the **tenancy** module (manages platform users)
- `customers.js` is in the **customers** module (manages storefront customers)
---
@@ -466,7 +452,7 @@ All frontends communicate with backend via APIs:
- `/api/v1/admin/*` - Admin APIs
- `/api/v1/vendor/*` - Vendor APIs
- `/api/v1/storefront/*` - Storefront APIs
- `/api/v1/platform/*` - Platform APIs
- `/api/v1/public/*` - Platform APIs
**Benefits:**
- Clear backend contracts

View File

@@ -509,11 +509,11 @@ Routes define API and page endpoints. They are auto-discovered from module direc
| Type | Location | Discovery | Router Name |
|------|----------|-----------|-------------|
| Vendor API | `routes/api/vendor.py` | `app/modules/routes.py` | `vendor_router` |
| Admin API | `routes/api/admin.py` | `app/modules/routes.py` | `admin_router` |
| Shop API | `routes/api/shop.py` | `app/modules/routes.py` | `shop_router` |
| Vendor Pages | `routes/pages/vendor.py` | `app/modules/routes.py` | `vendor_router` |
| Vendor API | `routes/api/vendor.py` | `app/modules/routes.py` | `vendor_router` |
| Storefront API | `routes/api/storefront.py` | `app/modules/routes.py` | `router` |
| Admin Pages | `routes/pages/admin.py` | `app/modules/routes.py` | `admin_router` |
| Vendor Pages | `routes/pages/vendor.py` | `app/modules/routes.py` | `vendor_router` |
**Structure:**
```
@@ -521,9 +521,10 @@ app/modules/{module}/routes/
├── __init__.py
├── api/
│ ├── __init__.py
│ ├── vendor.py # Must export vendor_router
│ ├── admin.py # Must export admin_router
── vendor_{feature}.py # Sub-routers aggregated in vendor.py
── vendor.py # Must export vendor_router
│ ├── storefront.py # Must export router (public storefront)
│ └── admin_{feature}.py # Sub-routers aggregated in admin.py
└── pages/
├── __init__.py
└── vendor.py # Must export vendor_router
@@ -754,22 +755,30 @@ class OrderAlreadyFulfilledError(OrderException):
### Templates
Jinja2 templates are auto-discovered from module `templates/` directories.
Jinja2 templates are auto-discovered from module `templates/` directories. The template loader searches `app/templates/` first (for shared templates), then each module's `templates/` directory.
| Location | URL Pattern | Discovery |
|----------|-------------|-----------|
| `templates/{module}/vendor/*.html` | `/vendor/{vendor}/...` | Jinja2 loader |
| `templates/{module}/admin/*.html` | `/admin/...` | Jinja2 loader |
| `templates/{module}/storefront/*.html` | `/storefront/...` | Jinja2 loader |
| `templates/{module}/public/*.html` | `/...` (platform pages) | Jinja2 loader |
**Structure:**
**Module Template Structure:**
```
app/modules/{module}/templates/
└── {module}/
├── admin/
│ ├── list.html
│ └── partials/ # Module-specific partials
│ └── my-partial.html
├── vendor/
│ ├── index.html
│ └── detail.html
── admin/
└── list.html
── storefront/ # Customer-facing shop pages
└── products.html
└── public/ # Platform marketing pages
└── pricing.html
```
**Template Reference:**
@@ -782,6 +791,27 @@ return templates.TemplateResponse(
)
```
**Shared Templates (in `app/templates/`):**
Some templates remain in `app/templates/` because they are used across all modules:
| Directory | Contents | Purpose |
|-----------|----------|---------|
| `admin/base.html` | Admin layout | Parent template all admin pages extend |
| `vendor/base.html` | Vendor layout | Parent template all vendor pages extend |
| `storefront/base.html` | Shop layout | Parent template all storefront pages extend |
| `platform/base.html` | Public layout | Parent template all public pages extend |
| `admin/errors/` | Error pages | HTTP error templates (404, 500, etc.) |
| `vendor/errors/` | Error pages | HTTP error templates for vendor |
| `storefront/errors/` | Error pages | HTTP error templates for storefront |
| `admin/partials/` | Shared partials | Header, sidebar used across admin |
| `vendor/partials/` | Shared partials | Header, sidebar used across vendor |
| `shared/macros/` | Jinja2 macros | Reusable UI components (buttons, forms, tables) |
| `shared/includes/` | Includes | Common HTML snippets |
| `invoices/` | PDF templates | Invoice PDF generation |
These shared templates provide the "framework" that module templates build upon. Module templates extend base layouts and import shared macros.
---
### Static Files