An API to handle most of the things related to XTeam Games. The main idea is to have a communication bridge between new games developed by the XTeam community (and game jam winners) and the XTeam Universe. So we can have a cohesive universe around the same user sessions, achievements, experiences, etc. With this API a game dev can publish their game within the XTeam Universe (XTU). They can also manage things like CRUD leaderboards, CRUD achievements, and CRUD Items. Monitor game's usage data, and authenticate with the same user across all XTU platforms.
The Admin Panel (Frontend APP) is connected to this API allowing XTeam admins to run games on Slack (like The Tower and The Arena) and the rest of the things a regular game dev can do.
Let's setup the project!🥹
Spin up the containers by running one of these two commands:
docker-compose up -d
You can now access the DB with your favorite client. If you don't use any, we recommend you OmniDB
Here's an example of the OmniDB client with the project DB running.
Create a new migration file running: npm run db:migrate:add some-new-table-name
.
Change the extension of the created file from .js
to .ts
.
Paste the following template to your migration:
import type { QueryInterface, Sequelize } from 'sequelize';
interface SequelizeContext {
context: {
queryInterface: QueryInterface;
Sequelize: Sequelize;
};
}
module.exports = {
async up({ context: { queryInterface } }: SequelizeContext) {
return queryInterface.sequelize.transaction(async (transaction) => {});
},
async down({ context: { queryInterface } }: SequelizeContext) {
return queryInterface.sequelize.transaction(async (transaction) => {});
},
};
Implement those two functions. up
is the migration and down
is the reverse of it. For example, in order to add a new column isEnabled
to the Game
table:
import type { QueryInterface, Sequelize } from 'sequelize';
interface SequelizeContext {
context: {
queryInterface: QueryInterface;
Sequelize: Sequelize;
};
}
module.exports = {
async up({ context: { queryInterface } }: SequelizeContext) {
return queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.addColumn(
'Game',
'isEnabled',
{ type: Sequelize.BOOLEAN },
{ transaction }
);
});
},
async down({ context: { queryInterface } }: SequelizeContext) {
return queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.removeColumn('Game', 'isEnabled', { transaction });
});
},
};
Now modify the model class, Game.ts
in this case, and add a new field:
export class Game extends Model<GameAttributes, GameCreationAttributes> {
@AllowNull(false)
@Column(DataType.BOOLEAN)
declare isEnabled: boolean;
// …
}
You're all set! Make sure everything works locally before pushing or merging.
Never ever ever modify it. Not even once.
Never ever modify any past migrations. If a migration was created and deployed, you can't ever change it. If you need to modify it, just create a new migration which will run after the previous one.
The API needs some env vars to work properly. You can ask @ccmoralesj for this.
Just grab the .env.example
file and copy everything into a new file called .env.dev
. It will look something like this at first.
# API
HOST=0.0.0.0
#HOST=127.0.0.1
PORT=3000
# DATABASE
DB_USERNAME=
DB_PASSWORD=
DB_NAME=gameshq_api
DB_HOSTNAME=127.0.0.1
DB_PORT=5434
# THE ARENA APP DEV
SLACK_ARENA_TOKEN=
SLACK_ARENA_SIGNING_SECRET=
# Private Channel
SLACK_ARENA_XHQ_CHANNEL=
# THE TOWER APP
SLACK_TOWER_SIGNING_SECRET=
SLACK_TOWER_TOKEN=
SLACK_THE_TOWER_CHANNEL=
# CAMPAIGN APP
SLACK_CAMPAIGN_SIGNING_SECRET=
SLACK_CAMPAIGN_TOKEN=
SLACK_NEUTRAL_ZONE_CHANNEL=
# FRONT-END-APP
FRONT_END_APP_BOT_TOKEN=
FRONT_END_SIGNING_SECRET=
# COOKIE
COOKIE_PASSWORD=
# GOOGLE API CREDS
GOOGLE_APPLICATION_CLIENT_ID=
GOOGLE_APPLICATION_CLIENT_SECRET=
GOOGLE_APPLICATION_CLIENT_RANDOM_PASSWORD=
# FIREBASE
GOOGLE_APPLICATION_CREDENTIALS=/some/path/to/google_credentials_games_api.json
We are almost there with the setup.🥲 Now it's time to run the API
First, make sure you're using our recommended version of Node and npm by running these commands:
nvm use
Following up, we have to install all required dependencies to run the project:
npm install
Finally, run the application in development mode with the following command:
npm run dev
# If you want to run "production" mode use npm start
The API should be up and running 🎉at port 3000!🎉 You can verify by browsing to http://localhost:3000/documentation
Let's start coding!🤓
Documentation is auto-generated based on the Joi validation provided. You can access it at /documentation
.
Collaborate in this repo is quite easy.
You only need to pick up a ticket from the JIRA board (If you don't have access you can ask @ccmoralesj)
Each JIRA ticket has an identifier based on a code and a number like XTG-123 which you will use later.
Each commit you do needs to have the JIRA ticket identifier so it can be related to the board.
You can use this commit format suggestion.
:optional-emoji: XTG-123: New endpoint to handle login
Emoji | Description |
---|---|
🚀 | New features, or enhancements to code |
🐞 | Bug fixes |
⚙️ | Refactors |
📦 | Build files, dependencies, config files |
🔎 | Minor fixes, typos, imports, etc |
🪄 | Others |
Once you're ready. You can create a new Pull Request (PR) by adding the JIRA ticket identifier in the title. The repo will give you a template to fill in the details of your amazing work!
You can use this PR title format suggestion.
XTG-123: Login
You'll need at least 1 review from your teammates to merge the pull request.
This project is connected to an EC2 instance from AWS.
All code from main
branch will be deployed to staging.
To deploy to production you must create a new release
and follow the semantic versioning fundamentals. That will trigger an automated deployment to production.
Some further information can be found on the X-team GamesHQ API Confluence page