Giter Site home page Giter Site logo

appist / appy Goto Github PK

View Code? Open in Web Editor NEW
131.0 6.0 14.0 5.32 MB

An opinionated productive web framework that helps scaling business easier.

License: MIT License

Go 85.07% Makefile 0.23% Smarty 14.70%
golang graphql prerender 12factor docker full-stack mailer worker sveltekit

appy's Introduction

appy

Build Status Vulnerabilities Check Go Report Card Coverage Status Go Doc Platform Support

An opinionated productive web framework that helps scaling business easier, i.e. focus on monolith first, only move to microservices with GRPC later on when your team is ready.

Click to see an application called "appist" made with "appy" in action

Debug Mode     Release Mode

Additional Notes

  • appy is made as a package for your application to import without the need to install any additional binary
  • appy glues the great packages to provide best productivity in developing Go web application
  • appy comes with 2 build types:
    • debug - when the code is NOT running within the binary
    • release - when the code is running within the binary
  • appy follows 12factor via APPY_ENV environment variable:
    • by default, it is development
    • when APPY_ENV=staging is set, the config file is configs/.env.staging
    • utilise configs/.env.<APPY_ENV> to support multiple environments deployment

Table Of Contents

Overview

architecture

Features

package cmd

  • Powerful built-in commands

    Click to see details
    My first awesome web application in Go.
    
    Usage:
      myapp [command]
    
    Available Commands:
      build             Compile the static assets into go files and build the release build binary (only available in debug build)
      config:dec        Decrypt a config value using the secret in `configs/<APPY_ENV>.key` or `APPY_MASTER_KEY` (only available in debug build)
      config:enc        Encrypt a config value using the secret in `configs/<APPY_ENV>.key` or `APPY_MASTER_KEY` (only available in debug build)
      db:create         Create all databases for the current environment
      db:drop           Drop all databases for the current environment
      db:migrate        Migrate the database(default: all, use --database to specify the target database) for the current environment
      db:migrate:status List all the database migration status(default: all, use --database to specify the target database) for the current environment
      db:rollback       Rollback the database(default: primary, use --database to specify the target database) to previous version for the current environment
      db:schema:dump    Dump all the databases schema for the current environment (only available in debug build)
      db:schema:load    Load all the databases schema for the current environment
      db:seed           Seed all databases for the current environment
      dc:down           Tear down the docker compose cluster
      dc:restart        Restart services that are defined in `docker-compose.yml`
      dc:up             Create and start containers that are defined in `docker-compose.yml`
      gen:migration     Generate database migration file(default: primary, use --database to specify the target database) for the current environment (only available in debug build)
      help              Help about any command
      middleware        List all the global middleware
      routes            List all the server-side routes
      secret            Generate a cryptographically secure secret key for encrypting cookie, CSRF token and config
      secret:rotate     Rotate the secret that is used to encrypt/decrypt the configs (only available in debug build)
      serve             Run the HTTP/HTTPS web server without `webpack-dev-server`
      setup             Run dc:up/db:create/db:schema:load/db:seed to setup the datastore with seed data
      ssl:setup         Generate and install the locally trusted SSL certs using `mkcert`
      ssl:teardown      Uninstall the locally trusted SSL certs using `mkcert`
      start             Run the HTTP/HTTPS web server with `webpack-dev-server` in development watch mode (only available in debug build)
      teardown          Tear down the docker compose cluster
      work              Run the worker to process background jobs
    
    Flags:
      -h, --help      help for myapp
      -v, --version   version for myapp
    
    Use "myapp [command] --help" for more information about a command.
  • Flexible custom commands building

package mailer

  • Ready-to-use SMTP email sending

  • I18n support

  • HTML templates binary embed support

  • Developer friendly email preview UI

    Click to see details

    Preview UI

package pack

  • Powerful built-in HTTP middleware

    Click to see details
    • API Only
      Remove Set-Cookie response header if the X-API-ONLY: 1 request header is sent.

    • CSRF
      Protect cookies from Cross-Site Request Forgery by including/validating a token in the cookie across requests.

    • GZIP Compress
      Compress the responses before returning it to the clients.

    • Health Check
      Provide the HTTP GET endpoint for health check purpose.

    • I18n
      Provide I18n support which the translations are stored in <PROJECT_NAME>/pkg/locales/*.yml.

    • Logger
      Provide logger support.

    • Mailer
      Provide mailer support which the views templates are stored in <PROJECT_NAME>/pkg/views/mailers/**/*.{html,txt}.

    • Prerender
      Prerender and return the SPA page rendered by Chrome if the HTTP request is coming from the search engines.

    • Real IP
      Retrieves the client's real IP address via X-FORWARDED-FOR or X-REAL-IP HTTP request header.

    • Recovery
      Recover the HTTP request from panic and return 500 error page.

    • Request ID
      Generate UUID v4 string for every HTTP request.

    • Request Logger
      Log the HTTP request information.

    • Secure
      Provide the standard HTTP security guards.

    • Session
      Provide session management using cookie/redis.

    • SPA
      Provide SPA hosting with specific path.

    • View Engine
      Provide server-side HTML template rendering.

  • Fully integrated with gqlgen with watch mode

  • Ready-to-use test context builder for unit test

package record

  • Powerful database management commands

    Click to see details
    db:create         Create all databases for the current environment
    db:drop           Drop all databases for the current environment
    db:migrate        Migrate the database(default: all, use --database to specify the target database) for the current environment
    db:migrate:status List all the database migration status(default: all, use --database to specify the target database) for the current environment
    db:rollback       Rollback the database(default: primary, use --database to specify the target database) to previous version for the current environment
    db:schema:dump    Dump all the databases schema for the current environment (only available in debug build)
    db:schema:load    Load all the databases schema for the current environment
    db:seed           Seed all databases for the current environment
  • Extended sql.DB with sqlx

  • Fully featured ORM

    Click to see details
    • Multiple databases support
    • Master/Replica switch
    • Soft delete
    • Associations (Not Yet Supported)
      • Has One
      • Has Many
      • Belongs To
      • Many To Many
      • Polymorphism
      • Preload
      • Eager Load
    • Callbacks
      • BeforeValidate/AfterValidate
      • BeforeCreate/AfterCreate
      • BeforeDelete/AfterDelete
      • BeforeUpdate/AfterUpdate
      • BeforeCommit/AfterCreateCommit/AfterDeleteCommit/AfterUpdateCommit
      • BeforeRollback/AfterRollback
    • Composite primary keys
    • Execution with context
    • SQL query builder/logger/inspector
    • Transactions
    • Validations with I18n support
  • Performant ORM

    Click to see details
    go test -run=NONE -bench . -benchmem -benchtime 10s -failfast ./record
    goos: darwin
    goarch: amd64
    pkg: github.com/appist/appy/record
    BenchmarkInsertRaw-4                1239          10103533 ns/op              88 B/op          5 allocs/op
    BenchmarkInsertDB-4                  898          11351591 ns/op            1548 B/op         19 allocs/op
    BenchmarkInsertORM-4                 826          13826999 ns/op           15338 B/op        283 allocs/op
    BenchmarkInsertMultiRaw-4            529          21830643 ns/op          107896 B/op        415 allocs/op
    BenchmarkInsertMultiDB-4             481          20931749 ns/op          166302 B/op        441 allocs/op
    BenchmarkInsertMultiORM-4            471          23261618 ns/op          791677 B/op       3872 allocs/op
    BenchmarkUpdateRaw-4                 903          13807008 ns/op            1064 B/op         21 allocs/op
    BenchmarkUpdateDB-4                 1008          13577352 ns/op            3677 B/op         52 allocs/op
    BenchmarkUpdateORM-4                 788          13923442 ns/op            8920 B/op        233 allocs/op
    BenchmarkReadRaw-4                  2162           4723198 ns/op            1810 B/op         47 allocs/op
    BenchmarkReadDB-4                   2263           5300805 ns/op            3257 B/op         69 allocs/op
    BenchmarkReadORM-4                  2259           5184327 ns/op            6911 B/op        230 allocs/op
    BenchmarkReadSliceRaw-4             2210           5871991 ns/op           23088 B/op       1331 allocs/op
    BenchmarkReadSliceDB-4              2197           5752959 ns/op           25070 B/op       1353 allocs/op
    BenchmarkReadSliceORM-4             1864           6249231 ns/op          246630 B/op       1526 allocs/op
    PASS
    ok      github.com/appist/appy/record   344.692s
  • Ready-to-use DB/ORM mocks for unit test

package view

  • Performant and fully featured template engine

  • I18n support

  • HTML templates binary embed support

package worker

  • Fully featured background job processing backed by Redis

    Click to see details
    • Cron jobs (Work In Progress)
    • Expiring jobs
    • Unique jobs
    • Scheduled jobs
    • Error handling
    • Middleware
    • Responsive Web UI + Authorization + Search (Work In Progress)
    • Strict/Weighted priority queues
  • Ready-to-use handler mock for unit test

Getting Started

Prerequisites

Quick Start

Step 1: Create the project folder with go module and git initialised.

$ mkdir <PROJECT_NAME> && cd $_ && go mod init $_ && git init

Note: The <PROJECT_NAME> must be an alphanumeric string.

Step 2: Create main.go with the snippet below.

package main

import (
  "github.com/appist/appy/cmd"
)

func main() {
  err := cmd.Scaffold()

  if err != nil {
    panic(err)
  }
}

Step 3: Initialize the project layout.

$ go run .

Step 4: Setup the databases using Docker Compose.

$ go run . setup

Step 5: Start developing your application locally.

$ go run . start

Acknowledgement

  • asynq - For processing background jobs
  • cobra - For building CLI
  • gin - For building HTTP router
  • gqlgen - For building GraphQL API
  • sqlx - For interacting with MySQL/PostgreSQL
  • testify - For writing unit tests
  • zap - For blazing fast, structured and leveled logging

Contribution

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed to appy!

License

MIT

Copyright (c) 2019-present, Appist

appy's People

Contributors

cayter avatar dependabot-preview[bot] avatar gitter-badger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

appy's Issues

[FEATURE] Implement interactive scaffolding with dependencies installed

Description

As a new user of the web framework, I would like to go through a guided flow to scaffold my web application and automatically install Go/NodeJS dependencies.

Suggested Tools

Expected Developer Experience

  1. Create the project folder with go module and git initialised.
$ mkdir <PROJECT_NAME> && cd $_ && go mod init $_ && git init
  1. Create main.go with the snippet below.
package main

import (
  "github.com/appist/appy/support"
)

func main() {
  support.Scaffold()
}
  1. Initialise the project layout with Go/NodeJS dependencies installed.
$ go run .
  1. Setup your local environment with databases running in docker compose cluster.
$ go run . setup
  1. Start developing your application locally.
$ go run . start
  1. Build the application binary with release mode.
$ go run . build
  1. Tear down everything once you're done testing.
$ go run . teardown

[FEATURE] Implement project scaffolding

Description

As a developer, I would like to easily setup a new project, so that I can focus on business and get the product to the market ASAP.

Expected Developer Experience

  • Initialize go modules with pre-defined main.go
  • Run go run .
  • Able to start development with docker-compose cluster setup
  • Able to build release mode

[BUG] go run . setup returns ERROR Version in "None" is unsupported

Description

go run . setup returns the error below:

ERROR: Version in "None" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
2020-08-04T11:04:51.627-0700	FATAL	exit status 1
github.com/appist/appy/cmd.newSetupCommand.func1
	/home/rob/go/pkg/mod/github.com/appist/[email protected]/cmd/setup.go:30
github.com/spf13/cobra.(*Command).execute
	/home/rob/go/pkg/mod/github.com/spf13/[email protected]/command.go:846
github.com/spf13/cobra.(*Command).ExecuteC
	/home/rob/go/pkg/mod/github.com/spf13/[email protected]/command.go:950
github.com/spf13/cobra.(*Command).Execute
	/home/rob/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
github.com/appist/appy.(*App).Run
	/home/rob/go/pkg/mod/github.com/appist/[email protected]/app.go:109
gofishee/pkg/app.Run
	/home/rob/dv/go/gofishee/pkg/app/app.go:104
main.main
	/home/rob/dv/go/gofishee/main.go:28
runtime.main
	/home/linuxbrew/.linuxbrew/Cellar/go/1.14.6/libexec/src/runtime/proc.go:203
exit status 1

Steps To Reproduce

  1. Went through the setup steps with mysql selected and name the project as gofishee
  2. Run go run . setup

[FEATURE] Implement ORM `belongsTo` association support

Description

As a developer who had used ActiveRecord before, I would like to streamline the ORM operations if there is a connection between 2 models.

Expected Developer Experience

  • Rely on association:"belongsTo" struct tag
  • Supported options:
    • dependent: delete, delete_without_callbacks
    • foreignKey
    • optional
    • polymorphic (will come together with hasOne/hasMany)
    • primaryKeys
    • touch
    • validate

[FEATURE] Implement config secret rotate command

Description

As a developer, I would like to easily rotate the secret for my config so that I don't have to re-encrypt all the config values 1 by 1.

Expected Developer Experience

  • Run a command called go run . secret:rotate <OLD_SECRET> <NEW_SECRET>
  • Display error if the OLD_SECRET is invalid
  • Re-encrypt all the config values automatically without changing the file format/comments

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

go: github.com/BurntSushi/[email protected] requires
	github.com/BurntSushi/[email protected] requires
	github.com/BurntSushi/[email protected] requires
	github.com/BurntSushi/[email protected] requires
	github.com/BurntSushi/[email protected] requires
	github.com/BurntSushi/[email protected] requires
	github.com/BurntSushi/[email protected]: invalid version: unknown revision

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

[FEATURE] Implement ORM `hasOne` association support

Description

As a developer who had used ActiveRecord before, I would like to streamline the ORM operations if there is a connection between 2 models.

Expected Developer Experience

  • Rely on association:"hasOne" struct tag
  • Supported options:
    • as
    • dependent: delete, delete_without_callbacks, nullify
    • foreignKey
    • primaryKeys
    • source
    • sourceType
    • through
    • touch
    • validate

[BUG] Project scaffolding doesn't work with go module name that contains special character `-`

Description

go run . setup has many warnings and fails on syntax error: pkg/graphql/generated/generated.go:2204:44: syntax error: unexpected -, expecting ( pkg/graphql/generated/generated.go:2208:6: missing function body.

Steps To Reproduce

  1. Performed Step 1, 2 and 3 of Quickstart
  2. Error occurs on Step 4: go run . setup
  3. MySql was selected
  4. Project/Module name was "go-fishee"
  5. I closely followed instructions with no customizations

I am excited about this project and I look forward to making this work. Thanks!

Environment

  • OS: Ubuntu 20.04 with latest updates
  • node -v: v14.7.0
  • go version go1.14.6 linux/amd64

Additional Information

go.mod

module go-fishee

go 1.14

require (
	github.com/99designs/gqlgen v0.11.3
	github.com/appist/appy v0.1.1
	github.com/vektah/gqlparser/v2 v2.0.1
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.