Skip to content

Getting Started

Annika Muecke edited this page Aug 3, 2022 · 5 revisions

General information

We are using Firebase as backend provider and its database service Firestore to store our data.

Preliminary research

addressing issue #23

  • For building an app's backend, 3 main components need to be considered:
    • Middleware: connection from front-end to back-end
    • Database: indicates UI for data penetration and memory persistence
    • Server: offers resource-sharing content, web services, databases, file storage (Cloud?)
  • as we only require a backend for storing our database in the cloud (and thus making it accessible simultaneously from several devices in the future), setting up our own infrastructure would be a complete overkill for the first prototype
  • therefore, we decided to rely on a third party provider for our backend and compared some popular ones to choose the most suitable one for our application:
Firebase Back4App AWS (Amplify)
Flutter + React yes yes yes
Cross-platform yes yes yes
Conditions 1 GB, 20k writes/day, 50k reads/day 25k Requests/month, 250 MB Data Storage, 1 GB Transfer, 1 GB Storage after 1 year: 0,01 $/min per creation, 0,023$ per GB storage
Database type noSQL noSQL relational/ SQL

All services have comparable features and fulfill our requirements. Firebase offers the most storage, database reads/writes on its free plan, amongst all compared providers. Additionally, it provides a seamless integration with our frontend framework Flutter, as both are products from Google, and was therefore picked as the provider to work with.

Account information

The database is stored under a Google Account of our project using the mail address madlabhandball@gmail.com. It is linked with Annikas phone number (sometimes required for 2-Factor-Authentication, can be changed in the future) and the password is known to all team members. One can login to the firebase dashboard here: https://console.firebase.google.com/.

Set up

Installing Firebase CLI

https://firebase.google.com/docs/cli#setup_update_cli You can put the binary .exe file in the root of your projects directory.

Adressing issue #36

Set Up Cloud Firestore DB (only once for entire project)

followed https://firebase.google.com/docs/firestore/quickstart?authuser=1:
The project is called Handball Performance Tracker. We used "Testmodus" as Security mode and europe-central as storage place for the Firestore Database.

Add Firestore project to our flutter project (only once for entire project)

followed https://firebase.google.com/docs/flutter/setup?authuser=1&platform=ios:
Used Commands:

curl -sL https://firebase.tools | bash
firebase login (with group gmail account)
dart pub global activate flutterfire_cli
flutterfire configure --project=handball-performance-tracker

Use Firebase in the Flutter project (individually after cloning the project)

To use firebase in our Flutter project you need to install the plugin with flutter pub add cloud_firestore or just push pub get in your IDE.

Gui Tool

https://refiapp.io allows to edit firestore in a table view. This makes life much easier than using the editor in the browser.

Database layout

Adressing issue #38

Selecting a project to work

Disclaimer: this does not seem to work 100% yet

Run in your terminal: firebase projects:list grafik

Firestore: General information

  • data stored in documents, that are organized in collections
  • documents:
    • contain a set of key ("field")-value pairs
    • lightweight, json-like records
    • contain strings/lists/maps
    • max 1 MB
    • can contain subcollections
  • collections:
    • containers for documents
    • can only contain documents
    • no need to "create" or "delete" collections
    • after creating the first document in a collection, it exists
    • after deleting all of the documents in a collection, it no longer exists
  • references:
    • can be retrieved for every document/collection
    • can be created no matter if the document exists, does not perform any network operations
  • indexing
    • indexes are used to quickly look up the locations of queried items in the database
    • used for all queries in firestore
    • single-field indexes:
      • store a sorted mapping of all the documents in a collection that contain a specific field
      • automatically maintained by firestore forr each field in a document and each subfield in a map
    • composite indexes:
      • store sorted mapping of all documents in a collection
      • used to support queries that are not already supported by single-field-indexes
      • can be created manually during app programming
  • optimized for storing large collections of small documents
  • best practices:
    • avoid nesting data: when data at a location in your database is fetched,all child nodes are also retrieved automatically; normalize data instead, e.g. separate information as much as possible
    • for two-way relationships, storing data redundant is the most elegant way
    • pay attention that if a value is stored redundant, it needs to be deleted from multiple locations to finally delete it

Clone this wiki locally