Getting Started with FlaskIt

FlaskIt is a modern full-stack framework built on Flask with elegant routing, MVL architecture, and batteries included.

Installation

Install FlaskIt using pip:

pip install flaskit-love
Requirements: Python 3.8 or higher

Quick Start

Create your first FlaskIt project in seconds:

Terminal
# Create a new project
flaskit new my-project

# Navigate to project
cd my-project

# Install dependencies
pip install -r requirements.txt

# Run the development server
flaskit serve

Your application is now running at http://localhost:5000 🚀

Project Structure

FlaskIt generates a complete, organized project structure:

my-project/
├── app/
│   ├── logic/          # Business logic handlers
│   ├── service/        # Data services (CRUD)
│   ├── model/          # Database models
│   ├── config/         # Configuration
│   ├── middleware/     # Custom middleware
│   └── database/       # Database setup
├── routes/
│   └── web.py          # Route definitions
├── web/
│   ├── views/          # HTML templates
│   │   ├── layouts/
│   │   ├── components/
│   │   └── pages/
│   └── static/         # CSS, JS, images
│       ├── css/
│       ├── js/
│       └── images/
├── app.py              # Application entry point
├── .env.example        # Environment variables template
├── requirements.txt    # Python dependencies
└── data.json          # Public data storage

Routing System

FlaskIt uses a clean, decorator-free routing system. Define all routes in routes/web.py:

Basic Routes

routes/web.py
from flaskit import Route
from app.logic.users import UserLogic

def register_routes(app):
    route = Route()
    
    # View routes (render templates)
    route.view('/', 'home.index').name('home')
    route.view('/about', 'home.about').name('about')
    
    # API routes
    route.get('/api/users', UserLogic.get_all)
    route.post('/api/users', UserLogic.create)
    route.put('/api/users/{id}', UserLogic.update)
    route.delete('/api/users/{id}', UserLogic.delete)
    
    return route

Route Groups

Group routes with a common prefix:

with route.group('/admin'):
    route.view('/dashboard', 'admin.dashboard')
    route.view('/users', 'admin.users')
    route.get('/api/stats', AdminLogic.stats)
No decorators! All routes are defined in one place for better organization and maintainability.

MVL Architecture

FlaskIt uses the Model-View-Logic pattern for clean separation of concerns:

Model

Data structure & database schema

Service

CRUD operations & data access

Logic

Business logic & validation

View

Presentation & templates

Example Flow

1. Model (app/model/user.py)

from app.database import db

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    email = db.Column(db.String(120))
    
    def to_dict(self):
        return {
            'id': self.id,
            'username': self.username,
            'email': self.email
        }

2. Service (app/service/user_service.py)

from app.model.user import User
from app.database import db

class UserService:
    @staticmethod
    def get_all_users():
        return User.query.all()
    
    @staticmethod
    def create_user(data):
        user = User(**data)
        db.session.add(user)
        db.session.commit()
        return user

3. Logic (app/logic/users.py)

from flaskit import jsonify, request
from app.service.user_service import UserService

class UserLogic:
    @staticmethod
    def get_all():
        users = UserService.get_all_users()
        return jsonify({
            'success': True,
            'data': [u.to_dict() for u in users]
        })
    
    @staticmethod
    def create():
        data = request.get_json()
        user = UserService.create_user(data)
        return jsonify({
            'success': True,
            'data': user.to_dict()
        }), 201

FlaskIt Watch

Built-in monitoring dashboard inspired by Laravel Telescope. Access real-time metrics and insights at /_watch.

System Metrics

CPU, Memory, and Disk usage in real-time

Routes List

All registered routes with HTTP methods

Request Logs

Last 100 HTTP requests with timestamps

Project Structure

File counts and project organization

Production Note: Disable Watch in production or restrict access to authorized users only.

Discord Notifications

Send beautiful notifications to Discord webhooks for user events, errors, and alerts.

Setup

Add webhook URLs to your .env file:

.env
                                
DISCORD_NEWUSER=https://discord.com/api/webhooks/...
DISCORD_CONTACT=https://discord.com/api/webhooks/...
DISCORD_ERRORS=https://discord.com/api/webhooks/...

Usage

from flaskit import discord, discord_colors

# Simple notification
discord.send_simple("newuser", "New user registered!")

# Success notification
discord.send_success("newuser", "User created!", details={
    "Username": "john_doe",
    "Email": "john@example.com"
})

# Error notification
discord.send_error("errors", "Database error", details=str(error))

Read full guide →

Data Loader

Manage application data with the built-in JSON data loader. Perfect for configuration, settings, and public data.

data.json
{
  "web": {
    "social": {
      "whatsapp": "https://wa.me/1234567890",
      "facebook": "https://facebook.com/..."
    }
  },
  "contact": {
    "email": "contact@example.com",
    "phone": "+1234567890"
  }
}

Access Data

from flaskit import get_data, all_data

# Get specific value with dot notation
whatsapp = get_data('web.social.whatsapp')
email = get_data('contact.email')

# Get all data
all_config = all_data()

Update Existing Projects

Update older FlaskIt projects to the latest version without breaking changes:

# Update FlaskIt package
pip install --upgrade flaskit-love

# Update project files
cd your-project
flaskit update

# Install new dependencies
pip install -r requirements.txt

The flaskit update command safely adds new features without modifying your code.

Deployment

Deploy your FlaskIt application to production using any Flask-compatible hosting platform.

Gunicorn (Recommended)

# Install Gunicorn
pip install gunicorn

# Run with Gunicorn
gunicorn -w 4 -b 0.0.0.0:8000 app:app

Environment Variables

Set production environment variables:

FLASK_ENV=production
SECRET_KEY=your-production-secret-key
DATABASE_URL=postgresql://...

Best Practices

✅ Organize Code by Feature

Keep related logic, services, and models together

✅ Use Services for Data Access

Never access database directly from Logic

✅ Name Routes Consistently

Use dot notation: users.index, users.show, users.store

✅ Keep Logic Thin

Complex operations belong in Services

✅ Validate Input

Always validate user input in Logic layer

✅ Handle Errors Gracefully

Use try-catch and return meaningful error messages

You're viewing documentation for FlaskIt v0.2.0

View Changelog