refactor: split monolithic app.py into modular Flask application with factory pattern

- Created app/ package with 6 modules:
  - __init__.py: Application factory (create_app function)
  - routes.py: All route handlers (473 lines)
  - models.py: Data persistence layer (41 lines)
  - validators.py: Input validation functions (48 lines)
  - email_service.py: Email sending functions (85 lines)
  - utils.py: Utility functions (30 lines)

- Implemented Flask application factory pattern
- Created run.py as minimal entry point
- Updated all test imports to use new module structure
- Fixed template/static folder paths for package structure

- All 102 tests passing
- Improved maintainability with clear separation of concerns
- Follows Flask best practices for scalable applications
This commit is contained in:
2025-12-27 22:36:05 +01:00
parent 733ee756c7
commit f1d8bae6a1
18 changed files with 1254 additions and 229 deletions
+8 -3
View File
@@ -8,7 +8,7 @@ from io import BytesIO
from datetime import datetime
import pytest
import yaml
from app import app as flask_app
from app import create_app
from flask_mail import Mail
@@ -18,6 +18,9 @@ def app():
# Create a temporary directory for test applications
temp_dir = tempfile.mkdtemp()
# Create test Flask app using factory
flask_app = create_app()
# Configure app for testing
flask_app.config['TESTING'] = True
flask_app.config['SECRET_KEY'] = 'test-secret-key'
@@ -133,7 +136,9 @@ def mock_mail(app, monkeypatch):
self.sent_messages.append(message)
mock = MockMail()
monkeypatch.setattr('app.mail', mock)
# Patch the mail instance in the app package (used by email_service)
import app.email_service
monkeypatch.setattr(app.email_service, 'mail', mock)
return mock
@@ -142,7 +147,7 @@ def create_test_application(app, temp_applications_dir):
"""Factory fixture to create test application data."""
def _create(session_id='test-123', **kwargs):
"""Create a test application with the given session ID and data."""
from app import save_application_data
from app.models import save_application_data
data = {
'session_id': session_id,