is it based on any book?
Yes, on a novel by the same name.
I Am Legend (film)
I Am Legend is a 2007 American post-apocalyptic action thriller film loosely based on the 1954 novel of the same name by Richard Matheson.
what happened at the end of i am legend Neville along with Anna and Ethan heads to Vermont to find the survivors' colony. what is the genre of the movie? An  American post-apocalyptic action thriller film.
wiki:22288985
I Am Legend (film) [SEP] Introduction
I Am Legend is a 2007 American post-apocalyptic action thriller film loosely based on the 1954 novel of the same name by Richard Matheson. Directed by Francis Lawrence, the film stars Will Smith as US Army virologist Robert Neville. It is set in New York City after a virus, which was originally created to cure cancer, has wiped out most of mankind, leaving Neville as the last human in New York, other than nocturnal mutants. Neville is immune to the virus and he works to develop a cure while defending himself against the hostile mutants. It is the third feature-film adaptation of Matheson's 1954 novel "I Am Legend", following 1964's "The Last Man on Earth" and 1971's "The Omega Man".