Some of the magento vendor module contain folder named as “Service”, What is the specific purpose for these directory.
Generally service contract reside in “Api” directory, so already one directory is avaialble then what is the use of additional service directory.
2
Answers
In Magento2, you have a complete freedom, when it comes to naming your folders, as long as you comply with PSR standards.
There are some conventions (as in best practices), but ultimately the name of the folders doesn’t really matter…
Commonly used folders are (and better be, as some actions in Magento are based on these conventions, see installation scripts for example):
Please refer to best practices https://devdocs.magento.com/guides/v2.2/ext-best-practices/extension-coding/common-programming-bp.html (there is a version in 2.1 and 2.3 documentation as well), for your own development but keep in mind that not all developers follow (or are even aware of) these guidelines and that – beside the common patterns – you have much more freedom than for M1.
Service directory is not a generic Magento module functional directory.
It is just a custom-created directory and used by that module, and doesn’t have a common meaning.
Actually in vendor/magento, there are still many custom created directory inside different default modules, e.g. in module-elasticsearch, there are /Elasticsearch5 and /SearchAdapter directory.