enferno

repository·master·Indexed 20 days ago

https://github.com/level09/enferno

A modern Flask framework (v13.2.0) optimized for AI-assisted development workflows. It features a production-ready stack with a Vue 3/Vuetify 3 frontend, robust authentication (2FA, WebAuthn, OAuth), and optional background task support via Celery and Redis. The framework includes tools for rapid shipping with zero build steps, SQLAlchemy 2.x database management via Alembic, and automated deployment options via Docker or the enferno_cli tool.

Tokens
11K
Snippets
46
Records
56
Agent score
68%

What's inside enferno

  1. Understand the Enferno project structure

    master

    Enferno follows a standard Flask application structure. The core logic resides in the enferno/ package, which contains the application factory, configuration, and extensions. Blueprints are used to modularize routes into portal/ (protected), user/ (management), and public/ (unprotected). Static assets like Vue and CSS are located in enferno/static/, while Jinja2 templates are in enferno/templates/.

    enferno/
    ├── enferno/                # Main application package
    │   ├── app.py             # Application factory
    │   ├── settings.py        # Configuration
    │   ├── extensions.py      # Flask extensions
    │   ├── commands.py        # CLI commands
    │   ├── portal/            # Blueprint: Protected routes
    │   ├── public/            # Blueprint: Public routes
    │   ├── user/              # Blueprint: User management
    │   ├── tasks/             # Background tasks (optional Celery)
    │   ├── utils/             # Utility functions
    │   ├── static/            # Static assets (Vue, Vuetify, CSS)
    │   └── templates/         # Jinja2 templates
    ├── docs/                  # Documentation
    ├── instance/             # SQLite database
    ├── pyproject.toml        # Dependencies and project config
    ├── setup.sh              # Setup script
    ├── run.py                # Entry point
    └── docker-compose.yml    # Docker configuration
  2. How blueprints and route protection work

    master

    Enferno uses a three-blueprint architecture to organize routes and manage security levels:

    1. Portal Blueprint (portal/): Designed for protected routes. You can protect every route in this blueprint automatically by using the @portal.before_request decorator combined with @auth_required().
    2. User Blueprint (user/): Handles user management and profile routes. Routes here typically require explicit @auth_required() decoration.
    3. Public Blueprint (public/): Contains routes accessible to everyone without authentication.

    Using the before_request pattern in the Portal blueprint is the recommended way to ensure no protected route is accidentally left open.

    from flask import Blueprint
    from flask_security import auth_required
    
    portal = Blueprint('portal', __name__)
    
    # Protect all routes in this blueprint automatically
    @portal.before_request
    @auth_required()
    def before_request():
        pass
    
    @portal.route('/dashboard')
    def dashboard():
        return render_template('portal/dashboard.html')
  3. Follow SQLAlchemy 2.x and Response patterns

    master

    When writing backend logic, follow these established patterns to ensure consistency with the existing codebase:

    Query Pattern (SQLAlchemy 2.x): Use db.select() for queries and db.paginate() for paginated results.

    Response Pattern: API responses should return a dictionary containing the list of items (converted via .to_dict()) and the total count.

    # Query pattern (SQLAlchemy 2.x)
    query = db.select(User)
    pagination = db.paginate(query, page=page, per_page=per_page)
    
    # Response pattern
    return {
        "items": [item.to_dict() for item in pagination.items],
        "total": pagination.total
    }
  4. Quickstart: Install and run Enferno

    master

    To get a local development instance of Enferno running, clone the repository, run the setup script, initialize the database, and create an admin user.

    Requirements:

    • Python 3.11+
    • uv

    Steps:

    1. Clone and enter the directory.
    2. Run ./setup.sh to install dependencies and generate a secure .env file.
    3. Initialize the database using uv run flask create-db.
    4. Create your admin user with uv run flask install.
    5. Start the server with uv run flask run.

    The application will be available at http://localhost:5000.

    git clone git@github.com:level09/enferno.git && cd enferno
    ./setup.sh                    # Installs deps + generates secure .env
    uv run flask create-db        # Setup database
    uv run flask install          # Create admin user
    uv run flask run              # → http://localhost:5000
  5. Quickstart with Enferno

    master

    Enferno is a Flask framework designed for rapid deployment with zero build steps. It uses Vue 3 and Vuetify 3 directly in the browser, eliminating the need for npm, webpack, or vite. To get a project running immediately, use the provided setup script and the Flask CLI.

    ./setup.sh && flask run
  6. Automated Deployment with Enferno CLI

    master

    For Ubuntu servers, the recommended way to deploy is using the enferno_cli tool. It automates server provisioning (supporting Python 3.13+), Nginx configuration with SSL, database setup (PostgreSQL/SQLite), Systemd service configuration, and security setup.

    # Install the CLI tool
    pip install enferno_cli
    
    # Run the interactive setup
    enferno setup
  7. Add background task support with Celery

    master

    By default, Enferno uses SQLite. To enable asynchronous background tasks using Celery and Redis, you must install the full extra dependencies and configure your environment variables.

    1. Run uv sync --extra full to install Redis and Celery support.
    2. Configure REDIS_URL and CELERY_BROKER_URL in your .env file.
    uv sync --extra full
  8. Install and set up Enferno locally

    master

    To run Enferno on your local machine, ensure you have Python 3.11+ and uv installed. Follow these steps to clone the repository, install dependencies, and initialize the application:

    1. Install uv using pip or the official shell script.
    2. Clone the repository and enter the directory.
    3. Run ./setup.sh to install dependencies and generate a secure .env file.
    4. Initialize the database using uv run flask create-db.
    5. Create an admin user using uv run flask install.
    6. Start the development server with uv run flask run.

    The application will be available at http://localhost:5000.

    # Install uv
    pip install uv
    
    # Clone and setup
    git clone git@github.com:level09/enferno.git
    cd enferno
    ./setup.sh
    uv run flask create-db
    uv run flask install
    uv run flask run
  9. Implement security best practices

    master

    When developing with Enferno, follow these security patterns:

    1. Input Validation: Use Flask-WTF and WTForms to define forms with validators like DataRequired() and Length().
    2. CSRF Protection: Ensure CSRFProtect(app) is initialized to prevent cross-site request forgery.
    3. Authentication: Use the @auth_required() decorator from flask_security on routes that require a logged-in user.
    from flask_wtf import FlaskForm
    from wtforms import StringField
    from wtforms.validators import DataRequired, Length
    
    class PostForm(FlaskForm):
        title = StringField('Title', validators=[DataRequired(), Length(max=80)])
  10. Deploy to a VPS using Ignite

    master

    You can deploy Enferno to any Ubuntu VPS (e.g., Hetzner, DigitalOcean) using the ignite script. This handles Caddy (with auto SSL), Python 3.13, Redis, and systemd services.

    Run the following command, replacing your-domain.com with your actual domain:

    curl -sSL https://raw.githubusercontent.com/level09/ignite/main/ignite.sh | sudo DOMAIN=your-domain.com bash
  11. Manage database migrations with Alembic

    master

    Schema changes are managed via Flask-Migrate (Alembic).

    Workflow for existing databases:

    1. Draft a migration based on model changes:
      uv run flask db migrate -m "description"
    2. Crucial: Review the generated file in migrations/versions/<revision>.py and adjust it if necessary.
    3. Apply the migration:
      uv run flask db upgrade

    Workflow for fresh databases:

    • Use uv run flask create-db to build the full schema and stamp it automatically.

    Legacy databases:

    • If you are using a database created before migrations were implemented, run uv run flask db stamp head once before starting the standard migration workflow.
    uv run flask db migrate -m "add status to user"
    uv run flask db upgrade