TheBrag CLI: Save your brags from terminal
Tags: linodehackathon, go, cli, api
Published: 2023-02-19 16:08:46

## What I built
If you're anything like me, you believe in getting things done as quickly as possible, but when the time comes for a performance review or job interview, you're stuck with a bad memory and a blank page, frantically combing through JIRA tickets, emails, and closed PRs from multiple projects.

Now, you don't have to think about what you did in the last six months or a year with **TheBrag**! 

> Brag now, remember later.

**TheBrag** is a CLI-based application that lets you save your brags (things you want to show off) directly from your terminal. 

**TheBrag has the following features:**
- You can add, view, update, or delete brags directly from the CLI. 
- Create custom categories to sort out your accomplishments like work tasks, personal tasks, blogs, etc.
- Use the "export to file" functionality to recieve a copy of your accomplishments via email.
- You can export all your data or by selected categories within a date range. 

### Category Submission:
- Wacky Wildcard
- Integration Innovators
- SaaS Superstars

### App Link
Download the CLI application from this [link](https://thebrags.ap-south-1.linodeobjects.com/thebrag).

**Installation Steps:**
1. Download the application from the link above.
2. Run `chmod a+x thebrag` from the directory where the file was downloaded. This will make the file executable for all groups on your system.
3. From the same directory you can run `./thebrag` on your terminal to start using it. 
OR 
4. If you want to access `thebrag` command from anywhere in your system, you need to add the application path to your $PATH environment variable. 
  - Navigate to your home directory by typing `cd` in the terminal.
  - Type `nano .profile` or `nano .zshrc`.
  - Inside this file, add the following line:
`export PATH=$PATH:/foo/bar`
(Replace /foo/bar with the location of the downloaded file)

![.zshrc screenshot showing how to add file path](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k2rnlyufvnzlk65qyosj.png)

  - Save and quit.
  - Exit Terminal.app (or whichever term program you're using) and restart it. 

You should now be able to run `thebrag` from anywhere.


### Screenshots
- `thebrag` command: Gives the basic information about the app along with a list of commands that can be used.

![thebrag command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77abixpcx5ejmf54t6yr.png)

- `thebrag login` command

![thebrag login command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bpuk2vljytyw3hukpl1s.png)

- Add a new category: `thebrag category -c "<category_name>"`

![Add category command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/36c026ehgup4a3l43nmo.png)

- List all existing categories: `thebrag category`

![List categories command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnpatzt6r11vqfe255hm.png)

- Add a brag: `thebrag add -c "<category_name>" -t "<brag title>" -d "<brag details>"`

![Add a brag command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1r04cywczq9vt3ftdl70.png)

- List brags: `thebrag get -n <no. of brags>`

`thebrag get -n <no. of brags> -s <skip_from_start> `

![List brags command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pwd00am839wpsyk8mte3.png)

- Get a specific brag: `thebrag get -i <brag_id>`

![Get brag by id command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqnkc41f96slp6bq6c6v.png)

- Update a brag: `thebrag update -i <brag_id> -d "new details content" -t "new title content" -c "new category name"`

![Update a brag command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ju1x011yh51s4zslw5h.png)

- Delete a brag: `thebrag delete -i <brag_id>`

![Delete a brag command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vudiap22sbngol1d9fbl.png)

- Export brags: `thebrag export -d "<from_date>,<to_date>" -c "<category_name>"`

![Export brags commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3nyd17ah7ts8wauslfgh.png)

- Received Email:

![Brags Email](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/orpgijishcxw16b4tn5x.png)

- Exported Brags CSV:

![Exported Brags file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vd4ihyy3klog7lbsnsrv.png)


### Description

A high level view of the system:

![TheBrag - System design diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tw5y39gt0ixsyteewxmc.png)

1. The `user` interacts with the application via the `CLI` to manage their brags.
2. The request is sent to the `thebrag APIs`, hosted on Linode servers, for processing .
3. The API interacts with the `MySQL` database to get/update the data.
4. The `Export Module` will let you export brags into a CSV file. 
5. After generating the file, it is uploaded an Object Storage bucket on Linode and sent to the registered email id using SendGrid Emails.


### Link to Source Code

1. APIs: [thebrag-api](https://github.com/khushboop09/thebrag-api)
2. CLI: [thebrag-cli](https://github.com/khushboop09/thebrag-cli)


### Permissive License
MIT License

## Background
From trying to come up with things to write about in the year end review for appraisals and giving talking points to help my manager for award nomination at work, made me think that I should start logging the things I've worked on in one place. 

Inspired by this [post](https://jvns.ca/blog/brag-documents/) by Julia Evans and practically spending all day in the terminal, I decided to just a write CLI application which will let me log my work directly from the terminal. 

The skeleton is me 😵‍💫.
![How to exit vim?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vy79xpmu2tszyu4rmitl.jpg)


### How I built it
**Language, Framework and Libraries:**

TheBrag-CLI uses the Golang's **Cobra library** which provides a simple interface to create powerful CLI applications.

TheBrag-API is built using Golang's **Gin framework** for easy implementation of REST-APIs and **Gorm** for MySQL integration. 

This is my first GoLang Application 🤩

**Infrastructure:**
- APIs are deployed on Linux virtual machines called **Compute Instances** provided by Linode. For demo purpose this is setup on a shared CPU nanode 1GB.
- **MySQL** is also provisioned on Linode using their **high performing managed database clusters**. Also on shared CPU nanode 1GB.
- Exported brag files are uploaded in a private bucket on **Object Storage** offering by Linode to save the exported data files on cloud.
- **SendGrid** is used to send the **email** containing the exported data file.
- Thebrag CLI app is hosted in a bucket on **Object Storage** by Linode with **public read access** to allow anyone to download the app and start using it.

### Future Scope/Roadmap
This is not the end for this project, I'm going to continue adding features to this.
- Filter brags by category, date range etc.
- Setup Github Actions for deployment.
- Convert your brags into a resume.
- Performance optimisation: Move export functionality to a worker.
- Dashboard for people who prefer a GUI.

PS: Feel free to share suggestions or feature requests.

### Additional Resources/Info
[1] [Opening a port on linux](https://www.digitalocean.com/community/tutorials/opening-a-port-on-linux) or this one [linux-how-to-open-a-port](https://phoenixnap.com/kb/linux-how-to-open-a-port)
[2] [Copy files from local to remote server](https://phoenixnap.com/kb/linux-scp-command)
[3] All go tutorials use localhost for API to listen to, remember to change the IP for production deployment. After 2 days of confusion I found this: [port-seems-to-be-open-but-connection-refused](https://askubuntu.com/questions/166068/port-seems-to-be-open-but-connection-refused)
[4] [SendGrid for emails](https://sendgrid.com/solutions/email-api/)