Expense Tracker App Part-3

2023-06-07

So today the goal is to explore some backend aspects: I want to explore how the data read from the front end can be sent to the transaction database. There are a few components to this:

  • Database
  • Backend server
  • Authentication
  • Unknown unknowns?

In this post I am going explore the backend server part today and leave database and other aspects for later.

Backend server

I have a couple of choices for backend languages: Python / JS (or a version like TypeScript) - this is mainly dictated by my motivation to learn something other than C++ and library support. As far as API is concerned, I intend to implement a GraphQL API due to it’s flexibility in querying stuff and good typing support. This page captures the history and tradeoffs between different API types - so not much I can add here.

Both Python and JavaScript have graphql libraries which would allow me to implement a server. I am currently leaning towards JS (maybe TypeScript later) simply because of the novelty of the language for me.

I setup the npm workspace by following the instructions here. Even though the server would mainly be responding to queries, I am first implementing a ‘mutation’ to add the transaction data to the database. This tutorial talks about how we can implement a graphql mutation in JS. Here’s the recordTransaction mutation schema:

type Mutation {
  recordTransaction(postedDate: Date, amount: PositiveFloat, notes: String, category: String)
}

The category parameter should probably be an enum if we want fixed categories, but currently I am thinking of user / front end determine what categories are possible so we’ll leave it at String type. Note that the PositiveFloat and Date types are not standard scalar types - they were brought in by including the GraphQL Scalars project.

Turns out there is some complications as to which graphql framework / middleware to use in JS - as with all things web - there’s way too many options out there for a noob to proces! Examples include Express-GraphQL , Apollo Server Express, GraphQL Helix etc. etc. I have no clue which one is better - but seems like Express-GraphQL is the simplest of all - but also limited in it’s capability. Will probably start with that and change later if necessary.

Also kind of exhausted for today so will revisit this later this week.