About two billion years ago, or maybe a little later, some eukaryote cells developed the ability to see. The cells that had evolved the ability to photosynthesize needed light in order to make their food. So it was important to these cells to be able to find sunlight to use in the photosynthesis.
Eyespots, like other parts of a cell such as lysosomes or golgi bodies, have a lipid membrane around them. Inside, eyespots have as many as twenty different kinds of protein molecules. These often have a dark or reddish color, as you can see in the picture.
The eyespots are near the flagellum, so they can control how the flagellum moves. When light hits some of these proteins, the protein builds a molecule that tells the flagellum to start moving the cell in the direction of the light. These eyespots are the ancestors of eyes.
Bibliography and further reading about eyespots: