🎬 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` |
  • All commands are powered by the OMDb API and managed with a clean Go + Cobra CLI structure.

##🧰 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:

    1. Read --id.

    2. Fetch movie data from OMDb.

    3. Initialize SQLite DB via ConnectDatabase().

    4. 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:

    1. Connect to the DB.

    2. Retrieve all movies with Find(&movies).

    3. 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:

    1. Read --id.

    2. Connect to DB.

    3. Use GORM to delete the record by IMDb ID.

    4. 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:

    1. Read --id1 and --id2.

    2. Fetch both movie details.

    3. Parse imdbRating to float and compare ratings.

    4. Compare release years for older/newer context.

    5. 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:

0
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: