Short
URL shortening service written in Go and React
Install / Use
/learn @short-d/ShortREADME
Short

Preview

Get s/ Chrome extension
Install it from Chrome Web Store or build it from source
Dependent Projects
- app: Reusable framework for Go apps & command line tools.
- kgs: Offline unique key generation service.
Table of Contents
Getting Started
Accessing the source code
git clone https://github.com/short-d/short.git
Prerequisites
- Go v1.13.1
- Node.js v12.12.0
- Yarn v1.19.1
- PostgreSQL v12.0
Local environmental variables
-
Copy
backend/.env.distfile tobackend/.env:cp backend/.env.dist backend/.env -
Copy
frontend/.env.development.distfile tofrontend/.env.development:cp frontend/.env.development.dist frontend/.env.development
Create reCAPTCHA account
-
Sign up at ReCAPTCHA with the following configurations:
| Field | Value | |-----------------|----------------| | Label |
Short| | reCAPTCHA type |reCAPTCHAv3| | Domains |localhost| -
Open
settings. CopySITE KEYandSECRET KEY. -
Replace the value of
RECAPTCHA_SECRETin thebackend/.envfile withSECRET KEY. -
Replace the value of
REACT_APP_RECAPTCHA_SITE_KEYinfrontend/.env.developmentfile withSITE KEY.
Configure Single Sign On
Create a new Client ID at Google API Credentials:
-
Click on
Create Credentialsand selectOAuth client ID. -
Select
Web applicationforApplication type. -
Fill in
http://localhost/oauth/google/sign-in/callbackforAuthorized redirect URIsand click onCreate. -
Replace the value of
GOOGLE_CLIENT_IDinbackend/.envfile withYour Client ID. -
Replace the value of
GOOGLE_CLIENT_SECRETinbackend/.envfile withYour Client Secret.
You can find the detailed instructions on setting up Facebook sign in here in case you are interested in.
Github
You can find the detailed instructions on setting up Github sign in here in case you are interested in.
Backend
-
Update placeholder values with your own configurations.
-
Launch backend server
cd backend ./scripts/dev -
Remember to install developers tools before start coding:
./scripts/tools
Frontend
-
Update
REACT_APP_RECAPTCHA_SITE_KEYinfrontend/.env.development. -
Launch frontend server
cd frontend ./scripts/dev -
Visit http://localhost:3000
System Design
App Level Architecture
Short backend is built on top of Uncle Bob's Clean Architecture, the central objective of which is separation of concerns.

It enables the developers to modify a single component of the system at a time while leaving the rest unchanged. This minimizes the amount of changes have to be made in order to support new requirements as the system grows. Clean Architecture also improves the testability of system, which in turn saves precious time when creating automated tests.
Service Level Architecture
Short adopts Microservices Architecture to organize dependent services around business capabilities and to enable independent deployment of each service.
SSR,
Toggle,
Status Page, Search,
Data Reporter,
Feedback Widget,
and Cloud API are still under active development.
Object Oriented Design
Short leverages class design, package cohesion, and package coupling principles to manage logical dependency between internal components.
Class Design
| Principal | Description | |------------------------------------------------------------------|------------------------------------------------------------------------| | Single Responsibility Principle | A class should have one, and only one, reason to change. | | Open Closed Principle | You should be able to extend a classes behavior, without modifying it. | | Liskov Substitution Principle | Derived classes must be substitutable for their base classes. | | Interface Segregation Principle | Make fine grained interfaces that are client specific. | | Dependency Inversion Principle | Depend on abstractions, not on concretions. |
Package Cohesion
| Principal | Description | |----------------------------------------------------------------------|-------------------------------------------------------| | Release Reuse Equivalency Principle | The granule of reuse is the granule of release. | | The Common Closure Principle | Classes that change together are packaged together. | | The Common Reuse Principle | Classes that are used together are packaged together. |
Package Coupling
| Principal | Description | |-----------------------------------------------------------------|-------------------------------------------------------| | Acyclic Dependencies Principle | The dependency graph of packages must have no cycles. | | Stable Dependencies Principle | Depend in the direction of stability. | | Stable Abstractions Principle | Abstractness increases with stability. |
Dependency Injection
Short produces flexible and loosely coupled code, by explicitly providing components with all of the dependencies they need.
type Authenticator struct {
tokenizer fw.CryptoTokenizer
timer fw.Timer
tokenValidDuration time.Duration
}
func NewAuthenticator(
tokenizer fw.CryptoTokenizer,
timer fw.Timer,
tokenValidDuration time.Duration,
) Authenticator {
return Authenticator{
tokenizer: tokenizer,
timer: timer,
tokenValidDuration: tokenValidDuration,
}
}
Short also simplifies the management of the big block of order-dependent initialization code with Wire, a compile time dependency injection framework by Google.
func InjectGraphQlService(
name string,
sqlDB *sql.DB,
gra
