Controllers
Instead of defining all route logic as closures, you may organize related actions into controller classes under app/http/controllers.
Basic controllers
Section titled “Basic controllers”from almasix.http import Controllerfrom almasix.prism import view
class WelcomeController(Controller): async def index(self): return view("welcome", {"title": "Almasix"})Wire the action in a route file:
Route.get("/", [WelcomeController, "index"])Generate a stub:
python smith make:controller PostControllerNested namespaces work (python smith make:controller Admin/UserController) and create __init__.py files as needed.
Dependency injection
Section titled “Dependency injection”Constructor and method dependencies are resolved from the application container:
from almasix.config import ConfigRepositoryfrom almasix.http import Controller, Request
class DemoController(Controller): def __init__(self, config: ConfigRepository) -> None: self.config = config
async def with_config(self, request: Request) -> dict: return {"app": self.config.get("app.name")}Type-hint Request or a FormRequest subclass to receive the current request (validated when using FormRequest).
Single-action style
Section titled “Single-action style”Prefer one public index / store / show method per intent. Almasix does not require invokable __call__ controllers — use an explicitly named method on the route.