Modular App System
The modular app system is the core feature of Django SuperApp. It allows you to create fully self-contained Django apps that automatically integrate into your project without manual configuration.What is a SuperApp App?
A SuperApp app is a standard Django app enhanced with:- Self-contained settings -
settings.pywithextend_superapp_settings()function - Self-contained URLs -
urls.pywith URL extension functions - Isolated dependencies - Optional
requirements.txtfor app-specific packages - Automatic discovery - No manual registration needed
App Structure
Each app in SuperApp follows a standardized structure:Required Files
settings.py
settings.py
Contains the
extend_superapp_settings(main_settings) function that modifies the main project settings.urls.py
urls.py
Contains URL extension functions that add routes to the main project.
Optional Files
requirements.txt
requirements.txt
Lists Python packages specific to this app. These should be installed during deployment if the app is used.
admin/
admin/
Directory containing admin model configurations. Each model should have its own file.
Automatic App Discovery and Loading
SuperApp uses Python’s built-in module discovery to automatically find and integrate apps. The discovery mechanism is implemented in the core framework files.Discovery Process
Fromsrc/django_superapp/settings.py:9-21:
How It Works
- Module Iteration -
pkgutil.iter_modules()scans all modules insuperapp/apps/ - Dynamic Import - Each app’s
settings.pyis imported usingimportlib.import_module() - Function Check - Checks if
extend_superapp_settings()function exists - Settings Integration - Calls the function with
main_settingsdictionary - Error Handling - Gracefully skips apps without
settings.py
The discovery mechanism only raises exceptions for actual errors (like syntax errors). Missing
settings.py files are silently skipped, making apps with only URL configurations valid.URL Discovery
Fromsrc/django_superapp/urls.py:7-19:
Real-World App Examples
Based on the conventions documented inCONVENTIONS.md:14-28:
Basic App Structure
App with Admin Navigation
FromCONVENTIONS.md:59-81:
App with Custom Admin
FromCONVENTIONS.md:83-94:
App Lifecycle
Best Practices
One Concern Per App
Keep apps focused on a single domain or feature (authentication, blog, API, etc.)
Self-Contained
Apps should be independent and not rely on other SuperApp apps when possible
Clear Dependencies
Document all app dependencies in requirements.txt
Proper Admin Organization
Keep admin files in the admin/ directory with one file per model
Conventions Summary
Based onCONVENTIONS.md:
- Apps live in
superapp/apps/<app_name>/ - Settings integration via
extend_superapp_settings(main_settings) - URL integration via
extend_superapp_urlpatterns(main_urlpatterns) - App-specific dependencies in
requirements.txt - Admin files in
superapp/apps/<app_name>/admin/<model_name_slug>.py - Use
SuperAppModelAdminbased onunfold.admin.ModelAdmin - Register admins with
superapp_admin_site - Configure sidebar navigation in app’s
settings.pyviaUNFOLD['SIDEBAR']['navigation']
Next Steps
Settings Integration
Learn how to configure app settings
URL Integration
Learn how to register app URLs
Create Your First App
Build your first SuperApp app