--- name: enferno-dev description: | Development skill for the Enferno Flask framework. Use when implementing features, fixing bugs, or writing code in Enferno-based applications: blueprints, SQLAlchemy models and migrations, admin JSON APIs, Vue 3 + Vuetify pages without a build step, Flask-Security auth, Celery tasks, and dependency upgrades. --- # Enferno Development Flask 3 + SQLAlchemy 2.x + Vue 3 + Vuetify 4. No frontend build step. `uv` for everything. ## Quick Reference ```bash uv run flask run --port 5001 # Dev server (5001 on macOS) uv run flask create-db # Create tables and stamp migrations uv run flask install # Create admin user uv run flask db migrate -m "msg" # Draft migration, review before upgrade uv run flask db upgrade # Apply migrations uv run pytest # Routes, auth, admin API, migrations, setup.sh uv run ruff check . && uv run ruff format . # Lint + format ``` ## Blueprint Structure ``` enferno/ ├── feature_name/ │ ├── views.py # Page routes and /api/ endpoints │ ├── models.py # SQLAlchemy models │ └── forms.py # WTForms (if needed) └── templates/feature_name/ ``` Register in `register_blueprints()` in `enferno/app.py`: ```python from enferno.feature_name.views import bp as feature_bp app.register_blueprint(feature_bp) ``` ## Models Use `BaseMixin` (`save()`/`delete()`) and implement `to_dict()`/`from_dict()`. After changing models, run `flask db migrate` and review the generated revision. ```python from enferno.extensions import db from enferno.utils.base import BaseMixin class Product(db.Model, BaseMixin): __tablename__ = "products" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), nullable=False) price = db.Column(db.Numeric(10, 2)) active = db.Column(db.Boolean, default=True) def to_dict(self): return {"id": self.id, "name": self.name, "price": float(self.price or 0), "active": self.active} def from_dict(self, data): self.name = data.get("name", self.name) self.price = data.get("price", self.price) self.active = data.get("active", self.active) return self ``` ## API Endpoints Protect the whole blueprint in `before_request`. Payloads are `{"item": {...}}`; lists return `items`, `total`, `perPage`. Log admin actions with `Activity.register`, which commits: leave the change pending (`flush()` for a new row's id) so the change and its audit entry are saved together or not at all. Errors under `/api/` return `{"message": ...}` JSON from the app-level handler. ```python from flask import Blueprint, render_template, request from flask_security import auth_required, current_user, roles_required from enferno.extensions import db from enferno.user.models import Activity from enferno.utils.tables import table_response bp = Blueprint("products", __name__) @bp.before_request @auth_required("session") @roles_required("admin") def before_request(): pass @bp.get("/products/") def products_page(): return render_template("products/index.html") @bp.get("/api/products") def list_products(): # Paging, ?sort_by= (only the columns named here) and ?q= search return table_response( db.select(Product).order_by(Product.id), sortable={"name": Product.name, "price": Product.price}, searchable=(Product.name,), ) @bp.post("/api/product/") def create_product(): product = Product().from_dict(request.json.get("item", {})) db.session.add(product) db.session.flush() Activity.register(current_user.id, "Product Create", product.to_dict()) return {"item": product.to_dict()} @bp.post("/api/product/") def update_product(id): product = db.get_or_404(Product, id) old = product.to_dict() product.from_dict(request.json.get("item", {})) Activity.register(current_user.id, "Product Update", {"old": old, "new": product.to_dict()}) return {"item": product.to_dict()} @bp.delete("/api/product/") def delete_product(id): product = db.get_or_404(Product, id) data = product.to_dict() db.session.delete(product) Activity.register(current_user.id, "Product Delete", data) return {"deleted": True} ``` ## Pages (Vue 3 + Vuetify) `layout.html` owns ``, the nav and the `#app` mount point. A page fills `{% block content %}` and mounts its app in `{% block js %}` with `layoutMixin` and `registerEnfernoComponents`, or the nav breaks. Vue expressions use `${ }`; `{{ }}` is Jinja. Data tables use `crudMixin` (`static/js/crud.js`) on the page and `table_response()` (`enferno/utils/tables.py`) on the server. Together they give paging, sorting, search, a skeleton while loading, an edit dialog that works on a copy, saves that keep the dialog open on failure, and an in-app delete confirmation. `cms/roles.html` is the smallest complete example. `layoutMixin` also provides `notify(message)`, `await confirmAction(message)` and `formatDate(iso)` for any page. ```html {% extends "layout.html" %} {% block content %} Save {% endblock %} {% block js %} {% endblock %} ``` Templates are parsed by the browser before Vue sees them: put ``/`` rows inside a `