MVC Architecture
Clear structure with separation of concerns: Models, Views, and Controllers.
Framefox is a modern Python web framework, designed to simplify the development of robust and maintainable web applications. Based on FastAPI, it adopts an object-oriented approach with a clear MVC architecture to improve developer productivity.
MVC Architecture
Clear structure with separation of concerns: Models, Views, and Controllers.
Built on FastAPI
High performance with automatic type validation and OpenAPI documentation.
Interactive Terminal
Built-in commands to quickly generate controllers, entities, and forms.
Advanced Routing System
Simple route decorators with customizable names and HTTP methods.
Install Framefox via pip:
pip install framefox
Create a new project:
mkdir my-projectcd my-projectframefox init
Start the development server:
framefox run
Your application is now accessible at http://localhost:8000
! 🎉
A Framefox project follows an organized structure:
Create a controller with the interactive terminal:
framefox create controller
Or manually create a src/controllers/home_controller.py
file:
from framefox.core.routing.decorator.route import Routefrom framefox.core.controller.abstract_controller import AbstractController
class HomeController(AbstractController): @Route("/", "home.index", methods=["GET"]) async def index(self): return self.render("home/index.html", { "message": "Welcome to Framefox!" })
@Route("/users/{id}", "home.user", methods=["GET"]) async def show_user(self, id: int): return {"user_id": id, "name": f"User {id}"}
The @Route
decorator defines your application routes:
/
, /users/{id}
)home.index
)["GET", "POST"]
)Framefox uses Jinja2 for template rendering. Create src/templates/home/index.html
:
<!DOCTYPE html><html><head> <title>My Framefox App</title> <link href="{{ asset('css/style.css') }}" rel="stylesheet"></head><body> <h1>{{ message }}</h1> <p>URL to user: <a href="{{ url_for('home.user', id=123) }}">User 123</a></p>
<!-- Automatic CSRF token --> <form method="POST"> {{ get_csrf_token() }} <input type="text" name="username" placeholder="Username"> <button type="submit">Submit</button> </form></body></html>
{{ url_for('route.name', param=value) }}
: Generate URLs{{ asset('path/file.css') }}
: Links to static assets{{ get_csrf_token() }}
: Automatic CSRF protection{{ get_current_user() }}
: Authenticated user{{ get_flash_messages() }}
: Flash messagesCreate typed forms with automatic validation:
from framefox.core.form.form_type import FormTypefrom framefox.core.form.field.text_type import TextTypefrom framefox.core.form.field.email_type import EmailType
class UserType(FormType): def build_form(self, form_builder): form_builder.add("name", TextType, { "required": True, "label": "Full Name" }) form_builder.add("email", EmailType, { "required": True, "label": "Email Address" })
Use the form in your controller:
@Route("/register", "user.register", methods=["GET", "POST"])async def register(self, request: Request): form = self.create_form(UserType)
await form.handle_request(request) if form.is_submitted() and form.is_valid(): # Process data data = form.get_data() self.flash("success", "Registration successful!") return self.redirect("user.success")
return self.render("user/register.html", {"form": form})
Framefox includes a complete authentication system:
In config/security.yaml
:
security: firewalls: main: pattern: ^/ authenticator: form_login login_path: /login check_path: /login_check default_target_path: /dashboard
access_control: - path: ^/admin roles: [ROLE_USER, ROLE_ADMIN] - path: ^/profile roles: [ROLE_USER]
class SecurityController(AbstractController): @Route("/login", "security.login", methods=["GET", "POST"]) async def login(self, request: Request): return self.render("security/login.html")
@Route("/logout", "security.logout", methods=["GET"]) async def logout(self): return self.redirect("security.login")
Define your entities with the integrated ORM:
from sqlmodel import Fieldfrom pydantic import EmailStr
from framefox.core.orm.abstract_entity import AbstractEntity
class User(AbstractEntity, table=True): id: int | None = Field(default=None, primary_key=True) username: str = Field(min_length=3, max_length=50) email: EmailStr = Field(nullable=False)
Create repositories for data access:
from framefox.core.orm.abstract_repository import AbstractRepositoryfrom src.entity.user import User
class UserRepository(Repository): def __init__(self): super().__init__(User)
Framefox provides a powerful interactive terminal:
# Generate a controllerframefox create controller
# Generate an entityframefox create entity
# Generate a userframefox create user
# Generate a complete CRUDframefox create crud
# List all routesframefox debug router
# Clear cacheframefox cache clear
Framefox includes several built-in middlewares:
from framefox.core.events.decorator.dispatch_event import DispatchEvent
class UserController(AbstractController): @Route("/users", "user.create", methods=["POST"]) @DispatchEvent("user.before_create", "user.after_create") async def create_user(self, request: Request): # Creation logic return {"success": True}
In development mode, access the web profiler at /_profiler
to analyze:
Build Your First App
Explore the ORM
Secure Your App
Deploy to Production
Ready to start? Framefox allows you to quickly develop modern and maintainable Python web applications. The framework philosophy prioritizes productivity without sacrificing flexibility!