I am studying groups from I.N Herstein and he talks about the notion of homomorphism in the following way:
By this (homomorphism) one means a mapping from one algebraic system to a like algebraic system which preserves structure. We make this precise, for groups, in the next definition.
Definition: A mapping from group G into a group G' is a homomorphism if for all a,b $\in$ G, $\phi(ab)=\phi(a)\phi(b)$
There are two things I note here:

He says "for groups etc etc" which I think implies that the above definition of a homomorphism is only valid for some (like groups) and not all structures while on the other hand the definition of homomorphism being a mapping that preserves structure is one which is general. Is this inference correct?

The above brings me to my followup question – What exactly does it mean to preserve the structure and how for groups the above definition encodes that?
When I think of "a mapping that preserves structure" something like the following comes to mind:
A mapping that takes the set of equally spaced points on the Xaxis to the equally spaced points on the YAxis.
or
A mapping that takes a set of points forming a figure (let's say a rectangle) on a plane to a set of points that form a rectangle at a different position on the plane.
As one can see my notion of a mapping that preserves structure is a very limited one.
How do I understand it in the context of groups, the above definition and in a more general way so that if I read a book talking about homomorphism of some other structure besides groups I would know how it preserves structure.
Best Answer
Thoughtful question.
The abstraction that the idea of a group captures is that of symmetry. So for any set with some kind of "structure" the set of all maps from that set to itself that preserve the structure will form a group.
In the example you pose about maps of the plane that preserve rectangles you are implicitly thinking about the group of all the rigid motions of the plane. The structure that's preserved is the distances between points. The isomorphisms of the Euclidean plane are the rigid motions.
In your question, groups enter in two ways. For group morphisms (iso, auto, homo) the underlying set with a structure is itself a group.
If you think about the points with integer coordinates in the number line, the group of symmetries is the integers themselves  you can translate in either direction by any integer amount.
Homomorphisms of groups (or of any other structure) capture the idea that you can "preserve" just parts of the structure. For example, if all you care about is whether an integer on the number line is an odd or even distance from $0$ there are only two symmetries that matter: you slide by an odd or an even distance. Those two symmetries make a group of order $2$: either you slide by an even or an odd distance. Then you have a homomorphism from the integers to the group of order $2$.
Related: What is an Homomorphism/Isomorphism "Saying"?