/reminders-cli

Reminders CLI app in Go

Primary LanguageGo

Reminders CLI app

Overview

In this project we'll build a multi component CLI application which consists of mainly 3 parts: a CLI client, a backend API server and a notifier service.

The CLI client will take the input from command line and pass it to the backend API through its HTTP client.

The backend API server is an HTTP server which has all the needed endpoints for CRUD operations on reminders. It also has 2 background running workers: background saver & background notifier. Correspondingly saving the in-memory data to the disk and notifying un-completed reminders.

The backend API server also communicates with the notifier service through its own HTTP client.

Speaking of the database layer, we'll be creating our own file database storage with some optimized mechanism for this type of application.

Ta-dah 🥳 🚀

Medium article 📖

YouTube tutorials 🎥

Requirements 🤓

In this tutorial we'll be writing a little bit of Node.js aka the Notifier Service because it's the fastest cross platform OS notification system available for us.

We'll also be using Yarn package manager for this application.

And that's all on the JavaScript (Node.js) side. The rest is pure Go code also without any third party packages meaning we'll write absolutely everything from scratch.

Components 🧩

  • CLI Client
  • HTTP client for communicating with the Backend API
  • Backend API
  • HTTP client for communicating with the Notifier service
  • Notifier service
  • Background Saver worker
  • Background Notifier worker
  • JSON file Database (db.json)
  • Database config file (.db.config.json)

CLI Client

Features

  • create a reminder
  • edit a reminder
  • fetch a list of reminders
  • delete a list of reminders

Note: Only works if Backend API is up & running

Backend API

Features

  • Does CRUD operations with incoming data from CLI client
  • Runs Background Saver worker, which saves in-memory data
  • Runs Background Notifier worker, which notifies un-completed reminders
  • It can work without the Notifier service, and will keep retrying unsent notifications until Notifier service is up
  • On backend API shutdown all the in-memory data is saved

Endpoints

  • GET /health - responds with 200 when server is up & running
  • POST /reminders/create - creates a new reminder and saves it to DB
  • PUT /reminders/edit - updates a reminder and saves it to DB (if duration is updated, notification is resent)
  • POST /reminders/fetch - fetches a list of reminders from DB
  • DELETE /reminders/delete - deletes a list of reminders from DB

Background Saver

Features

  • Saves in-memory reminders to the disk (db.json)
  • Saves db config to the disk (.db.config.json)

Background Notifier

Features

  • Pushes un-completed reminders to the Notifier service

Notifier Service

Features

  • Sends OS notifications

Endpoints

  • GET /health - responds with 200 when server is up & running
  • POST /notify - sends OS notification and retry response

File DB

Features

  • Records are saved inside db.json file
  • Has a db config file (.db.config.json)
  • Has an auto increment ID generator

Installation âš™

Before running any command or trying to compile the programs make sure you first have all the needed dependencies installed:

Configure make (WINDOWS ONLY):

Note: Make sure you have GitBash installed before proceeding.

  1. Download the Make executable

  2. Extract the contents form the zip

  3. Place the bin/make.exe inside C:\Program Files\Git\mingw64\bin

  4. If you're using Goland update your SHELL Ctrl + Alt + S --> Tools --> Terminal --> Shell Path --> "C:\Program Files\Git\bin\sh.exe" --login -i

  5. Restart Goland IDE

For more info refer to GitBash - CygWin


Run 🎮

make commands

# builds client & server binaries, formats & lints the code
make

# builds the client binary
make client

# builds the server binary
make server

# formats the entire code base
make fmt

# lints the entire code base
make lint

# checks the entire code base for code issues
make vet

server flags

# display a helpful message of all available flags for the server binary
./bin/server --help

# runs the backend http server on the specified address
# --backend flag needs to be provided to ./bin/client if address != :8080
./bin/server --addr=":9090"

# runs the http backend server with a different path to the database
./bin/server --db="/path/to/db.json"

# runs the http backend server with a different path to the database config
./bin/server --db-cfg="/path/to/.db.config.json"

# runs the http backend server with a different notifier service url
./bin/server --notifier="http://localhost:8989"

client commands & flags

# displays a helpful message about all the commands and flags available
./bin/client --help

# runs CLI client with a different backend api url
./bin/client --backend="http://localhost:7777"

# creates a new reminder which will be notified after 3 minutes
./bin/client create --title="Some title" --message="Some msg!" --duration=3m

# edits the reminder with id: 13
# note: if the duration is edited, the reminder gets notified again
./bin/client edit --id=13 --title="Another title" --message="Another msg!"

# fetches a list of reminders with the following ids
./bin/client fetch --id=1 --id=3 --id=6

# deleted the reminders with the following ids
./bin/client delete --id=2 --id=4

Note: Before using ./bin/client binary, make sure to have /bin/server and notifier/notifier.js up & running

1st terminal

node notfier/notifier.js

2nd terminal

./bin/server

3rd terminal

./bin/client ...

Resources 💎

Feedback âš—

GopherTuts TypeForm

Community 🙌

GopherTuts Discord


Enjoy 🚀🚀🚀