More than a year ago I started working on a side project born out of the furstration I had with buffer, ifttt and zapier. The use case was pretty simple: I just wanted to share an article and some comments about it on multiple social media platforms from a single location.
All sharing services had great functionalities (e.g. automated workflows[^fn:1]) but you're always limited in the number of shares you can distribute withing a time frame without paying for premium. At the same time they all lacked support for LinkedIn which then sparked the idea for gocial. After having a look at the LinkedIn Post API[^fn:2]
I decided I'll implement my own service in Golang and learn more about OAuth and JWT tokens.
Design
For the overall system design I use a serverless environment to run my Golang binary. Currently I use netlify.com to host my Lambda function which serves all the functionalities via HTTP and some REST API.
As for the software architecture I've used hexagonal architecture to have more or less strict boundaries between the domains and enable lose coupling.
Sketching ideas
As always I've started with a rough idea how the code structure should like. Initially I wrote down some ideas on my whiteboard and codified these later on.
Hexagonal Architecture
I know the picture below doesn't look like an hexagonal structure but it should at least emphasize what the core domain is about.
๐ I've recently release an online presentation on this topic. Checkout Hexagonal Architecture (Basic Introduction using Python).
Project layout
For the project structure/layout I've decided to go with this structure:
gocial:
โโโ cli
โโโ docs
โโโ internal
โโโ lambda
โโโ server
/internal
This is where the gocial specific domain code goes to. This includes entities, different services and the authentication part.
./internal
โโโ config
โ โโโ config.go
โโโ entity
โ โโโ identity.go
โ โโโ providers.go
โ โโโ share.go
โโโ identity
โ โโโ cookie_repository.go
โ โโโ file_repository.go
โ โโโ repository.go
โโโ jwt
โ โโโ token.go
โโโ oauth
โ โโโ goth_repository.go
โ โโโ repository.go
โ โโโ service.go
โโโ share
โโโ linkedin_repository.go
โโโ repository.go
โโโ service.go
โโโ twitter_repository.go
/server
./server
โโโ api.go
โโโ html
โ โโโ html.go
โ โโโ package.json
โ โโโ package-lock.json
โ โโโ postcss.config.js
โ โโโ static
โ โ โโโ main.css
โ โโโ tailwind.config.js
โ โโโ tailwind.css
โ โโโ tailwind.js
โ โโโ templates
โ โโโ about.html
โ โโโ auth
โ โโโ base.html
โ โโโ index.html
โ โโโ partials
โ โโโ share
โโโ http.go
โโโ oauth.go
โโโ share.go
This folder contains HTTP server specific functionalities:
/html
- here I put all the HTML templates and components (partials)
- I use tailwindCSS so there is a little bit of
npm
foo
http.go
- responsible for launching the HTTP server and setting up API routes
- renders HTML templates
api.go
- handles different API routes (e.g. sharing articles/comments)
oauth.go
- defines API endpoints for doing OAuth
Project repository
Check out the project repository ๐
[^fn:1]: Initially I played with RSS and hugo for publishing content via a RSS feed which will then trigger posts on Twitter, LinkedIn & co. [^fn:2]: Which apparently now it's legacy and got replaced by the posts API.