Skip to content

Commit d1c4328

Browse files
authored
Merge pull request #686 from python-discord/readme-for-api-app
Add a README for the API app
2 parents e5b2750 + 073e09a commit d1c4328

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

pydis_site/apps/api/README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# The "api" app
2+
3+
This application takes care of most of the heavy lifting in the site, that is,
4+
allowing our bot to manipulate and query information stored in the site's
5+
database.
6+
7+
We make heavy use of [Django REST
8+
Framework](https://www.django-rest-framework.org) here, which builds on top of
9+
Django to allow us to easily build out the
10+
[REST](https://en.wikipedia.org/wiki/Representational_state_transfer) API
11+
consumed by our bot. Working with the API app requires basic knowledge of DRF -
12+
the [quickstart
13+
guide](https://www.django-rest-framework.org/tutorial/quickstart/) is a great
14+
resource to get started.
15+
16+
## Directory structure
17+
18+
Let's look over each of the subdirectories here:
19+
20+
- `migrations` is the standard Django migrations folder. You usually won't need
21+
to edit this manually, as `python manage.py makemigrations` handles this for
22+
you in case you change our models. (Note that when generating migrations and
23+
Django doesn't generate a human-readable name for you, please supply one
24+
manually using `-n add_this_field`.)
25+
26+
- `models` contains our Django model definitions. We put models into subfolders
27+
relevant as to where they are used - in our case, the `bot` folder contains
28+
models used by our bot when working with the API. Each model is contained
29+
within its own module, such as `api/models/bot/message_deletion_context.py`,
30+
which contains the `MessageDeletionContext` model.
31+
32+
- `tests` contains tests for our API. If you're unfamilar with Django testing,
33+
the [Django tutorial introducing automated
34+
testing](https://docs.djangoproject.com/en/dev/intro/tutorial05/) is a great
35+
resource, and you can also check out code in there to see how we test it.
36+
37+
- `viewsets` contains our [DRF
38+
viewsets](https://www.django-rest-framework.org/api-guide/viewsets/), and is
39+
structured similarly to the `models` folder: The `bot` subfolder contains
40+
viewsets relevant to the Python Bot, and each viewset is contained within its
41+
own module.
42+
43+
The remaining modules mostly do what their name suggests:
44+
45+
- `admin.py`, which hooks up our models to the [Django admin
46+
site](https://docs.djangoproject.com/en/dev/ref/contrib/admin/).
47+
48+
- `apps.py` contains the Django [application
49+
config](https://docs.djangoproject.com/en/dev/ref/applications/) for the `api`
50+
app, and is used to run any code that should run when the app is loaded.
51+
52+
- `pagination.py` contains custom
53+
[paginators](https://www.django-rest-framework.org/api-guide/pagination/) used
54+
within our DRF viewsets.
55+
56+
- `serializers.py` contains [DRF
57+
serializers](https://www.django-rest-framework.org/api-guide/serializers/) for
58+
our models, and also includes validation logic for the models.
59+
60+
- `signals.py` contains [Django
61+
Signals](https://docs.djangoproject.com/en/dev/topics/signals/) for running
62+
custom functionality in response to events such as deletion of a model
63+
instance.
64+
65+
- `urls.py` configures Django's [URL
66+
dispatcher](https://docs.djangoproject.com/en/dev/topics/http/urls/) for our
67+
API endpoints.
68+
69+
- `views.py` is for any standard Django views that don't make sense to be put
70+
into DRF viewsets as they provide static data or other functionality that
71+
doesn't interact with our models.

0 commit comments

Comments
 (0)