Skip to content

ajorgensen/go-react-webapp-bootstrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go React Webapp Bootstrap

Purpose

The purpose of this project is to serve as a learning/test-bed for experimenting with how to structure a golang project that features a react frontend and go backend. This will also hopefully serve as a project that can be cloned and used as a jumping off point for new applications.

This structure is heavily based of a great blog post series by AAF Engineering.

Quick start

Requirements

  • npm
  • yarn
  • golang

Build and Serve

To build and serve the webapp you can run make build serve. This should build the react app, compile the go backend, and start the webserve running by default on port 9092. If you need to change the port for any reason you can do so in config.yaml

Structure

├── Makefile
├── README.md
├── backend
│   ├── api
│   ├── app
│   ├── db
│   └── models
├── cmd
│   ├── root.go
│   ├── serve.go
│   └── version.go
├── config.yaml
├── frontend
│   ├── README.md
│   ├── build
│   ├── node_modules
│   ├── package-lock.json
│   ├── package.json
│   ├── public
│   └── src
├── go.mod
├── go.sum
└── main.go

cmd

This is where all of the command that we'll want to run for our service. Most interesting in this example is serve.go but in the future it's possible to add entry points to handle migrations, etc.

backend

Anything related to the backend goes in here. In this example we've broken the application up into different responsibilities, api, app, db, and models. At a high level, we will have one go file for each of these different sections for each high level concept in our applications. For example, if we want to add the concept of a user to our application, we will have a file called user.go in api, app, db, and models all responsible for handling each of the different responsibility.

api

We'll put all of our routing logic in here. Any handler function that we need to define to handle the api interactions will be defined in here.

app

This serves as the broken between the api and the database and contains all of the business logic for the application.

db

This handles the actual database interactions for each of the different models we have.

models

Defines the data that will be stored in each model and any convience methods for accessing or modifying that data.

frontend

The front end is just a react app generated with npx create-react-app frontend. This will house all of the frontend code that will be served by our golang backend service. You can either run the front end with npm start in developement to get the live-reload functionality but in production we'll pre-compile the app with yarn build and then serve it directly with go.

About

Test bed for bootstrapping a react frontend/go backend webapp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •