Skip to content
Kapsulon edited this page Nov 4, 2024 · 5 revisions

The Server part of the project is made using SvelteKit, a JavaScript framework made to simplify all server actions (fetch, http protocol, ...) and related to Svelte framework.

Database

The project data is stored only in a AWS cluster using Vercel, a deployer and web-app maintainer. The database is written in SQL using PostgreSQL framework.

The following is a representation of our database schemas :

model User {
  id             Int       @id @unique @default(autoincrement())
  email          String    @unique
  role           UserRole  @default(USER)
  token          String    @unique
  hashedPassword String
  createdAt      DateTime  @default(now())
  username       String    @unique
  Service        Service[]
  Program        Program[]
}

model Program {
  id      Int      @id @unique @default(autoincrement())
  name    String
  actions Action[]
  User    User?    @relation(fields: [userId], references: [id])
  userId  Int?
}

model Action {
  id        Int        @id @unique @default(autoincrement())
  programId Int?
  actionId  String
  metadata  Json?
  persistentData Json?
  program   Program?   @relation(fields: [programId], references: [id])
  reactions Reaction[]
}

model Reaction {
  id         Int     @id @unique @default(autoincrement())
  reactionId String
  actionId   Int?
  metadata   Json?
  persistentData Json?
  action     Action? @relation(fields: [actionId], references: [id])
}

model Service {
  id           Int      @id @unique @default(autoincrement())
  userId       Int?
  metadata     Json
  providerType Provider
  User         User?    @relation(fields: [userId], references: [id])
}

enum UserRole {
  USER
  API_USER
  ADMIN
}

enum Provider {
  DISCORD
  STEAM
  SPOTIFY
  BATTLENET
  REDDIT
  TWITCH
}

API Routes

The API routes are located in /api route. All the API routes are protected using JWT session checking.

About JSON (/api/about.json)

This route is made to list all current implemented services, their actions and related reactions. As of this moment, the route is currently templated and not working dynamically with our database.

Authentication (/api/auth)

This route is made to encapsulate all the authentication methods for the API user.

  • POST /api/auth/login: Login the user using JWT encryption.
    • Required body: (JSON)
      {
          "email": "string",
          "password": "string"
      }
  • POST /api/auth/register: Register the user using JWT encryption.
    • Required body: (JSON)
      {
          "email": "string",
          "password": "string",
          "username": "string",
          "role": "USER"
      }
  • GET /api/auth/logout: Logout the user. (deletes their token)
    • Required headers:
      • Authorization: Bearer <token>

User data (/api/user)

  • GET /api/user: Get the user data.
    • Required headers:
      • Authorization: Bearer <token>
  • POST /api/user: Update the user data.
    • Required headers:
      • Authorization: Bearer <token>
    • Required body: (JSON)
      {
          "email": "string",
          "password": "string",
          "username": "string"
      }

Service Linking (/api/link)

This route is made to encapsulate service routes to link the latter to the user. The routes architecture are the following : /api/link/{service_name}

Services that are available include:

  • Spotify
  • Discord
  • Steam
  • BattleNet
  • Reddit
  • Twitch

Service Unlinking (/api/unlink)

This route is the same as Service Linking but used to unlink services.

Program (/api/program)

This route is made to encapsulate all the program routes for the user.

  • GET /api/program: Get all the programs of the user.
    • Required headers:
      • Authorization: Bearer <token>
  • POST /api/program: Create a new program.
    • Required headers:
      • Authorization: Bearer <token>
    • Required body: (JSON)
      {
          "name": "string"
      }
  • DELETE /api/program/{program_id}: Delete a program.
    • Required headers:
      • Authorization: Bearer <token>
  • PATCH /api/program/{program_id}: Update a program.
    • Required headers:
      • Authorization: Bearer <token>
    • Required body: (JSON)
      {
          "name": "string"
      }
  • PUT /api/program/{program_id}/node: Add a node to a program.
    • Required headers:
      • Authorization: Bearer <token>
    • Required body: (JSON)
      {
          "isAction || isReaction": "boolean (true)",
          "id || reactionId": "number",
          "metadata": "JSON"
      }
  • DELETE /api/program/{program_id}/node: Delete a node from a program.
    • Required headers:
      • Authorization: Bearer <token>
    • Required body: (JSON)
      {
          "isAction || isReaction": "boolean (true)",
          "id": "number"
      }
  • PATCH /api/program/{program_id}/node: Update a node from a program.
    • Required headers:
      • Authorization: Bearer <token>
    • Required body: (JSON)
      {
          "isAction || isReaction": "boolean (true)",
          "id": "number",
          "metadata": "JSON"
      }

Get available Actions (/api/actions)

This route is made to list all the available actions for the user.

  • GET /api/actions: Get all the actions.
    • Required headers:
      • Authorization: Bearer <token>

Get available Reactions (/api/reactions)

This route is made to list all the available reactions for the user.

  • GET /api/reactions: Get all the reactions.
    • Required headers:
      • Authorization: Bearer <token>