TT-004: complete modular frontend integration

This commit is contained in:
2026-08-09 22:57:51 +03:00
parent a819bc9807
commit 3f14532b9b
185 changed files with 1197 additions and 204824 deletions
@@ -8,24 +8,11 @@ router = APIRouter(prefix="/platform", tags=["Platform Modules"])
@router.get("/modules")
async def list_platform_modules():
"""List all discovered and registered modules.
Returns:
List of module metadata including id, name, version, description,
enabled status, router count, and declared permissions.
"""
"""List all discovered and registered modules with frontend info."""
registry = get_module_registry()
modules = registry.all()
return [
{
"id": m.id,
"name": m.name,
"version": m.version,
"description": m.description,
"enabled": m.enabled,
"routers": len(m.routers()),
"permissions": m.permissions(),
}
m.module_info()
for m in modules
]
+37 -72
View File
@@ -2,105 +2,70 @@
from abc import ABC, abstractmethod
from pathlib import Path
from typing import List, Optional
from typing import List, Optional, Dict, Any
from fastapi import APIRouter
class FrontendInfo:
"""Frontend configuration for a module."""
def __init__(self, dev_url: str = "", prod_path: str = ""):
self.dev_url = dev_url
self.prod_path = prod_path
def to_dict(self) -> Dict[str, str]:
return {
"dev_url": self.dev_url,
"prod_path": self.prod_path,
}
class BaseModule(ABC):
"""Abstract base class for all platform modules.
Each module must implement this class to be discovered and registered
by the platform's module loader.
Attributes:
id: Unique module identifier (e.g., 'request', 'crm')
name: Human-readable display name
version: Semantic version string
description: Brief description of the module
enabled: Whether the module is enabled
"""
"""Abstract base class for all platform modules."""
id: str
name: str
version: str
description: str = ""
enabled: bool = True
frontend: FrontendInfo = FrontendInfo()
def routers(self) -> List[APIRouter]:
"""Return FastAPI routers to be auto-mounted by the platform.
Override this method to expose API endpoints through the platform.
All routers returned here will be automatically included in the
FastAPI application without manual registration in main.py.
Default implementation returns an empty list.
Returns:
List of FastAPI APIRouter instances.
"""
"""Return FastAPI routers to be auto-mounted."""
return []
def permissions(self) -> List[str]:
"""Return permission strings required/managed by this module.
Override this method to declare permissions in the format:
'<module_id>.<action>' (e.g., 'request.read', 'request.write')
Default implementation returns an empty list.
Returns:
List of permission identifier strings.
"""
"""Return permission strings."""
return []
def static_path(self) -> Optional[Path]:
"""Return path to the module's static files directory.
Override this method to serve static files (CSS, JS, images)
through the platform. The platform will mount this directory
at /modules/{module_id}/static
Default implementation returns None.
Returns:
Path to static directory, or None if not applicable.
"""
"""Return path to static files directory."""
return None
def templates_path(self) -> Optional[Path]:
"""Return path to the module's templates directory.
Override this method to serve HTML templates through the platform.
Default implementation returns None.
Returns:
Path to templates directory, or None if not applicable.
"""
"""Return path to templates directory."""
return None
def module_info(self) -> Dict[str, Any]:
"""Return module info for API response."""
return {
"id": self.id,
"slug": self.id, # Use id as slug
"name": self.name,
"version": self.version,
"description": self.description,
"enabled": self.enabled,
"routers": len(self.routers()),
"permissions": self.permissions(),
"frontend": self.frontend.to_dict(),
}
async def startup(self) -> None:
"""Lifecycle hook called when the platform starts.
Override this to perform initialization tasks such as:
- Database migrations
- Background job scheduling
- External service connections
Default implementation does nothing.
"""
"""Lifecycle hook called when the platform starts."""
pass
async def shutdown(self) -> None:
"""Lifecycle hook called when the platform shuts down.
Override this to perform cleanup tasks such as:
- Closing connections
- Stopping background jobs
- Flushing buffers
Default implementation does nothing.
"""
"""Lifecycle hook called when the platform shuts down."""
pass
def __repr__(self) -> str:
+1 -1
View File
@@ -82,4 +82,4 @@ async def shutdown():
if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host="0.0.0.0", port=9000, reload=True)
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)