Blueprint Overview
Blueprints are defined inapp/main/__init__.py and registered in app/__init__.py:setup_blueprints():
The Four Blueprints
1. Main Blueprint
Purpose: Primary application routes for authenticated users Location:app/main/
Features:
- Session management (makes sessions permanent)
- Saves service/organisation context after requests
- Contains all user-facing functionality
make_session_permanent() function sets sessions to expire after 20 hours of inactivity, while save_service_or_org_after_request() stores the current service or organisation in the session.
2. JSON Updates Blueprint
Purpose: JSON endpoints for asynchronous page updates Location:app/main/ (shares views with main blueprint)
Use Cases:
- Auto-updating dashboards
- Real-time notification status updates
- Live data feeds without full page reloads
3. No Cookie Blueprint
Purpose: Routes that should not set or modify cookies Location:app/main/ (shares views with main blueprint)
Features:
- No session permanence
- No service/org saving
- Prevents race conditions in asynchronous requests
- Letter template previews (iframes)
- Email branding previews
- Document downloads
- Any asynchronously loaded subresources
4. Status Blueprint
Purpose: Health checks and system status Location:app/status/
Features:
- Unauthenticated
- Unstyled (minimal HTML)
- No cookies
- No session handling
- Load balancer health checks
- Monitoring systems
- Uptime checks
View Organization
Views are organized inapp/main/views/ by functional area:
Authentication & User Management
Service Management
Templates & Messaging
Organisation Management
Branding & Customization
Platform Administration
API & Integration
Miscellaneous
Complete View List
The application includes 46 view modules:- add_service
- agreement
- api_keys
- code_not_received
- conversation
- dashboard
- document_download
- email_branding
- feedback
- find_users
- forgot_password
- history
- inbound_number
- index
- invites
- jobs
- join_service
- letter_branding
- make_your_service_live
- manage_users
- new_password
- notifications
- org_member_make_service_live
- organisations/ (directory)
- performance
- platform_admin
- pricing
- providers
- register
- report_requests
- returned_letters
- security_policy
- send
- service_settings/ (directory)
- sign_in
- sign_out
- sub_navigation_dictionaries
- template_email_files
- templates
- tour
- two_factor
- unsubscribe_requests
- uploads
- verify
- webauthn_credentials
- your_account
- your_services
Route Registration
Routes are registered using decorators on view functions:Route Patterns
Common route patterns:Forms
Forms are defined inapp/main/forms.py (over 118,000 lines, indicating extensive form validation):
Validators
Custom form validators are inapp/main/validators.py, providing:
- Email validation
- Phone number validation
- Template content validation
- Permission checking
- Unique constraint validation
Permission Decorators
Views use permission decorators to control access:Blueprint Registration
Blueprints are registered inapp/__init__.py:setup_blueprints():
Best Practices
When to Use Each Blueprint
- main: All standard user-facing pages
- json_updates: AJAX endpoints that return JSON
- no_cookie: Embedded content, previews, downloads
- status: Health checks only
View Organization
- Group related views in the same module
- Use subdirectories for complex feature areas (organisations, service_settings)
- Keep view functions focused and delegate to models/clients
- Use decorators for authentication and authorization
Next Steps
- Models - Learn about data models used in views
- API Clients - Understand how views interact with the API
- Application Structure - See the overall architecture