Hi,
I would recommend watching this webinar on Form engine. It is older but the idea is still the same. Also, this KB article talks about adding fields to document types - they are forms as any other so you can take inspiration from there as well.
Best regards,
Juraj Ondrus