diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index a3d77f0..4106a9d 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -2,6 +2,7 @@ import { defineConfig, HeadConfig } from "vitepress"; // https://vitepress.dev/reference/site-config export default defineConfig({ + title: "GENG", description: "A tool to generate golang web project.", themeConfig: { @@ -25,7 +26,15 @@ export default defineConfig({ collapsed: false, items: [ { text: "How to use?", link: "/how-to-use" }, - // { text: "Getting Started", link: "/getting-started" }, + { text: "Generate a project", link: "/generate-project" }, + { text: "Generate a project using config", link: "/generate-project-config" }, + { text: "Start the project", link: "/start-project" }, + { text: "Project Folder structure", link: "/folder-structure" }, + { text: "Generate a module", link: "/generate-module" }, + { + text: "Generate a infrastructure", + link: "/generate-infrastructure", + }, ], }, { diff --git a/docs/enter-author-detail.png b/docs/enter-author-detail.png new file mode 100644 index 0000000..c5925e2 Binary files /dev/null and b/docs/enter-author-detail.png differ diff --git a/docs/enter-go-module-name.png b/docs/enter-go-module-name.png new file mode 100644 index 0000000..5e36cb8 Binary files /dev/null and b/docs/enter-go-module-name.png differ diff --git a/docs/enter-go-version.png b/docs/enter-go-version.png new file mode 100644 index 0000000..24763a4 Binary files /dev/null and b/docs/enter-go-version.png differ diff --git a/docs/enter-project-description.png b/docs/enter-project-description.png new file mode 100644 index 0000000..2b57076 Binary files /dev/null and b/docs/enter-project-description.png differ diff --git a/docs/enter-project-directory.png b/docs/enter-project-directory.png new file mode 100644 index 0000000..df93d06 Binary files /dev/null and b/docs/enter-project-directory.png differ diff --git a/docs/enter-project-name.png b/docs/enter-project-name.png new file mode 100644 index 0000000..1a701ab Binary files /dev/null and b/docs/enter-project-name.png differ diff --git a/docs/folder-structure.md b/docs/folder-structure.md new file mode 100644 index 0000000..7505f1c --- /dev/null +++ b/docs/folder-structure.md @@ -0,0 +1,109 @@ +--- +outline: deep +title: Start a project +description: Let's learn how to execute a project using Gen-G +--- + +# How to use? + +## Folder Structure of the project + +```bash +. +├── README.md +├── bootstrap +│   ├── app.go +│   └── module.go +├── console +│   ├── commands +│   │   ├── migration.go +│   │   ├── random.go +│   │   ├── seed.go +│   │   └── serve.go +│   └── console.go +├── docker +│   ├── custom.cnf +│   ├── db.Dockerfile +│   ├── run.sh +│   └── web.Dockerfile +├── docker-compose.yml +├── domain +│   ├── dtos +│   │   └── hello.dto.go +│   ├── hello +│   │   ├── hello.controller.go +│   │   ├── hello.module.go +│   │   ├── hello.repository.go +│   │   ├── hello.route.go +│   │   └── hello.service.go +│   ├── middlewares +│   │   └── module.go +│   ├── models +│   │   └── hello.model.go +│   └── module.go +├── go.mod +├── go.sum +├── main.go +├── migrations +│   ├── hello.go +│   ├── migrator.go +│   └── module.go +├── pkg +│   ├── framework +│   │   ├── command.go +│   │   ├── constants.go +│   │   ├── env.go +│   │   ├── logger.go +│   │   ├── migration.go +│   │   ├── module.go +│   │   └── seed.go +│   ├── infrastructure +│   │   ├── module.go +│   │   └── router.go +│   ├── middlewares +│   │   ├── command.go +│   │   ├── module.go +│   │   └── rate_limitter.go +│   ├── module.go +│   ├── responses +│   │   └── response.go +│   ├── services +│   │   └── module.go +│   └── utils +│   ├── aws_error.go +│   └── functional_programming.go +└── seeds + ├── hello.go + ├── module.go + └── seeder.go + +19 directories, 48 files +``` + +## Folder Structure :file_folder: + +| Folder Path | Description | +| -------------------------------- | ------------------------------------------------------------------------------------------------------------ | +| `/bootstrap` | contains modules required to start the application | +| `/console` | server commands, run `go run main.go -help` for all the available server commands | +| `/docker` | `docker` files required for `docker compose` | +| `/domain` | contains dtos, models, constants and folder for each domain with controller, repository, routes and services | +| `/domain/constants` | global application constants | +| `/domain/models` | ORM models | +| `/domain/` | controller, repository, routes and service for a `domain`. In this template `user` is a domain | +| `/pkg` | contains setup for api_errors, infrastructure, middlewares, external services, utils | +| `/pkg/api-errors` | server error handlers | +| `/pkg/framework` | contains env parser, logger... | +| `/pkg/infrastructure` | third-party services connections like `gmail`, `firebase`, `s3-bucket`, ... | +| `/pkg/middlewares` | all middlewares used in the app | +| `/pkg/responses` | different types of http responses are defined here | +| `/pkg/services` | service layers, contains the functionality that compounds the core of the application | +| `/pkg/types` | data types used throught the application | +| `/pkg/utils` | global utility/helper functions | +| `/seeds` | seeds for already migrated tables | +| `/tests` | includes application tests | +| `.env.example` | sample environment variables | +| `dbconfig.yml` | database configuration file for `sql-migrate` command | +| `docker-compose.yml` | `docker compose` file for service application via `Docker` | +| `main.go` | entry-point of the server | +| `Makefile` | stores frequently used commands; can be invoked using `make` command | \ No newline at end of file diff --git a/docs/generate-project-config.md b/docs/generate-project-config.md new file mode 100644 index 0000000..d0fad3f --- /dev/null +++ b/docs/generate-project-config.md @@ -0,0 +1,77 @@ +--- +outline: deep +title: Scaffold a project +description: Let's learn how to generate a project using Gen-G +--- + +# How to use? + +## Generate a project using config + +Instead of using the following command. +```bash +geng new +``` + +- Create a `geng.json` file which can contain following value: +```jsonc +{ + "projectName": "todo app", + "projectModuleName": "github.com/mukezhz/todo", + "author": "Mukesh Kumar Chaudhary ", + "projectDescription": "A simple todo project", + "goVersion": "1.21" + // "directory": ".", + // "infrastructureName": [], + // "serviceName": [] +} +``` + +Now enter the project generation command. +```bash +geng new +``` + +You will get the similar output: +```bash + + GENG: GENERATE GOLANG PROJECT + + ██████╗ ███████╗███╗ ██╗ ██████╗ + ██╔════╝ ██╔════╝████╗ ██║ ██╔════╝ + ██║ ███╗█████╗ ██╔██╗ ██║█████╗██║ ███╗ + ██║ ██║██╔══╝ ██║╚██╗██║╚════╝██║ ██║ + ╚██████╔╝███████╗██║ ╚████║ ╚██████╔╝ + ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ + + + + The information you have provided: + + Project Name 💻: Todo App + Project Module 📂: github.com/mukezhz/todo + Project Description 📚: A simple todo project + Go Version 🆚: 1.21 + Author Detail 🤓: Mukesh Kumar Chaudhary + + 💻 Change directory to project: + cd todo_app + + 💾 Initalize git repository: + git init + + 📚 Sync dependencies: + go mod tidy + + 🕵 Copy .env.example to .env: + cp .env.example .env + + 🏃 Start Project 🏃: + go run main.go app:serve + + Thank You For using 🙏🇳🇵🙏: +``` + +**Note:** I have filled the project description, author name and go version. + +:tada: Now follow the instruction and run the project \ No newline at end of file diff --git a/docs/generate-project.md b/docs/generate-project.md new file mode 100644 index 0000000..69bc838 --- /dev/null +++ b/docs/generate-project.md @@ -0,0 +1,86 @@ +--- +outline: deep +title: Scaffold a project +description: Let's learn how to generate a project using Gen-G +--- + +# How to use? + +## Generate a project + +In order to generate a project you need to enter the following command: +```bash +geng new +``` + +Once you enter the command it will ask you bunch of questions. + +- To enter Project Name * +![enter project name](./enter-project-name.png) +- To enter Project Module * +![enter go module name](./enter-go-module-name.png) +- To enter Author Detail [Optional] +![author detail](./enter-author-detail.png) +- To enter Project Description [Optional] +![project description](./enter-project-description.png) +- To enter Go Version [Optional] +![go version](./enter-go-version.png) +- To enter Project Directory [Optional] +![project directory](./enter-project-directory.png) +- To Select the infrastructure? **Use Space key to Select** [Optional] +![select infrastructure](./select-infrastructure.png) + +### After filling all question you will get following output +```bash + + GENG: GENERATE GOLANG PROJECT + + ██████╗ ███████╗███╗ ██╗ ██████╗ + ██╔════╝ ██╔════╝████╗ ██║ ██╔════╝ + ██║ ███╗█████╗ ██╔██╗ ██║█████╗██║ ███╗ + ██║ ██║██╔══╝ ██║╚██╗██║╚════╝██║ ██║ + ╚██████╔╝███████╗██║ ╚████║ ╚██████╔╝ + ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ + + + + The information you have provided: + + Project Name 💻: Todo App + Project Module 📂: github.com/mukezhz/todo + Project Description 📚: + Go Version 🆚: 1.20 + Author Detail 🤓: + + 💻 Change directory to project: + cd todo_app + + 💾 Initalize git repository: + git init + + 📚 Sync dependencies: + go mod tidy + + 🕵 Copy .env.example to .env: + cp .env.example .env + + 🏃 Start Project 🏃: + go run main.go app:serve + + Thank You For using 🙏🇳🇵🙏: +``` + +### Entered value + +Here I have entered the following value: +1. project name: todo app +2. go module name: github.com/mukezhz/todo +3. author detail: [just pressed enter ie. empty] +4. project description: [just pressed enter ie. empty] +5. go version: [just pressed enter ie. empty] +6. project directory: [just pressed enter ie. empty] +7. select infrastructure: [just pressed enter ie. empty] + +**Note:** You can fill the optional value + +:tada: Now follow the instruction and run the project \ No newline at end of file diff --git a/docs/how-to-use.md b/docs/how-to-use.md index 4ad752f..9d46cc4 100644 --- a/docs/how-to-use.md +++ b/docs/how-to-use.md @@ -4,4 +4,43 @@ outline: deep # How to Use -# \ No newline at end of file +## Guide + +Gen-G is designed with user-friendliness as a priority, making it straightforward to use. Like most command-line interface (CLI) tools, it follows a specific pattern: + +```bash +geng command [flag] +``` + +You can get the list of command using: + +```bash +geng help +``` + +### Output +```bash +geng is a CLI library for Go that empowers applications. + +Usage: + geng [command] + +Available Commands: + completion Generate the autocompletion script for the specified shell + gen Create a new domain + help Help about any command + infra Add a new infrastructure + migrate migrate the project + new Create a new project + run Run the project + seed Seed the project + service Add a new Service + start Execute the project + +Flags: + -h, --help help for geng + +Use "geng [command] --help" for more information about a command. +``` + +Please refer to the dedicated section of each command. \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 9497e31..2f468d6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,11 +15,11 @@ hero: link: /roadmap features: - - title: Feature A - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit - - title: Feature B - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit - - title: Feature C - details: Lorem ipsum dolor sit amet, consectetur adipiscing elit + - title: Generate Go Project + details: Gen-G will help you to generate a starter for go gin project + - title: Generate a module + details: Gen-G will help you to generate module which will setup DI + - title: Generate from bru file + details: Gen-G will help you to generate module from Bru file --- diff --git a/docs/module-name.png b/docs/module-name.png new file mode 100644 index 0000000..ff4d342 Binary files /dev/null and b/docs/module-name.png differ diff --git a/docs/project-name.png b/docs/project-name.png new file mode 100644 index 0000000..8e92015 Binary files /dev/null and b/docs/project-name.png differ diff --git a/docs/select-infrastructure.png b/docs/select-infrastructure.png new file mode 100644 index 0000000..6b9a06d Binary files /dev/null and b/docs/select-infrastructure.png differ diff --git a/docs/start-project.md b/docs/start-project.md new file mode 100644 index 0000000..310f9f7 --- /dev/null +++ b/docs/start-project.md @@ -0,0 +1,77 @@ +--- +outline: deep +title: Start a project +description: Let's learn how to execute a project using Gen-G +--- + +# How to use? + +## Start the project + +In order to start a project just follow the given instruction which has been printed on project generation step. + +1. change the directory if you haven't specified project directory to . (ie. current directory) +```bash +cd [your project name] +``` +2. initialize the git +```bash +git init +``` +3. install the dependency using +```bash +go mod tidy +``` +4. copy the .env.example to .env +```bash +cp .env.example .env +``` +5. run the project +``` +geng run app:serve +//or +go run . app:serve +``` + +### Output +```bash +➜ geng git:(main) ✗ cd todo_app +➜ todo_app git:(main) ✗ go mod tidy +go: finding module for package github.com/aws/smithy-go +go: found github.com/aws/smithy-go in github.com/aws/smithy-go v1.20.3 +... +➜ todo_app git:(main) ✗ git init +Initialized empty Git repository in /Users/mukesh.chaudhary/GolandProjects/geng/todo_app/.git/ +➜ todo_app git:(main) ✗ cp .env.example .env +➜ todo_app git:(main) ✗ geng run app:serve +2024-07-08T20:27:08.001+0545 INFO [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached. + + +2024-07-08T20:27:08.002+0545 INFO [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production. + - using env: export GIN_MODE=release + - using code: gin.SetMode(gin.ReleaseMode) + + +2024-07-08T20:27:08.002+0545 INFO [GIN-debug] GET /health-check --> github.com/mukezhz/todo/pkg/infrastructure.NewRouter.func1 (5 handlers) + +2024-07-08T20:27:08.002+0545 INFO [GIN-debug] GET /api/hello --> github.com/mukezhz/todo/domain/hello.(*Controller).HandleRoot-fm (5 handlers) + +2024-07-08T20:27:08.002+0545 INFO commands/serve.go:29 +-----------------------+ +2024-07-08T20:27:08.002+0545 INFO commands/serve.go:30 | GO CLEAN ARCHITECTURE | +2024-07-08T20:27:08.002+0545 INFO commands/serve.go:31 +-----------------------+ +2024-07-08T14:42:08.002Z INFO commands/serve.go:49 Running server +2024-07-08T14:42:08.002Z INFO [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value. +Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details. + +2024-07-08T14:42:08.002Z INFO [GIN-debug] Listening and serving HTTP on :5000 +``` + +### Info + +Once you follow all the step correctly you can see your app running at port **:5000** + +you can verify it using curl: +```bash +curl http://localhost:5000/health-check +# or simply enter the uri in browser +``` \ No newline at end of file