Skip to Content
DocumentationCLI Referencegofasta new

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

FlagDefaultDescription
--graphqlfalseInclude GraphQL support (gqlgen schema, resolvers, /graphql endpoint, playground)
--gqlfalseAlias 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 myapp

Create a project with a full Go module path:

gofasta new github.com/myorg/myapp

Create a project with GraphQL support:

gofasta new myapp --graphql

What It Does

When you run gofasta new myapp, the CLI performs the following steps in order:

  1. Create project directory — creates the myapp/ directory
  2. Initialize Go module — runs go mod init with the appropriate module path
  3. Copy skeleton files — writes template files into the project, including a starter User resource
  4. Install Gofasta and Cobra — runs go get github.com/gofastadev/gofasta@latest (the gofasta library) and go get github.com/spf13/cobra@latest to add them to go.mod
  5. Install tools — runs go get to add tool dependencies (wire, air, swag) and go mod edit -tool for each. If --graphql is passed, gqlgen is also installed.
  6. Tidy modules — runs go mod tidy to synchronize dependencies
  7. Generate Wire DI code — runs go tool wire ./app/di/ to generate the dependency injection container
  8. Generate GraphQL code (only with --graphql) — runs go tool gqlgen generate to create Go types and resolvers from the GraphQL schema
  9. Initialize Git — runs git init and 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.sum

Architecture

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
Last updated on