DEV Community

Victor Dorneanu
Victor Dorneanu

Posted on • Originally published at blog.dornea.nu on

Releasing Gocial

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) 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 I decided I’ll implement my own service in Golang and learn more about OAuth and JWT tokens.


gocial main page

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 architectureto 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.

image
Early ideas

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).

image
Hexagonal Architecture

Project layout

For the project structure/layout I’ve decided to go with this structure:

gocial:

├── cli
├── docs
├── internal
├── lambda
└── server

Enter fullscreen mode Exit fullscreen mode

Code Snippet 1: Overall project structure

/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

Enter fullscreen mode Exit fullscreen mode

/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

Enter fullscreen mode Exit fullscreen mode

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 github repository

Top comments (0)