Boilerplate for building a monolighic Go and React application

Monolithic Go and React Application Boilerplate

Screenshot

This repository provides a simple and monolithic service with a server written in Go and frontend with React. The service does not orient the modern services (like microservices or micro frontends), but you can see the simplicity and easiness of development and deployment. Sometimes monolithic services are helpful for a small-scale or non-critical business situation such as an internal system.

This project introduce the following languages and frameworks:

The application serves a tiny social blog as a sample. The users can publish the articles and add comments. Feel free to customize and build your applications based on this project.

Quickstart (for development)

The repository contains two projects; for the frontend and server-side. The frontend project is in frontend sub-project, you can install dependencies and run the debug server by yarn:

$ cd frontend
$ yarn install && yarn start

Then run server-side service in debug mode by go run:

$ go run main.go  -debug

You can see the sample application on http://localhost:8000

Sample application: A minimal social blog

The application provides a minimal social blog as a sample. You can retrieve the articles and publish your article via your browser. You are also able to send your comment to the articles.

Any frontend page consists of a single page known as a single-page application; the server responds with a single HTML. The pages transit seamlessly. The frontend scripts fetch and send articles and comments via APIs asynchronously using axios. The server-side application provides the following REST APIs:

  • GET /api/health and GET /api/ready: The heath check endpoints to ensure the application lives. You can see more detail in Kubernetes docs.
  • GET /api/articles: Get all articles with summaries.
  • GET /api/articles/{article_id}: Get a article with full content.
  • POST /api/articles: Create a new article.
  • GET /api/articles/{article_id}/comments: Get comments of the article article_id.
  • POST /api/articles/{article_id}/comments: Create a new comment for the article_id article_id.

How to develop it

The server-side go service has a debug mode to serve the webpack development server on the same endpoint with APIs. This is useful to make the frontend scripts able to access APIs with no CORS headers. Any requests excluding the path starting with /api/ returns assets served from webpack

Server-side

The server-side program has two packages, repository and web. The repository packages contain interfaces and implementation to read and persist user's requests. Note that the current implementation server never keeps data. The server loses the article you published or the comments you sent when the restart. If you wish to persist them, try to implement repositories instead of mock storing to the in-memory.

The web packages provide the routes of the request from user's URLs and present responses for the request. They are known as the controller layer in MVC or DDD. If you want to add some APIs or add models, implement them to repository and web, respectively. If you need more complex logic or use cases, feel free to implement or add new packages.

Frontend

Any page consists of a single page as known as a single-page application. The react-router is a library to achieve client-side routing.

The frontend sub-project is initialized by react-scripts and keeps the directory structure and build processes. Every component is in frontend/src in flatten.

How to deploy it to the production

Manual deploy

You should not use a webpack development server by yarn start and go run in production. You need to build them before deployment. To generate frontend assets, run yarn build. This command generates minified HTML, JavaScript, and CSS.

$ (cd frontend && yarn install && yarn build)

To compile a server-side application to create an executable binary, use go build:

$ CGO_ENABLED=0 go build -o go-react-boilerplate -trimpath .

Then you can confirm to run it by the following:

./go-react-boilerplate -webroot ./frontend/build

The server-side also serves asset files from the directory specified by -webroot, so you do not need some 3rd-party HTTP server like Apache HTTP server or NGINX.

Building a Docker container

This repository contains Dockerfile. Using docker containers allows you to develop applications faster and make deployment easier. The Dockerfile uses multi-stage builds; it contains steps to build frontend and server-side phases. You can build a docker image and run the container from the image by docker build and docker run:

$ docker build -t go-react-builderplate .
$ docker run --rm -p 8000:8000 go-react-builderplate

License

MIT

Similar Resources

Example hello-world service uses go-fx-grpc-starter boilerplate code

About Example hello-world service uses https://github.com/srlk/go-fx-grpc-starter boilerplate code. Implementation A hello world grpc service is creat

Nov 14, 2021

Go Clean Architecture Boilerplate

Go Clean-Architecture Simple Go Clean-Architecture Boilerplate Overview The purpose of the template is to show: How to organize a project and prevent

Nov 27, 2021

A golang boilerplate for Mixin Bot

go-boilerplate This is a golang boilerplate for Mixin Bot. run ./go-boilerplate -f YOUR_KEYSTORE_FILE help to see the help. It enables several widely

Nov 3, 2022

Golang service boilerplate using best practices

go-boilerplate Golang service boilerplate using best practices. Responsibility: Register (CRUD) and Login Users with JWT. Dependencies Gin-Gonic Swagg

May 11, 2022

Go-fn Boilerplate for Web Functions

alya-go-fn-boilerplate Go-fn Boilerplate for Web Functions This projects aiming to create a deployment ready go skeleton webserver for fast developmen

Feb 5, 2022

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app. This is done by replacing variables in main during build with ldflags.

Nov 14, 2021

Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging

Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging and plugins to provide users with a much stronger, more integrated experience than the loose coupling and stand-alone commands of the previous generation of tools.

Dec 16, 2022

An application that is developed to generate application by API specification

GO boilerplate is an application that is developed to generate application by API specification and Database schema with the collaboration with opn-generator.

Oct 14, 2021

A tool that facilitates building OCI images

A tool that facilitates building OCI images

Buildah - a tool that facilitates building Open Container Initiative (OCI) container images The Buildah package provides a command line tool that can

Jan 3, 2023
A boilerplate for building Gradescope autograders for Go projects.

go-autograder A boilerplate for building Gradescope autograders for Go projects. Getting started This autograder works by running all Go tests in a st

Nov 6, 2022
A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture
A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

Mar 2, 2022
GolangChatroom - Live chatrooms built with Golang, React, and TypeScript with Webpack Hot Reloading
GolangChatroom - Live chatrooms built with Golang, React, and TypeScript with Webpack Hot Reloading

Go Live Chatrooms An example project demonstrating websockets and authentication

Jan 3, 2022
dockerized (postgres + nginx + golang + react)
dockerized (postgres + nginx + golang + react)

PNGR Stack Dockerized (postgres + nginx + golang + react) starter kit Only implements basic user signup, session management, and a toy post type to de

Jan 7, 2023
This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

Dec 22, 2022
Automatically generate Go test boilerplate from your source code.
Automatically generate Go test boilerplate from your source code.

gotests gotests makes writing Go tests easy. It's a Golang commandline tool that generates table driven tests based on its target source files' functi

Jan 3, 2023
A Visual Go REST API boilerplate builder.
A Visual Go REST API boilerplate builder.

A Visual Go REST API boilerplate builder. The boilerplate builder will export a Go web server with 0 dependencies, besides the ones you add.

Jul 8, 2022
A boilerplate for Go fiber versioning
A boilerplate for Go fiber versioning

Fiber Versioning Boilerplate Prerequisite Make sure you have the following installed outside the current project directory and available in your GOPAT

Nov 18, 2022
A boilerplate showing how to create a Pulumi component provider written in Go

xyz Pulumi Component Provider (Go) This repo is a boilerplate showing how to create a Pulumi component provider written in Go. You can search-replace

Mar 4, 2022
Golang Fiber boilerplate with MySQL resource.

Fibo - Go Fiber API Boilerplate A starter project with Golang, Fiber and Gorm Golang Fiber boilerplate with MySQL resource. Supports multiple configur

Nov 1, 2022