gofasta new
Creates a brand-new Gofasta project from scratch. By default, this generates a REST-only project with database migrations, authentication, dependency injection, background jobs, email support, Docker configuration, and CI/CD pipelines. Pass --graphql to also include GraphQL support (gqlgen schema, resolvers, /graphql endpoint, and playground).
Usage
gofasta new <name> [flags]The <name> can be a simple name like myapp or a full Go module path like github.com/myorg/myapp. When a simple name is used (no / in the argument), the module path defaults to the project name. When a full path is provided, it is used as the Go module path and the last segment becomes the project directory name.
Flags
| Flag | Default | Description |
|---|---|---|
--graphql | false | Include GraphQL support (gqlgen schema, resolvers, /graphql endpoint, playground) |
--gql | false | Alias for --graphql |
Without --graphql, the generated project is REST-only — no GraphQL files, no gqlgen dependency, and no /graphql routes.
Examples
Create a project with a simple name:
gofasta new myappCreate a project with a full Go module path:
gofasta new github.com/myorg/myappCreate a project with GraphQL support:
gofasta new myapp --graphqlWhat It Does
When you run gofasta new myapp, the CLI performs the following steps in order:
- Create project directory — creates the
myapp/directory - Initialize Go module — runs
go mod initwith the appropriate module path - Copy skeleton files — writes template files into the project, including a starter User resource
- Install Gofasta and Cobra — runs
go get github.com/gofastadev/gofasta@latest(the gofasta library) andgo get github.com/spf13/cobra@latestto add them togo.mod - Install tools — runs
go getto add tool dependencies (wire, air, swag) andgo mod edit -toolfor each. If--graphqlis passed, gqlgen is also installed. - Tidy modules — runs
go mod tidyto synchronize dependencies - Generate Wire DI code — runs
go tool wire ./app/di/to generate the dependency injection container - Generate GraphQL code (only with
--graphql) — runsgo tool gqlgen generateto create Go types and resolvers from the GraphQL schema - Initialize Git — runs
git initand creates an initial commit
What It Generates
Running gofasta new myapp produces the following project structure. Items marked (—graphql only) are only included when the --graphql flag is passed:
myapp/
cmd/
serve.go # HTTP server entry point
app/
models/ # GORM database models
user.model.go
repositories/ # Data access layer
interfaces/
user_repository.go
user.repository.go
services/ # Business logic layer
interfaces/
user_service.go
auth_service.go
user.service.go
auth.service.go
rest/
controllers/ # REST API controllers
user.controller.go
auth.controller.go
routes/ # Route definitions
index.routes.go
user.routes.go
auth.routes.go
middlewares/ # HTTP middlewares
auth.middleware.go
casbin.middleware.go
dtos/ # Request/response DTOs
user.dtos.go
auth.dtos.go
di/ # Dependency injection (Google Wire)
container.go
wire.go
providers/
user.go
auth.go
graphql/ # GraphQL schema and resolvers (--graphql only)
schema.graphqls
resolver.go
generated.go
jobs/ # Background jobs
tasks/ # Scheduled tasks (cron)
emails/ # Email templates
db/
migrations/ # SQL migration files (up/down)
seeders/ # Database seed files
config/
config.yaml # Application configuration
docker-compose.yml # Docker Compose for app + database
Dockerfile # Multi-stage Docker build
Makefile # Common development commands
.github/
workflows/ # CI/CD pipeline definitions
.air.toml # Air hot reload configuration
.env.example # Environment variable template
gqlgen.yml # gqlgen GraphQL configuration (--graphql only)
go.mod
go.sumArchitecture
The generated project follows a layered architecture:
Controller --> Service --> Repository --> Database- Controllers handle HTTP requests and delegate to services
- Services contain business logic and call repositories
- Repositories handle database queries via GORM
- DI Container wires everything together using Google Wire
Related
- Quick Start
- Project Structure
- gofasta init — initialize a cloned project
- gofasta dev — start the development server