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 ๐ฅ
- Reminders CLI in Go #1 - Project setup & bare bones - [Download Code]
- Reminders CLI in Go #2 - Notifier Service - [Download Code]
- Reminders CLI in Go #3 - CLI Basics - [Download Code]
- Reminders CLI in Go #4 - Command Switch - Part 1 - [Download Code]
- Reminders CLI in Go #5 - Command Switch - Part 2 - [Download Code]
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
createa reminderedita reminderfetcha list of remindersdeletea 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 & runningPOST /reminders/create- creates a new reminder and saves it to DBPUT /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 DBDELETE /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 & runningPOST /notify- sends OS notification and retry response
File DB
Features
- Records are saved inside
db.jsonfile - 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.
-
Download the Make
executable -
Extract the contents form the zip
-
Place the
bin/make.exeinsideC:\Program Files\Git\mingw64\bin -
If you're using Goland update your SHELL
Ctrl+Alt+S-->Tools-->Terminal-->Shell Path-->"C:\Program Files\Git\bin\sh.exe" --login -i -
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 vetserver 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=4Note: Before using ./bin/client binary,
make sure to have /bin/server and notifier/notifier.js up & running
1st terminal
node notfier/notifier.js2nd terminal
./bin/server3rd terminal
./bin/client ...Resources ๐
Feedback ๐ง
Community ๐ฌ
Enjoy ๐๐๐
