In SmartThings, “routine” is a term used specifically for the instructions you can create inside the SmartThings app. You don’t get to see the code for those, just the user interface in the app. So I think the term you are looking for is “automations.”
There are two kinds of automations you can create where you can see all the details, but neither will show up in the SmartThings app. They use a backend connection to the platform.
1. Use a Custom Smartapp to Access the SmartThings API
SmartThings only recently began offering a standard REST API. You access this through the cloud. You can write whatever code you like using whatever programming language you like, and host that code yourself wherever you like—but the access point to SmartThings is in the cloud. This is how most third party integrations are written now.
- Use the official Rules API
The Rules API is one endpoint on the SmartThings API that lets you upload rules to your account. The rules will use what is essentially a scripting language for the SmartThings platform. You can write the payload in either JSON or YAML. It is unique in that you do NOT have to host the automation yourself. The automations will run on the ST platform after you have uploaded them whenever the conditions that you specified are met. Right now that means they run inside the ST cloud, but the publicly stated intent is that eventually many rules will be able to run locally on your own hub,
This was originally intended as the substitute for Webcore, but partway in they dropped the part of the project that would have created a visual front end for it.
Instead, you will have to download the CLI tool (command level interface) and the new ST SDK onto a pc/laptop.
Then you will write your own code for your rules (which ST calls “recipes” when they are added to your account through the rules API, as opposed to “routines,” which are added through the smartthings app.). Once you have written your recipe, you upload it to your account in the ST cloud, and then it can run based on the conditions you specify. Right now that is in the cloud, but eventually it might be local.
So you will always need the internet to add new recipes to your account. But maybe some day they will be able to run locally. (No promises, though.)
To be honest, I don’t know the exact process for getting a recipe from your pc to your ST account, but others can help with that.
As @nathancu said, there’s a whole section of the forum dedicated to the Rules API—you can ask further questions there.
3. An Unofficial Alternative: Use MQTT
If you really want your custom automations to run locally now, there’s a third alternative. Set up an MQTT broker on a local server and use the following project to integrate with ST locally. It still won’t show up in the ST app, but you do get local operation and the ability to write custom rules.
Integration Solutions using MQTT
That said, logically if you’re considering option 3 the question would have to be asked why you don’t just consider Home Assistant instead of SmartThings? It’s free, it’s local, you control the code. It’s too hard for many non programmers, but with your coding background it does seem like a candidate.
Hopefully someone who knows more about this stuff will correct me if I’ve gotten anything wrong. I’ve been following the architecture discussions but haven’t used the tools myself.