Skip to content

Commit cb6f9e7

Browse files
authored
Merge pull request #13 from upsaurav12/improvements
fix: some improvements
2 parents 867d54f + 43cb07f commit cb6f9e7

File tree

6 files changed

+97
-60
lines changed

6 files changed

+97
-60
lines changed

README.md

Lines changed: 75 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Go Bootstrapper
1+
# BootstrapCLI
22

3-
**Go Bootstrapper** is a CLI tool that scaffolds production-ready Golang projects — no dependency headaches, no manual setup.
3+
**BootstrapCLI** is a CLI tool that scaffolds production-ready Golang projects — no dependency headaches, no manual setup.
44
Just run a command and get a fully configured project with linters, routers, and structure ready to code.
55

66
* * *
@@ -18,74 +18,106 @@ Once installed, confirm the installation:
1818

1919
## Quick Start 💨
2020

21-
Create a REST API project using **Gin**:
21+
#### 1. Create a New Project
2222

2323
```
24-
bootstrap new myapp --type=rest --router=gin --port=8080
24+
bootstrap new myapp --type=rest --router=gin --port=8080 --db=postgres
2525
```
26+
- This command scaffolds a production-ready Go project with:
27+
- Standard project structure
28+
- Database configuration
29+
- Router setup
30+
- Makefile and tooling
2631

27-
Create a project with **PostgreSQL** integration:
32+
#### 2. Prepare the Project
2833

2934
```
30-
bootstrap new myapp --type=rest --router=gin --db=postgres
35+
cd myapp && make tidy
36+
```
37+
38+
#### 3. Start Required Services (Database)
39+
```
40+
docker compose up -d
41+
```
42+
43+
Before running ``make run`` make sure that you have running 'db' in docker, running with the same credentials as in .env file.
44+
45+
#### 4. Run the Application
46+
47+
```
48+
make run
3149
```
3250

33-
* * *
3451

3552
## Example Project Structure
3653

3754
```
3855
myapp/
39-
├── Makefile
40-
├── README.md
41-
├── cmd/
42-
│ └── main.go
43-
├── internal/
44-
│ ├── config/
45-
│ │ └── config.go
46-
│ ├── handler/
47-
│ │ └── user_handler.go
48-
│ ├── router/
49-
│ │ └── routes.go
50-
│ └── db/ ← created only if --db flag is passed
51-
│ └── db.go
52-
└── go.mod
56+
├── cmd
57+
│ └── main.go
58+
├── docker-compose.yml
59+
├── go.mod
60+
├── go.sum
61+
├── internal
62+
│ ├── config
63+
│ │ ├── config.go
64+
│ │ └── config_test.go
65+
│ ├── db
66+
│ │ └── database.go
67+
│ ├── handler
68+
│ │ └── user_handler.go
69+
│ ├── model
70+
│ │ ├── registory.go
71+
│ │ └── user_model.go
72+
│ ├── repository
73+
│ │ └── user_repo.go
74+
│ ├── server
75+
│ │ ├── routes.go
76+
│ │ └── server.go
77+
│ └── service
78+
│ └── user_service.go
79+
├── Makefile
80+
├── project.yaml
81+
└── README.md
5382
5483
```
5584

56-
* * *
57-
5885
## CLI Options
86+
### `new`
5987

60-
| Flag | Description | Example |
61-
| --- | --- | --- |
62-
| --type | Type of project (rest, grpc, etc.) | --type=rest |
63-
| --router | Router framework (gin, chi, echo) | --router=gin |
64-
| --port | Application port | --port=8080 |
65-
| --db | Database integration | --db=postgres |
88+
Creates a new project with the specified configuration options.
6689

67-
* * *
90+
### Flags
6891

69-
## Why Go Bootstrapper?
92+
| Flag | Description | Example |
93+
|--------------|-------------------------------------------------|----------------------|
94+
| `--type` | Type of project (e.g., `rest`) | `--type=rest` |
95+
| `--router` | Router framework (`gin`, `chi`, `echo`, `fiber`) | `--router=gin` |
96+
| `--port` | Application port | `--port=8080` |
97+
| `--db` | Database integration | `--db=postgres` |
98+
| `--entities` | Add entities | `--entities=user` |
7099

71-
Developers often waste time repeating setup tasks — creating folders, configuring routers, writing Makefiles, adding linters, etc.
72100

73-
**Go Bootstrapper** automates all that.
74-
You focus on business logic — it handles the rest.
101+
### `apply`
102+
Create a new project using yaml file configurations
103+
| Flag | Description | Example |
104+
|--------------|------------------------------------------------- |----------------------|
105+
| `--yaml` | unique file name for the yaml file | `--yaml=project.yaml`|
75106

76-
It’s like:
107+
**BootstrapCLI** automates all that.
108+
You focus on business logic — it handles the rest.
77109

78-
> `create-react-app`, but for Golang �
110+
> Note: This is my first OSS project, I want to make a CLI tool(maybe webUI) which is not just generator tool which only generate
111+
> go code, but it will help developers to follow best practices, and assist during the project development. In future versions of the project i will add AI which will help developer to assist during their development and help in debugging + fixing error. I am adding AI not to generate code in there project but for assisting purpose only.
79112
80113
* * *
81114

82115
## Roadmap
83116

84-
* Add `--with-auth` flag for JWT + middleware setup
85-
* `add` command to make CLI tool more extensible to generate ``service``, ``handlers``, ``controllers``.
86-
* Commands like ``build``, ``test``, ``dev``, ``fmt`` to make it more developer friendly, ensuring production ready code.
87-
* ``init`` that will be used for letting users to choose their configurations via ``TUI``.
88-
117+
* Add CLI command that let users to write their project description, to generate the project automatically without using flags.
118+
* Command such as ``explain``, ``error`` , ``upgrade`` for the tool to make it progressive CLI tool.
119+
* Add support for ``auth``, ``logging`` , ``observability`` and so on if it make sense.
120+
* Add functionality in which users can switch to other options, for example postgres -> mongodb.
89121

90122
* * *
91123

@@ -94,12 +126,12 @@ It’s like:
94126
Contributions, feedback, and ideas are welcome!
95127
Feel free to open an issue or PR on [GitHub](https://github.com/upsaurav12/bootstrap).
96128

97-
Consider star the project 🙏
129+
Hope you like this project.
98130

99131
* * *
100132

101133
## License
102134

103-
Licensed under the **MIT License** © 2025 [Saurav Upadhyay](https://github.com/upsaurav12)
135+
Licensed under the **MIT License** © 2026 [Saurav Upadhyay](https://github.com/upsaurav12)
104136

105137
* * *

cmd/new.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type TemplateData struct {
142142
OtherImports string
143143
UpperEntity []string
144144
ApiGroup func(entity string, get string, lowerentity string) string
145+
IsAPIGroup bool
145146
Get string
146147
FullContext string
147148
ToTheClient string
@@ -215,6 +216,7 @@ func buildTemplateData(projectName string,
215216
Returnable: frameworkConfig.Returnable,
216217
ReturnKeyword: frameworkConfig.ReturnKeyword,
217218
HTTPHandler: frameworkConfig.HTTPHandler,
219+
IsAPIGroup: frameworkConfig.IsAPIGroup,
218220
Entities: Entities,
219221
// UpperEntity: ,
220222
}
@@ -246,6 +248,7 @@ func buildTemplateData(projectName string,
246248
ReturnKeyword: frameworkConfig.ReturnKeyword,
247249
HTTPHandler: frameworkConfig.HTTPHandler,
248250
Entities: yamlConfig.Entities,
251+
IsAPIGroup: frameworkConfig.IsAPIGroup,
249252
}
250253
}
251254

pkg/framework/framework.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type FrameworkConfig struct {
2424
ReturnKeyword string
2525
HTTPHandler string
2626
Entities []string
27+
IsAPIGroup bool
2728
}
2829

2930
var FrameworkRegistory = map[string]FrameworkConfig{
@@ -38,6 +39,7 @@ var FrameworkRegistory = map[string]FrameworkConfig{
3839
Start: "gin.Default()",
3940
OtherImports: `"net/http"`,
4041
FullContext: "c *gin.Context",
42+
IsAPIGroup: true,
4143
ApiGroup: func(entity string, get string, lowerentity string) string {
4244
apiGroup := fmt.Sprintf(`
4345
{
@@ -80,18 +82,19 @@ var FrameworkRegistory = map[string]FrameworkConfig{
8082
"github.com/go-chi/render"
8183
"net/http"
8284
`,
85+
IsAPIGroup: false,
8386
ApiGroup: func(entity string, get string, lowerentity string) string {
8487
apiGroup := fmt.Sprintf(`
8588
r.Group(func(r chi.Router) {
86-
r.%s("/%s", handler.Get%ss)
89+
r.%s("/%s", %sHandler.Get%ss)
8790
})
88-
`, get, lowerentity, entity)
91+
`, get, lowerentity, lowerentity, entity)
8992

9093
return apiGroup
9194
},
9295
Get: "Get",
9396
FullContext: "w http.ResponseWriter, r *http.Request",
94-
ToTheClient: "json.NewEncoder(w).Encode(",
97+
ToTheClient: "render.JSON(w,r,",
9598
Response: "(w, r,",
9699
ImportRouter: `
97100
"encoding/json"
@@ -117,17 +120,16 @@ var FrameworkRegistory = map[string]FrameworkConfig{
117120
Router: "*echo.Echo",
118121
Start: "echo.New()",
119122
OtherImports: `"net/http"`,
120-
123+
IsAPIGroup: true,
121124
ApiGroup: func(entity, get, lowerentity string) string {
122125
return fmt.Sprintf(`
123-
api := r.Group("/api/v1")
124126
{
125127
%s := api.Group("/%s")
126128
{
127-
%s.%s("", handler.Get%ss)
129+
%s.%s("", %sHandler.Get%ss)
128130
}
129131
}
130-
`, lowerentity, lowerentity, lowerentity, get, entity)
132+
`, lowerentity, lowerentity, lowerentity, get, lowerentity, entity)
131133
},
132134

133135
Get: "GET",
@@ -162,17 +164,17 @@ var FrameworkRegistory = map[string]FrameworkConfig{
162164
Router: "*fiber.App",
163165
Start: "fiber.New()",
164166
OtherImports: `"net/http"`,
165-
167+
IsAPIGroup: true,
166168
ApiGroup: func(entity, get, lowerentity string) string {
167169
return fmt.Sprintf(`
168170
api := r.Group("/api/v1")
169171
{
170172
%s := api.Group("/%s")
171173
{
172-
%s.%s("", handler.Get%ss)
174+
%s.%s("", %sHandler.Get%ss)
173175
}
174176
}
175-
`, lowerentity, lowerentity, lowerentity, get, entity)
177+
`, lowerentity, lowerentity, lowerentity, get, lowerentity, entity)
176178
},
177179

178180
Get: "Get",

project.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ project:
22
name: "test1"
33
port: 8080
44
arch: "clean"
5-
router: "chi" # or gin / echo / fiber
5+
router: "chi"
6+
db: "postgres"
67

78
entities:
89
- user
910
- product
10-
- payment

templates/rest/clean/internal/handler/example_handler.go.tmpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package handler
22

33
import (
44
"{{.ModuleName}}/internal/service"
5-
"net/http"
65

7-
"github.com/gin-gonic/gin"
6+
{{.ImportHandler}}
87
)
98

109
type {{.Entity}}Handler struct {
@@ -15,7 +14,7 @@ func New{{.Entity}}Handler(s *service.{{.Entity}}Service) *{{.Entity}}Handler {
1514
return &{{.Entity}}Handler{Service: s}
1615
}
1716

18-
func (h *{{.Entity}}Handler) Get{{.Entity}}s(c *gin.Context) {
17+
func (h *{{.Entity}}Handler) Get{{.Entity}}s({{.FullContext}}) {{.Returnable}}{
1918
{{.LowerEntity}}s, _ := h.Service.Get{{.Entity}}s()
20-
c.JSON(http.StatusOK, {{.LowerEntity}}s)
19+
{{.ReturnKeyword}} {{.ToTheClient}} {{.LowerEntity}}s)
2120
}

templates/rest/clean/internal/server/routes.go.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ func (s *Server) RegisterRoutes() {{.HTTPHandler}} {
1616

1717
gormDB := s.db.GetDB()
1818

19-
19+
{{- if .IsAPIGroup }}
2020
api := r.Group("/api/v1")
21+
{{- end }}
2122

2223
{{ if .Entities }}
2324
{{ range $i, $entity := .Entities }}

0 commit comments

Comments
 (0)