Skip to content

Dev's Guide: Backend basic concepts

Ashar Fuadi edited this page Aug 10, 2018 · 17 revisions

This section explains the basic knowledge required for understanding Judgels codebase on the backend side.

Tech stack

Database design

Judgels adapts the database design explained here: Phabricator Database Schema. In particular:

  • Here, by "objects" we mean objects as in REST resources. For example: users, problems, contests.
  • Each object in Judgels has a database-generated auto-increment ID. We don't use this ID for referencing objects.
  • Instead, each object in Judgels has a unique identifier called JID (Judgels ID) in the form of JIDXXXXYYYYYYYYYYYYYYYYYYYY, where X is object type code and Y is a shortened UUID. For example: JIDUSER7uMucIkm1exJTu7sJvxR.
  • JIDs as unique identifiers enables easy backup or migration between different Judgels app instances.
  • In addition to JID, each object may have user-friendly ID. For example: usernames, problem slugs, contest slugs.
  • Complex properties are stored either on disk database as JSON strings. For example: grading result details.
  • Additionally, each object may have the following columns:
    • createdBy, createdAt, createdIp: user, time, and IP when this object is created.
    • updatedBy, updatedAt, updatedIp: user, time, and IP when this object is updated.

REST application layers

  1. Service: declares the REST API endpoints. Example: ContestService.
  2. Resource: implements the REST API endpoints. Example: ContestResource.
  3. Role checker: authorizes REST API calls. Example: ContestRoleChecker.
  4. Store: manages CRUD operations of business objects. Example: ContestStore.
  5. Dao: declares the CRUD operations in database. Example: ContestDao.
  6. HibernateDao: implements the CRUD operations in database. Example: ContestHibernateDao.
  7. Model: represents a row in a database. Example: ContestModel.