I'm looking for a book and the plot goes something like this: there's a boy who lives with his mom and sister, they're relatively poor and live in a small apartment genetically made out of a live tree. There are multiple worlds all connected by a train track with trains with consciousness and feelings piloting the track.
To get to the main plot, the kid is offered a job by a doctor/scientist with a female robot to steal an object from a royal family by pretending to be a relative. They succeed at stealing it, but while escaping in a space pod, the robot girl is launched away into space; he fell in love with the robot and he is able to escape and give the doctor the object, but the kid asks the doctor to save the robot which he fell in love with.
My memory is a little foggy here, but he somehow saved the robot, and I forgot what happened at the end, but they open a portal and that's how it ended. I read this book about 2-3 years ago on an iPad if that helps.