Where does Ulysses store its local content? I'd like to backup my local content with my own scripts. But I'm not familiar about how OSX apps works. So I can't find where does Ulysses stores its local content.

Or generally, where usually does an OSX apps, stores its buffer content?
It’s really up to each program to decide if it stores in the home folder / documents and lets users manage things or if it makes a database in plain view (like Photos or iTunes) with aspects of the database elsewhere or entirely hide the filesystem and manage all files / syncing. 

In the case of Ulysses - the developer has decided to manage things in a bundle/database and either sync it to iCloud via a local cache or store the content locally in your user library folder - out of view of normal expectations in ~/Documents or ~/Desktop

Content stored On My Mac

If you do not sync your local content using iCloud (i.e. it's in the On My Mac section in your Ulysses sidebar), you can access each group in your Ulysses library at the following file path:

~/Library/Group Containers/X5AZV975AG.com.soulmen.shared/Ulysses/Documents/Library/Groups-ulgroup/

Each group belongs it its own -ulgroup directory and will have an (unhelpful) hash for a name—for example, cba24c5b16a949c388b0204c9aa28867-ulgroup.

Within each -ulgroup directory, your documents will each have their own .ulysses file. And you guessed it, they also have a hash for a filename. Note that .ulysses files actually contain both a Content.xml and a Text.txt with your content in them.  

Content synced via iCloud

You will have a hard time accessing your Ulysses iCloud-stored library from Finder, but I seem to be able to access mine fine using the Terminal if you're comfortable doing that. It's stored similarly as I described above, but here is the file path you'll be looking for instead:

~/Library/Mobile Documents/X5AZV975AG~com~soulmen~ulysses3/Documents/Library/Groups-ulgroup

A note on iCloud. The com~soulmen~ulysses3 is the application bundle/group name provided to Apple by the developer when they created the iCloud entitlements for this application. The X5AZV975AG is Apple’s provided identifier that combined with the reverse dns type name space, makes each iCloud bucket unique but common across everyone that uses that app.