TT-004: complete modular frontend integration
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user