π¬ I Built an IMDb CLI App with Go β Search, Save & Compare Movies from Your Terminal


π Table of Contents
Easily navigate through the blog:
##π¬ Why I Built This IMDb CLI App in Go
As someone who enjoys working in the terminal, I wanted a fun and useful project that lets me explore movies without opening a browser. Thatβs why I built go_IMDB-cli
β a command-line tool that helps you:
I chose to build this as a CLI because itβs lightweight, fast, and a great way to improve my Go skills while working with APIs and databases. It's simple, efficient, and fully offline for saved favourites β just the way I like my tools.
π§ What You Can Do with go_IMDB-cli
This command-line tool is designed to make working with movie data fast, simple, and fun β right from your terminal. Here are the features it supports:
| Command | Description | Example Usage |
| --------- | --------------------------------- | ------------------------------------------------ |
| `search` | Search movies by title | `./imdb search --title "Batman"` |
| `detail` | View detailed info by IMDb ID | `./imdb detail --id tt1234567` |
| `add` | Save a movie to favorites | `./imdb add --id tt1234567` |
| `list` | List all favorite movies | `./imdb list` |
| `delete` | Delete a movie from favorites | `./imdb delete --id tt1234567` |
| `compare` | Compare two movies by IMDb rating | `./imdb compare --id1 tt0111161 --id2 tt0068646` |
##π§° Technologies Used
| Tech | Why I Chose It |
| ------------------ | ------------------------------------------------------------------------------------ |
| Go | Fast, a compiled language thatβs perfect for building efficient and portable CLI apps. |
| Cobra | A powerful library for building structured CLI commands and subcommands. |
| GORM | An ORM that simplifies working with SQLite using Go structs. |
| SQLite | Lightweight embedded database to store favourite movies locally without setup. |
| OMDb API | A free and simple API to fetch movie data by title or IMDb ID. |
| Docker | Containerises the app so it runs consistently on any system without manual setup. |
| GitHub Actions | Automated testing and build workflows to ensure the code is always production-ready. |
##π Project Folder Structure
go_IMDB-cli/
β
βββ .github/workflows/ # CI/CD pipeline config for GitHub Actions
βββ api/ # Handles OMDb API calls (search by title, get by ID)
β βββ omdb.go # Functions to call and parse OMDb responses
β
βββ cmd/ # All CLI commands implemented using Cobra
β βββ add.go # Adds a movie to favourites
β βββ compare.go # Compares two movies by rating
β βββ delete.go # Deletes a movie from favourites
β βββ detail.go # Gets full movie details by IMDb ID
β βββ list.go # Lists all favourite movies
β βββ search.go # Searches for movies by title
β
βββ db/ # Database setup and connection logic
β βββ db.go # Initializes SQLite DB and migrates Movie model
β
βββ models/ # GORM model definitions
β βββ movie.go # Movie struct (Title, Year, IMDb ID, etc.)
β
βββ Dockerfile # Docker setup to containerise the app
βββ go.mod # Go module definitions
βββ go.sum # Go module checksum file
βββ main.go # Entry point: sets up and runs Cobra root command
βββ README.md # Project documentation and usage guide
##βοΈ How It Works β Command-by-Command
Each feature in go_IMDB-cli
is implemented as a command using the Cobra CLI library. These commands are neatly organised inside the cmd/
folder, and each performs a specific task, such as fetching data from the OMDb API or interacting with the local SQLite database using GORM.
π search
β Search Movies by Title
Location:
cmd/search.go
Key Function:
api.SearchMovies(title string)
Flow:
Read
--title
flag.Call OMDb API via
SearchMovies
.Receive and unmarshal the JSON into
SearchResponse
.Loop through matches and print each movieβs title, year, and IMDb ID.
Usage:
./imdb search --title "Batman"
π detail
β View Movie by IMDb ID
Location:
cmd/detail.go
Key Function:
api.GetMovieByID(id string)
Flow:
Read
--id
flag.Send request to OMDb via
GetMovieByID
.Unmarshal JSON into a
Movie
struct.Display full details: title, genre, plot, ratings, etc.
Usage:
./imdb detail --id tt1375666
β add
β Save Movie to Favorites
Location:
cmd/add.go
Functions Used:
api.GetMovieByID(id)
db.ConnectDatabase()
db.DB.Create(&movie)
Flow:
Read
--id
.Fetch movie data from OMDb.
Initialize SQLite DB via
ConnectDatabase()
.Create
models.Movie
instance and store it using GORM.
Usage:
./imdb add --id tt1375666
π list
β Show Saved Favorites
Location:
cmd/list.go
Functions Used:
db.ConnectDatabase()
db.DB.Find(&movies)
Flow:
Connect to the DB.
Retrieve all movies with
Find(&movies)
.Print each movieβs basic info (title, year, IMDb ID).
Usage:
./imdb list
ποΈ delete
β Remove a Favorite
Location:
cmd/delete.go
Functions Used:
db.ConnectDatabase()
db.DB.Where("imdb_id = ?", id).Delete(&movie)
Flow:
Read
--id
.Connect to DB.
Use GORM to delete the record by IMDb ID.
Print confirmation or a "not found" message.
Usage:
./imdb delete --id tt1375666
βοΈcompare
β Compare Two Movies
Location:
cmd/compare.go
Functions Used:
api.GetMovieByID(id1)
api.GetMovieByID(id2)
Flow:
Read
--id1
and--id2
.Fetch both movie details.
Parse
imdbRating
to float and compare ratings.Compare release years for older/newer context.
Print a comparison summary.
Usage:
./imdb compare --id1 tt0111161 --id2 tt0068646
##π How to Run the Project
π οΈ Option 1: ##Run as a Local Go Binary
git clone https://github.com/sidharth-chauhan/go_IMDB-cli.git
cd go_IMDB-cli
go build -o imdb
Check available commands:
./imdb --help
./imdb search --title "Inception"
./imdb detail --id tt1375666
./imdb add --id tt1375666
./imdb list
./imdb delete --id tt1375666
./imdb compare --id1 tt0111161 --id2 tt0068646
π³ Option 2: ##Run Using Docker Compose
docker-compose up
/*----------------------------------------------------------------------------------------*/
docker-compose run imdb search --title "Inception"
docker-compose run imdb detail --id tt1375666
##π£ Try It. Fork It. Improve It.
If you enjoy working from the terminal and love clean developer tooling, I invite you to try out the project and explore the codebase:
π GitHub Repo β sidharth-chauhan/go_IMDB-cli
Whether you're looking to contribute, learn Go, or just manage your favorite films offline β this tool is built with you in mind.
##π€ Letβs Connect
I'm always open to feedback, ideas, and collaboration. Feel free to reach out:
πΌ LinkedIn
π¦ Twitter
π» GitHub
βοΈ Hashnode Blog
Subscribe to my newsletter
Read articles from Sidharth chauhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sidharth chauhan
Sidharth chauhan
π Hello! I'm Sidharth Chauhan, a passionate DevOps Engineer dedicated to automating and optimizing processes to enhance software development and deployment. With expertise in Docker, Kubernetes, CI/CD, AWS, and more, I thrive in environments that leverage cutting-edge technologies and tools.I love sharing my knowledge and experiences through blogging, and I'm always eager to connect with like-minded professionals. Whether you're looking to collaborate on a project, need help with DevOps, or just want to chat about the latest tech trends, feel free to reach out!π Connect with Me: