Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Architecture

Jonas Wanke edited this page Apr 8, 2021 · 14 revisions

Modules

Warning: These infos are soon deprecated and have to be updated when the refactorings proposed in Home are completed.

The app is divided into modules, each of which has its own folder (inside app/lib/) and is responsible for a part of the app (for example, there's a news module and a dashboard module).

Inside each module, there are four parts:

  1. The data.dart file defines the module's entities. Entities are classes that represent something in the domain, for example Homework, NewsArticle, etc. All entities implement Entity and have an Id<YourEntityType> that can uniquely identify them among other entities of the same type. Also, because we use hive for data persistence, you may see entities marked with a @HiveType(typeId: TypeId.yourEntityType) annotation. (You need to declare TypeId.yourEntityType first inside lib/app/hive.dart — just choose the biggest number you find there + 1).
  2. The routes.dart file contains a public <module name>Routes declaration containing all routes this module can handle. Think of routes like URLs in the browser — in fact, these are the same as those of the HPI Schul-Cloud Web-Client so users can open webpages in the app. The <module name>Routes is then registered in lib/app/routing.dart.
  3. The widgets folder contains the widgets that this module displays or offers to other parts of the app.
  4. The <module name>.dart file simply exports all the classes that are used by other modules.

A word about app

The app module takes care of stuff that's used throughout the app.

This e.g. includes Services — classes that handle some logic — like UserService and ApiNetworkService.

The app module also provides common widgets that are used across multiple modules.

📦 Packages

Packages are great! Whenever we see some piece of code that can be reused by other projects, we try to create a package for it.

Here are the most important packages we use:

  • 💾 Data layer:
    • hive: The database we use for persisting Entitys.
    • hive_cache: A thin wrapper around hive offering references to other Entitys.
  • 🖼 UI layer:
  • General:
    • logger: When logging stuff, use logger.i() (for infos, or .v() (verbose), .e() (error), etc.) instead of print for prettier output!
    • time_machine: When doing anything related to date & time, use this package. It takes care of time zones, formatting, etc.