I want to take nothing away from your post subtance-wise, but “from the scratch” is just a little stretch I think.
LineageOS 14.1 was an open-source Android 7.1 and went official - in its terms - on the Fairphone 2 in October 2017.
The announcement of Fairphone’s Android 7.1 in May 2018 said “we’ve been working hard with a community of Open Source Android developers and external parties”.
I have no inside knowledge of the matter, but I cannot help but guess which community of Open Source Android developers they might have turned to, to exactly not having to start from scratch .
Of course it was still courageous of Fairphone to develop an official Android 7 for the Snapdragon 801, and moreover to get it certified by Google, when seemingly nobody else did … but they had available a non-certified community daily-driver-grade Android 7.1 to have a look at and developers to consult about it.
(By the way … for use cases where “Google-certified” might not be important … LineageOS 15.1 is an open-source daily-driver-grade Android 8.1 and went official - again in its terms - on the Fairphone 2 in August 2018.)