-
Notifications
You must be signed in to change notification settings - Fork 8
Backend
This page keeps all information and steps to install and configure the Appwrite backend. All commands are for Linux only. If you wish to use another OS, you will have to adapt them to your OS.
The backend of the Campus App serves as the main management unit for all processes the involve push notifications and data storage. As of right now, Appwrite is used as our backend software.
Upon startup of the app a new user account or session, depending on whether an account already exists, is created. Each account has a randomized email address serving as the user identifier and a randomized password. Both values are random numbers and cannot be traced back to any personal data.
The following features are currently backed by our backend:
- Push notifications for saved events.
- This is done by saving the Firebase Messaging token and the id of the event in the
saved_events
collection under thepush_notifications
database. - Upon startup the saved events are synchronized across the server and the app, which is done by adding locally saved events to the database and removing events that are no loner saved on the client side.
- This is done by saving the Firebase Messaging token and the id of the event in the
- Configuration storage
- Serving dynamic configuration attributes e.g. API URLs, update statuses, etc.
System requirements:
- 1 CPU Core and 2GB of RAM
- Docker
- Docker Dompose Version 2
Follow the installation guide as instructed here: https://appwrite.io/docs/installation
In order to create the databases you also have to install the Appwrite CLI which can be found here: https://appwrite.io/docs/command-line
After setup, make sure to follow the Environment Variables section, otherwise you won't be able to communicate with your own backend
After you have installed the backend, you have to create your first project with a unique project id.
To create the required databases for the campus app, you have to run the following commands:
- Create the database:
appwrite databases create --databaseId push_notifications --name 'Push Notifications'
-
Create the saved events collection:
appwrite databases createCollection --databaseId push_notifications --collectionId saved_events --name 'Saved Events' --permissions 'create("users")' --documentSecurity true
-
Create the following attributes for the
saved_events
collection:- String fcmToken :
appwrite databases createStringAttribute --databaseId push_notifications --collectionId saved_events --key fcmToken --size 250 --required true
- int eventId :
appwrite databases createIntegerAttribute --databaseId push_notifications --collectionId saved_events --key eventId --required true
- String startDate :
appwrite databases createStringAttribute --databaseId push_notifications --collectionId saved_events --key startDate --size 30 --required true
- String fcmToken :
-
Create an index for the
saved_events
collection:appwrite databases createIndex --databaseId push_notifications --collectionId saved_events --key index --type key --attributes 'fcmToken' --orders 'ASC'
- Create the
accounts
database:appwrite databases create --databaseId accounts --name 'Accounts'
-
Create the
last_login
collection:appwrite databases createCollection --databaseId accounts --collectionId last_login --name 'Last Login' --permissions 'create("users")' --documentSecurity true
-
Create the following attributes for the
last_login
collection:- String userId :
appwrite databases createStringAttribute --databaseId accounts --collectionId last_login --key userId --size 25 --required true
- String date :
appwrite databases createStringAttribute --databaseId accounts --collectionId last_login --key date --size 30 --required true
- String userId :
-
Create an index for the
last_login
collection:appwrite databases createIndex --databaseId accounts --collectionId last_login --key index --type key --attributes 'userId' --orders 'ASC'
- Create the
data
database:appwrite databases create --databaseId data --name 'Data'
-
Create the
publishers
collection:appwrite databases createCollection --databaseId data --collectionId publishers --name 'Publishers' --permissions 'read("any")'
-
Create the following attributes for the
publishers
collection:- String wpUserId :
appwrite databases createIntegerAttribute --databaseId data --collectionId publishers --key id --required true
- String name :
appwrite databases createStringAttribute --databaseId data --collectionId publishers --key name --size 100 --required true
- String initiallyDisplayed :
appwrite databases createBooleanAttribute --databaseId data --collectionId publishers --key initiallyDisplayed --xdefault false --required false
- bool hidden :
appwrite databases createBooleanAttribute --databaseId data --collectionId publishers --key hidden --xdefault false --required false
- String wpUserId :
-
Create an index for the
publishers
collection:appwrite databases createIndex --databaseId data --collectionId publishers --key index --type key --attributes 'id' --orders 'ASC'
-
Create the
study_courses
collection:appwrite databases createCollection --databaseId data --collectionId study_courses --name 'Studiengänge' --permissions 'read("any")'
-
Create the following attributes for the
study_courses
collection:- String wpUserId :
appwrite databases createIntegerAttribute --databaseId data --collectionId study_courses --key pId --required true
- String name :
appwrite databases createStringAttribute --databaseId data --collectionId study_courses --key name --size 100 --required true
- String faculty :
appwrite databases createStringAttribute --databaseId data --collectionId study_courses --key faculty --size 220 --required true
- String wpUserId :
-
Create an index for the
study_courses
collection:appwrite databases createIndex --databaseId data --collectionId study_courses --key index --type key --attributes 'pId' --orders 'ASC'
Cloud functions can be written in a variety of programming language such as Python or Javascript. We chose JavaScript, powered by NodeJS to run our cloud functions.
-
Create the respective Cloud Function:
appwrite functions create --functionId push_saved_events --name 'Saved Event Push Notifications' --runtime node-16.0 --execute users
-
Create an API key and set the
API_KEY
secret as a function variable using the Appwrite console webinterface. -
Create a deployment through the web interface or run the following command (Replace the path with your path to the savedEvents cloud function folder from our cloud functions repository:
appwrite functions createDeployment --functionId push_saved_events --activate=true --entrypoint="savedEventPushNotification.js"--code aw-functions/push-notifications/savedEventsNotification/
-
Create the respective Cloud Function:
appwrite functions create --functionId create_user --name 'Create User' --runtime node-16.0 --execute any
-
Add your Appwrite API key as as a function variable, while using the
API_KEY
identifier. -
Generate a random string and set it as a function variable with the
AUTH_KEY
identifier. -
Create a deployment through the web interface or run the following command:
appwrite functions createDeployment --functionId create_user --activate=true --entrypoint="createUser.js" --code aw-functions/users/createUser/
-
Create the respective Cloud Function:
appwrite functions create --functionId push_general --name 'General Push Notifications' --runtime node-16.0
-
Generate a random string and set it as a function variable with the
AUTH_KEY
identifier. -
Create a deployment through the web interface or run the following command:
appwrite functions createDeployment --functionId push_general --activate=true --entrypoint="sendPushNotification.js" --code aw-functions/push-notifications/generalNotification
Miscellaneous commands:
- Delete deployment
appwrite functions deleteDeployment --deploymentId <Deployment-ID> --functionId <Function-ID>