@@ -43,6 +43,41 @@ Each of these directories contains a standalone Django app registered in the [se
43
43
All of the common logic and [ database models and migrations] ( ./models-migrations.md ) are defined in ` benefits.core ` , and this
44
44
app is imported by the other apps.
45
45
46
+ ## Django request pipeline
47
+
48
+ Each request to the Benefits app is ultimately a [ Django request] ( https://docs.djangoproject.com/en/5.0/ref/request-response/ )
49
+ and goes through the [ Django HTTP request pipeline] ( https://docs.djangoproject.com/en/5.0/topics/http/ ) .
50
+
51
+ Benefits uses middleware to pre- and post-process requests for (view) access control, session configuration, and analytics.
52
+ Benefits also uses context processors to enrich the Django template context with data needed for rendering on the front-end.
53
+
54
+ !!! example "Key supporting files"
55
+
56
+ [`benefits/core/context_processors.py`][core-context-processors]
57
+
58
+ [`benefits/core/middleware.py`][core-middleware]
59
+
60
+ In general, the flow of a Django request looks like:
61
+
62
+ ``` mermaid
63
+ flowchart LR
64
+ user((User))
65
+ style user stroke-width:2px
66
+
67
+ pre_middleware[Request middleware]
68
+ view_middleware[View-specific middleware]
69
+ context[Context processors]
70
+ view[View function]
71
+ post_middleware[Response middleware]
72
+
73
+ user -- Request --> pre_middleware
74
+ pre_middleware -- Request --> view_middleware
75
+ view_middleware -- Request --> context
76
+ context -- Request --> view
77
+ view -- Response --> post_middleware
78
+ post_middleware -- Response --> user
79
+ ```
80
+
46
81
## Initial setup
47
82
48
83
In this phase, the user makes the initial selections that will configure the rest of their journey.
@@ -238,6 +273,8 @@ benefits->>littlepay: enroll funding source in group
238
273
deactivate benefits
239
274
```
240
275
276
+ [ core-context-processors ] : https://github.com/cal-itp/benefits/blob/dev/benefits/core/context_processors.py
277
+ [ core-middleware ] : https://github.com/cal-itp/benefits/blob/dev/benefits/core/middleware.py
241
278
[ core-models ] : https://github.com/cal-itp/benefits/blob/dev/benefits/core/models.py
242
279
[ core-session ] : https://github.com/cal-itp/benefits/blob/dev/benefits/core/session.py
243
280
[ core-views ] : https://github.com/cal-itp/benefits/blob/dev/benefits/core/views.py
0 commit comments