Overview
This is a memo on how to add content types and fields using Drupal custom modules.
The following two articles were helpful.
https://www.drupal.org/docs/drupal-apis/entity-api/creating-a-custom-content-type-in-drupal-8
Car Brand Example
Following the first article introduced above, I was able to add a content type “Car Brand” with a “body” field.

Note that the above article skips the part about creating the custom module. First, create the following folder and file.
Adding Custom Fields
Using the above as reference, I was able to add a content type, but to add custom fields, I needed to add both a Field and a Field storage.
When I was unsure about how to write the YAML for Field storage, the second link introduced at the beginning was helpful.
By using the “Configuration Manager” module, I was able to check the definitions of already registered Fields and Field storages.
Based on the above, let’s create a content type called “IIIF Media” and add a field for storing a string called iiif_image_url, and fields for storing numeric values called iiif_image_width and iiif_image_height. The following files are needed.
Content Type
modules/custom/foobar/config/install/node.type.iiif_media.yml
Field: iiif_image_url (string)
Field storage
modules/custom/foobar/config/install/field.storage.node.field_iiif_image_url.yml
Note that by setting dependencies > enforced > module > {module name}, the storage is also deleted when the module is uninstalled. Without this setting, only the storage information remained after uninstalling.
The following article was helpful.
https://www.drupal.org/project/drupal/issues/3231028
!
On the other hand, having related content types and fields deleted when uninstalling a module can be problematic in some cases, so care must be taken with these settings.
Field
modules/custom/foobar/config/install/field.field.node.iiif_media.field_iiif_image_url.yml
Field: iiif_image_width (integer)
Field storage
modules/custom/foobar/config/install/field.storage.node.field_iiif_image_width.yml
Field
modules/custom/foobar/config/install/field.field.node.iiif_media.field_iiif_image_width.yml
Summary
As a result, by installing the custom module “foobar,” I was able to create a content type called “IIIF Media” and add fields with string and integer field types, as shown below.

I hope this serves as a useful reference for adding content types and fields using custom modules.