How do you predict incoming base attack?

Hello, so i’m at my first run through but i played Xcom 2 before so i have the basic idea how the game mostly work. I’m currently around 45% red meter. I discovered 7 bases but I lost one there’s only a Armadillo in the base so the game Auto determent i lost. Now i’m under the second base attack which I only have 2 new recruits that chill and training. Now they have to defeat 10+ monsters to keep the base. Now i saved the game hopefully i can somehow cheese through. My question is how do you predict the incoming attack?? or it’s RNG so you need to place like 5 soldiers every base? I’m currently have 8 man and 7 man squad defending havens and do missions around the globe also a third scouting/exploring squad to scan around. I thought i did fine but I lost one base already due to no one at the base so Auto lost it. Please let me know if i miss something important. There’s not even warning like Haven is under attack you need to get there in time. The mission just pop so i’m confused if i play the game wrong. I should just sit at bases with A teams and let other Haven die?

Hellow

I think thei’re a part of rng, BUT you’ll receive a message on your left screen (thhe same whay that when a haven is under attack) that say that ennemi move toward a base, leaving you half a day to a day to move any soldier you want in or out the said base.

if one of your bases is within range of an alien base, it can be attacked, just like the havens. If you click on an alien base, you will see a blue ring that tells you it’s range

Okay thanks guys, I didn’t know Lair in range will cause that base attack and good to know the tiny reminder i knew it’s there but mostly just research will be done in how many hrs didn’t pay attention about it.