Skip to content

Commit 7e702b6

Browse files
committed
docs(logic): outline Django request pipeline
1 parent ebb20b3 commit 7e702b6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/development/application-logic.md

+37
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,41 @@ Each of these directories contains a standalone Django app registered in the [se
4343
All of the common logic and [database models and migrations](./models-migrations.md) are defined in `benefits.core`, and this
4444
app is imported by the other apps.
4545

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+
4681
## Initial setup
4782

4883
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
238273
deactivate benefits
239274
```
240275

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
241278
[core-models]: https://github.com/cal-itp/benefits/blob/dev/benefits/core/models.py
242279
[core-session]: https://github.com/cal-itp/benefits/blob/dev/benefits/core/session.py
243280
[core-views]: https://github.com/cal-itp/benefits/blob/dev/benefits/core/views.py

0 commit comments

Comments
 (0)