If you want to create a controller rendering
then there is an option to clone
an existing component in Sitecore SXA
. Follow this article to know how to clone a component in SXA.
https://sbhatiablogs.wordpress.com/2020/10/01/how-to-customized-components-in-sxa-by-cloning/
And to know more about creating a controller rendering
in SXA, you need to follow this article shared by Sitecore
.
https://doc.sitecore.com/xp/en/developers/sxa/17/sitecore-experience-accelerator/walkthrough--building-a-simple-rendering.html
Also if you want to check the code of an existing OOTB Sitecore controller then you need to go to a particular component and you will find the controller class and assembly in the controller field like this.
In this example the controller is Sitecore.XA.Feature.Composites.Controllers.AccordionController
and you can find this in the Sitecore.XA.Feature.Composites
DLL. So you need to use some third-party tools to extract this DLL and you will be able to find the code.
Then if you want to extend this code, you can copy the same logic in your controller class and extend it as per your needs.
Then in the above image in the Controller field, you need to pass your class and assembly name and then this will work with your logic.
Hope this is enough information for you to start.