Add the force:hasRecordId interface to a Lightning component to enable the component to be assigned the ID of the current record.
…
force:hasRecordId in Custom Lightning Component development
The force:hasRecordId interface does two things to a component that implements it.
It adds an attribute named recordId to your component. This attribute is of type String, and its value is an 18-character Salesforce record ID,
When your component is invoked in a record context in Lightning Experience or the Salesforce app, the recordId is set to the ID of the record being viewed