# Architecture overview

### API

The API is built with Django Rest Framework and implements the [key concepts](https://icij.gitbook.io/prophecies/getting-started/key-concepts) of Prophecies.

<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><a href="https://icij.github.io/prophecies/api.html"><strong>Explore the API</strong></a> </td><td><em>Use this page to explore the latest specifications of the API.</em></td><td></td></tr><tr><td><a href="https://icij.github.io/prophecies/openapi.yml"><strong>Download API schema</strong></a></td><td><em>This schema follows the</em> <a href="https://swagger.io/specification/"><em>OpenAPI 3</em></a><em>. You can load this file in many OpenAPI clients, including Swagger or Redoc.</em></td><td></td></tr><tr><td><a href="https://jsonapi.org/"><strong>JSON:API specification</strong></a></td><td><em>The JSON:API spec is a standard for structuring JSON responses in APIs to optimize data exchange and efficiency.</em></td><td></td></tr></tbody></table>

### Stack

Prophecies is based on the following open source tools:

* Python 3.9, 3.10
* Node 16, 18
* Django 4.2
* Django Rest Framework 3.14
* Django Rest Framework JSON:API 6.1
* Pytest
* Vue 2.7
* Vue CLI 5
* Vuex ORM 0.36
* Jest 28
* Poetry
* Yarn

### Interaction workflow

This sequence diagram illustrates the communication flow within the Prophecies platform infrastructure, focusing on how a request travels from the user interface to the database and back.

{% @mermaid/diagram content="%%{
init: {
"theme": "base",
"themeVariables": {
"primaryColor": "#91ADAC",
"primaryTextColor": "#000",
"primaryBorderColor": "#EFEFEF",
"secondaryColor": "#235B59",
"noteBkgColor": "#FFE980",
"noteBorderColor": "#FFE980"
}
}
}%%

sequenceDiagram
participant UI as User Interface (Vue 2)
participant API as API (Django Rest Framework)
participant Django as Django
participant Database as Database (PostgreSQL)

```
UI->>+API: Sends HTTP request
API->>+Django: Passes request
Django->>+Database: SQL queries
Database-->>-Django: Returns data
Django-->>-API: Processes data
API-->>-UI: Responds with data (JSON:API)

Note over UI,Database: Interaction Flow" fullWidth="true" %}
```

### Database schema

Here is a simplified version of the Database schema.

{% @mermaid/diagram content="%%{
init: {
"theme": "base",
"themeVariables": {
"primaryColor": "#91ADAC",
"primaryTextColor": "#000",
"primaryBorderColor": "#EFEFEF",
"secondaryColor": "#235B59",
"noteBkgColor": "#FFE980",
"noteBorderColor": "#FFE980"
}
}
}%%

erDiagram
ChoiceGroup {
AutoField id
CharField name
}
AlternativeValue {
AutoField id
CharField name
CharField value
ForeignKey choice\_group
}
Choice {
AutoField id
CharField color
CharField name
CharField value
CharField shortkeys
ForeignKey choice\_group
BooleanField require\_alternative\_value
}
Project {
AutoField id
CharField name
ForeignKey creator
}
Task {
AutoField id
CharField name
CharField description
ForeignKey project
ForeignKey creator
PositiveIntegerField rounds
BooleanField automatic\_round\_attributions
BooleanField allow\_multiple\_checks
BooleanField allow\_items\_addition
PositiveIntegerField priority
ForeignKey choice\_group
CharField color
CharField record\_link\_template
BooleanField embeddable\_links
CharField embeddable\_record\_link\_template
CharField status
CharField template\_type
OneToOneField template\_setting
DateTimeField created\_at
ManyToManyField checkers
}
TaskRecord {
AutoField id
ForeignKey task
CharField uid
TextField original\_value
TextField predicted\_value
JSONField metadata
CharField status
PositiveIntegerField rounds
PositiveIntegerField priority
CharField link
CharField embeddable\_link
BooleanField locked
ForeignKey locked\_by
BooleanField has\_notes
BooleanField has\_disagreements
ManyToManyField bookmarked\_by
}
TaskRecordMedia {
AutoField id
ForeignKey task
ForeignKey task\_record
FileField file
CharField uid
CharField mime\_type
PositiveIntegerField height
PositiveIntegerField width
DateTimeField created\_at
DateTimeField updated\_at
}
TaskRecordReview {
AutoField id
ForeignKey task\_record
ForeignKey checker
PositiveIntegerField round
CharField status
ForeignKey choice
CharField note
DateTimeField note\_created\_at
DateTimeField note\_updated\_at
TextField alternative\_value
DateTimeField created\_at
DateTimeField updated\_at
}
AlternativeValue }|--|| ChoiceGroup : choice\_group
Choice }|--|| ChoiceGroup : choice\_group
Task }|--|| Project : project
Task }|--|| ChoiceGroup : choice\_group
TaskRecord }|--|| Task : task
TaskRecordMedia }|--|| Task : task
TaskRecordMedia }|--|| TaskRecord : task\_record
TaskRecordReview }|--|| TaskRecord : task\_record
TaskRecordReview }|--|| Choice : choice
" fullWidth="false" %}
