Sorry, but your trip seems very rushed once you take into account how long it will take you from door to door each time you change location. Porto to Lisbon will be 5 + hours door to door by train.
Three nights = 2 days.
The advice given about dropping the Algarve and visiting the Silver Coast is sensible given your timeframe. If it must be the Algarve, I would go there after Porto and Lisbon. You will waste far too much time in transit going south to then head north again. There are few direct flights between Porto and Faro so you may have to travel via train. By the time you have got to the airport, waited for your flight, flown, got through the airport then travelled to Lagos, that will have taken about 5 hours door to door. Lagos has poor public transport links. A car is an asset in the Algarve. Tavira/Cabanas are much closer to Faro airport and are less windy than Lagos and the western end of the Algarve.
I prefer the beach resorts in Portugal to Spain - they are generally less built up plus the dining hours are much better in Portugal. I hate eating dinner at 10-11 pm. Torremolinos wouldn’t be my choice of resort. Cadiz is a charming city but it doesn’t have the same quality of beaches as Portugal.