Quick Start With “Spica”
In this post, I am going to share my experiences with creating a backend service with Spica for a mobile game. Spica includes many features that help your development progress. Here, I will explain some of them.
1-Creating Database
First, we needed a database to store our data such as user information, game statistics, rewards of users. Luckily, Spica has a module called Bucket to save all our structured data. Each grouped data is a bucket. For instance; UserBucket, RewardBucket, etc. We defined the document fields for buckets and created them. Spica has a well-structured admin panel to make all the required setup. Creating a bucket, setting its data model up, etc. are very easy to do on Spica. This saved us from spending too much time on creating DB and setting up its configurations. Thanks to the Buckets module, it is possible to relate the two bucket fields as we do on SQL servers. This helped us to fetch the distributed data in a structured format. While creating our buckets and setting them up, we set up the relations between them. All actions with bucket documents such as editing, listing, and filtering can be done on the panel. Also, we used the field type called ‘Relation’ to understand which statistics belong to which users. Therefore, it was very easy to manage the buckets for admin.
2-Creating API
We used the Function module to create custom behavioral functions on our service that can connect database and application such as login, sign up, reset the password, return game user statistics, calculate leaderboard, etc. To create a function, we need to complete the two steps below;
Selecting a trigger
We might call triggers as the conditions that make a particular function work. There are different kinds of triggers in Spica like HTTP requests, scheduled triggers, DB triggers (one that works based on the changes in the DB). This way we don’t spend time on code to catch these trigger actions.
Writing code
We need to write code about what function will do after it is triggered. It might be login, sign up, send reset password code, get leaderboard, etc. Basic Javascript/Typescript and MongoDB skills are enough for this step. There is an IntelliSense support that makes coding easier. We have an input called Dependencies that we can import any NPM package to the function.
To sum up, these two modules are enough to create your backend service with Spica.