The V1 MVC Framework was developed as a personal project to help understand the Model-View-Controller (MVC) architecture by building a small-scale version. The primary goal was to explore the processes involved in structuring an MVC-based application, including routing, request handling, data validation, transactions, and rendering views. This framework serves as a hands-on learning tool to deepen understanding of how MVC components interact.
- Hands-on MVC Understanding: Built to explore how small-scale MVC applications work.
- Lightweight and Modular: Each component is independent, making it easy to extend.
- Practical Learning: Focuses on applying theoretical MVC concepts in a structured manner.
This documentation details the core components of the framework and demonstrates how to build a simple web application using it.
The V1AbstractController class enforces a structured approach to controllers while allowing flexibility in defining CRUD operations.
- All controllers inherit from
V1AbstractControllerand must implement__init__. - A controller method processes the data received from the body(kwargs) of the request and returns a response, which is passed to the view, as a kwargs
controller_response=response.
The logging module provides structured logs for debugging and monitoring.
- Captures errors, warnings, and informational logs.
- Logs are stored in
error.log,info.log, andwarning.logfiles.
Handles atomic data operations to maintain integrity.
- Begin, commit, and rollback transactions.
- Ensures data consistency when multiple operations are performed.
Provides input validation for key-value pairs.
- Ensures keys and values conform to specific rules.
- Validates emails, phone numbers, and URLs.
Manages application data and enforces validation rules.
- CRUD operations for structured data storage.
- Persistent storage using JSON.
- Custom validation rules for flexible data integrity enforcement.
Maps URLs to controllers and views dynamically.
- The router connects an incoming request to a specific controller action.
- The controller's response is passed as a
kwargto the assigned view.
Handles rendering JSON and HTML templates.
- Views inherit from
V1BaseViewand must implement__init__. - The controller response is received as a
kwargand processed. - The view must return a response, or no content will be displayed.
Extracts relevant data from incoming HTTP requests.
- Parses GET and POST data.
- Handles file uploads.
- Validates headers to ensure proper request format.
Constructs structured HTTP responses for client requests.
- Supports status codes (
200,404,500). - Handles binary and text responses.
- Automatically sets correct headers for content type.
Processes and saves uploaded files to a structured directory.
- Categorizes files by extension for organized storage.
- Ensures secure file handling by preventing unwanted overwrites.
Acts as a lightweight web server to process requests.
- Handles incoming HTTP requests.
- Serves static files (CSS, JS, images).
- Routes requests to the appropriate controller.
Create a controller that processes user requests.
# File - webapp_name.hello_controller.py
from controllers.v1_Controller import V1AbstractController
class HelloController(V1AbstractController):
def __init__(self):
pass
def hello(self, **kwargs):
return "Hello, World!"Create a view that handles rendering the response.
# File - webapp_name.hello_view.py
from views.v1_View import V1BaseView
class HelloView(V1BaseView):
def __init__(self):
pass
def render(self, **kwargs):
message = kwargs["controller_response"]
return f"<h1>{message}</h1>"Define the route in the v1_router.py file.
# File - webapp_name.hello_router.py
from webapp_name.beta_view import HelloView
from webapp_name.hello_controller import HelloController
from routers.v1_Router import V1Router
router = V1Router()
router.add_route("/hello", HelloController, "hello", HelloView)Before starting the server, ensure you run the file responsible for registering routes:
python -m webapp_name.hello_router
Run the following command to start the server:
python -m servers.v1_runserver
Run the server and visit http://127.0.0.1:8080/hello.
The V1 MVC Framework includes a development dashboard that helps you manage and debug your applications. The dashboard consists of a React frontend and a Flask backend.
- First, start the Flask backend server:
# From the root directory of the project
python -m mvc-dashboard.server.app- Then, in a new terminal, start the React frontend:
# From the mvc-dashboard directory
cd mvc-dashboard
npm install # Only needed first time
npm startThe dashboard will be available at http://localhost:3000.
- Server Management: Start, stop, and restart your MVC server
- Route Testing: Test your routes with different HTTP methods and content types
- File Management: View and edit your project files
- Real-time Logs: Monitor server and application logs
- Project Selection: Switch between different web applications
If you encounter any issues:
- Make sure both the Flask backend and React frontend are running
- Check that the MVC server is properly configured
- Verify that all required dependencies are installed
- Check the console for any error messages
For more detailed information about the dashboard components and their usage, refer to the dashboard documentation.
The V1 MVC Framework was built as a learning project to explore MVC principles by developing a fully functional small-scale framework. It covers essential features like routing, transactions, request handling, and views while maintaining simplicity. This framework serves as an excellent tool for gaining hands-on experience with MVC-based development.
- Client sends a request →
/hello. - Router matches the request and calls
HelloController.hello(). - Controller processes logic and returns
"Hello, World!". - Router sends the response to
HelloView.render()as akwarg. - View processes the response and returns
"<h1>Hello, World!</h1>". - The rendered response is sent to the client's browser.
If a view does not return anything, no content will be displayed.
This flow ensures a clear separation of concerns between routing, controller logic, and rendering views.
netstat -ano | findstr :8080
taskkill /PID [PID_NUMBER] /F