Skip to content
/ GoNest Public

GoNest is a powerful, scalable Go framework inspired by NestJS that provides a complete solution for building enterprise-grade applications.

License

Notifications You must be signed in to change notification settings

ulims/GoNest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GoNest Framework

Go Version License Go Report Card

A powerful, enterprise-grade Go web framework inspired by NestJS, designed for building scalable, maintainable applications with modern architectural patterns.

πŸš€ Features

  • πŸ—οΈ Modular Architecture: NestJS-style module system with dependency injection
  • πŸ”„ Lifecycle Management: Comprehensive application and module lifecycle hooks
  • πŸ›‘οΈ Built-in Security: Guards, interceptors, and authentication systems
  • πŸ“Š Database Integration: MongoDB support with Mongoose-like ODM
  • 🌐 WebSocket Support: Real-time communication capabilities
  • ⚑ High Performance: Built on Echo framework for optimal performance
  • πŸ§ͺ Testing Utilities: Built-in testing framework and utilities
  • πŸ“ Validation: Request/response validation with struct tags
  • 🎯 CLI Tools: Code generation and project management tools

πŸ“ Project Structure

When you create a new GoNest application, you'll get a well-organized project structure that follows Go and NestJS best practices:

my-gonest-app/
β”œβ”€β”€ cmd/
β”‚   └── server/
β”‚       └── main.go           # Application entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ modules/              # Feature modules (business domains)
β”‚   β”‚   β”œβ”€β”€ user/            # User module example
β”‚   β”‚   β”‚   β”œβ”€β”€ user_module.go     # Module definition and DI setup
β”‚   β”‚   β”‚   β”œβ”€β”€ user_service.go    # Business logic layer
β”‚   β”‚   β”‚   β”œβ”€β”€ user_controller.go # HTTP request handlers
β”‚   β”‚   β”‚   └── user_dto.go        # Data transfer objects
β”‚   β”‚   └── auth/            # Authentication module
β”‚   β”œβ”€β”€ config/              # Configuration management
β”‚   β”‚   └── config.go
β”‚   β”œβ”€β”€ middleware/          # Custom middleware
β”‚   └── shared/              # Shared utilities and types
β”œβ”€β”€ pkg/                     # Public packages (if needed)
β”œβ”€β”€ scripts/                 # Build and deployment scripts
β”œβ”€β”€ docs/                    # Project documentation
β”œβ”€β”€ tests/                   # Integration and e2e tests
β”œβ”€β”€ .env                     # Environment variables
β”œβ”€β”€ .gitignore              # Git ignore rules
β”œβ”€β”€ go.mod                  # Go module definition
β”œβ”€β”€ go.sum                  # Dependency checksums
β”œβ”€β”€ Dockerfile              # Container configuration
β”œβ”€β”€ docker-compose.yml      # Multi-service setup
└── README.md              # Project documentation

Module Structure

Each feature module follows a consistent, flat structure inspired by NestJS:

internal/modules/user/
β”œβ”€β”€ user_module.go          # Module registration and dependency injection
β”œβ”€β”€ user_controller.go      # HTTP request handling
β”œβ”€β”€ user_service.go         # Business logic implementation
β”œβ”€β”€ user_dto.go            # Request/response data structures
β”œβ”€β”€ user_entity.go         # Domain entities/models
└── user_repository.go     # Data access layer (if needed)

πŸš€ Installation

To get started, you can either use our CLI tool (recommended), automated setup scripts, or manually set up your project. All approaches will produce the same outcome.

πŸš€ CLI Tool (Recommended)

Our CLI tool provides the fastest and most reliable way to create a new GoNest project:

# 1. Clone the GoNest repository
$ git clone https://github.com/ulims/GoNest.git
$ cd GoNest

# 2. Build the CLI tool
$ go build -o gonest.exe cmd/gonest/main.go

# 3. Create a new project
$ ./gonest.exe new my-project-name

# 4. Create with specific template and strict mode
$ ./gonest.exe new my-api --template=api --strict

The CLI tool automatically:

  • βœ… Create the recommended project structure
  • βœ… Initialize Go module and Git repository
  • βœ… Install all GoNest dependencies
  • βœ… Generate configuration files
  • βœ… Set up Docker and build automation
  • βœ… Create comprehensive documentation
  • βœ… Support multiple project templates
  • βœ… Generate components (modules, controllers, services)

HINT
The CLI tool is the most reliable way to get started. It handles all dependencies and creates a production-ready project structure.

πŸš€ Automated Setup Scripts

If you prefer to use our setup scripts directly:

Linux/macOS

# Clone the GoNest repository
$ git clone https://github.com/ulims/GoNest.git
$ cd GoNest

# Make the script executable and run it
$ chmod +x scripts/setup-project.sh
$ ./scripts/setup-project.sh my-project-name

Windows

# Clone the GoNest repository
$ git clone https://github.com/ulims/GoNest.git
$ cd GoNest

# Run the batch script
$ scripts\setup-project.bat

Alternatives

Manual Setup

If you prefer to set up manually:

# Create a new directory for your project
$ mkdir my-gonest-app
$ cd my-gonest-app

# Initialize Go module
$ go mod init my-gonest-app

# Add GoNest dependency
$ go get github.com/ulims/GoNest

Basic Application Structure

package main

import (
    "context"
    "github.com/sirupsen/logrus"
    gonest "github.com/ulims/GoNest"
)

func main() {
    // Initialize logger
    logger := logrus.New()
    logger.SetLevel(logrus.InfoLevel)
    
    // Create application
    app := gonest.NewApplication().
        Config(&gonest.Config{
            Port:        "8080",
            Host:        "localhost",
            Environment: "development",
        }).
        Logger(logger).
        Build()
    
    // Start application
    if err := app.Start(); err != nil {
        logger.Fatal("Failed to start application:", err)
    }
}

Run Your Application

go run main.go

Your application will be available at http://localhost:8080

πŸ“š Documentation

🎯 Architecture Principles

GoNest follows proven architectural patterns inspired by NestJS:

  • πŸ—οΈ Modular Design: Organize code into feature modules with clear boundaries
  • πŸ’‰ Dependency Injection: Automatic dependency resolution and injection
  • πŸ“± Flat Module Structure: Keep module files organized without deep nesting
  • πŸ”„ Separation of Concerns: Controllers handle HTTP, Services handle business logic
  • πŸ§ͺ Testable by Design: Easy to mock and test individual components
  • πŸ“ Consistent Patterns: Every module follows the same organizational structure

Quick Start Example

// Create a complete user module in minutes
userModule := gonest.NewModule("UserModule").
    Controller(userController).
    Service(userService).
    Build()

app.ModuleRegistry.Register(userModule)

πŸ› οΈ CLI Tool

GoNest includes a powerful CLI tool for project scaffolding and component generation. This is the recommended way for developers to get started with GoNest.

πŸ“₯ Installation & Setup

πŸš€ One-Line Installation (Fastest & Recommended)

Get started in seconds! This installer handles everything automatically.

Linux/macOS:

$ curl -sSL https://raw.githubusercontent.com/ulims/GoNest/master/install-gonest.sh | bash

Windows:

# Download and run the installer
$ curl -o install-gonest.bat https://raw.githubusercontent.com/ulims/GoNest/master/install-gonest.bat && install-gonest.bat

βœ… What happens automatically:

  • CLI tool installed globally
  • All dependencies handled
  • Ready to use immediately

πŸ”§ Alternative Installation Methods

Manual Installation:

# Clone and install manually
$ git clone https://github.com/ulims/GoNest.git
$ cd GoNest
$ go install ./cmd/gonest

# Verify installation
$ gonest --help

Build from Source:

# Clone and build locally
$ git clone https://github.com/ulims/GoNest.git
$ cd GoNest
$ go build -o gonest.exe cmd/gonest/main.go  # Windows
$ go build -o gonest cmd/gonest/main.go       # Linux/macOS

πŸš€ Creating New Projects

# Basic project
$ gonest new my-app

# Navigate to your project
$ cd my-app

# Dependencies are downloaded automatically by the CLI
# But if you encounter issues, manually run:
$ go mod tidy

# Run your application
$ go run cmd/server/main.go

πŸ“‹ Project Templates

# API project with strict mode
$ gonest new my-api --template=api --strict

# Full-stack project
$ gonest new my-webapp --template=fullstack

# Microservice project
$ gonest new my-service --template=microservice

πŸ”§ Generating Components

# Navigate to your GoNest project
$ cd my-app

# Generate a new module
$ gonest generate module user

# Generate a controller
$ gonest generate controller user

# Generate a service
$ gonest generate service user

# Generate DTOs and entities
$ gonest generate dto user
$ gonest generate entity user

πŸ—οΈ Project Management

# Build the application
$ gonest build

# Run the application
$ gonest run

# Run tests
$ gonest test

πŸ“‹ Available Templates

Template Description Use Case
basic Standard GoNest structure General applications
api API-focused with Swagger REST APIs, microservices
fullstack Web app with templates Full-stack applications
microservice gRPC + protobuf Microservice architecture

🎯 Available Commands

Command Description Example
new Create new project gonest new my-app
generate Generate components gonest generate module user
build Build application gonest build
run Run application gonest run
test Run tests gonest test

πŸ”’ Strict Mode

Enable strict mode for enhanced security and validation:

$ gonest new my-app --strict

Strict mode includes:

  • Enhanced input validation
  • Security headers
  • Rate limiting
  • CORS configuration
  • Request logging

Available Templates

  • basic (default): Standard GoNest project structure
  • api: API-focused project with Swagger documentation
  • fullstack: Full-stack application with web templates
  • microservice: Microservice with gRPC and protobuf support

Strict Mode

Enable additional validation and security features with --strict flag.

πŸ”§ Key Components

Modules

type UserModule struct {
    *gonest.Module
}

func NewUserModule(logger *logrus.Logger) *UserModule {
    userService := NewUserService(logger)
    userController := NewUserController(userService)
    
    module := gonest.NewModule("UserModule").
        Controller(userController).
        Service(userService).
        Build()
    
    return &UserModule{Module: module}
}

Services

type UserService struct {
    users  map[string]*User
    logger *logrus.Logger
}

func (s *UserService) CreateUser(username, email, password string) (*User, error) {
    // Business logic implementation
}

Controllers

type UserController struct {
    userService *UserService
}

func (c *UserController) CreateUser(ctx echo.Context) error {
    // HTTP request handling
}

πŸ§ͺ Testing

GoNest provides built-in testing utilities:

func TestUserService(t *testing.T) {
    testApp := gonest.NewTestApp().
        Module(userModule).
        Build()
    
    // Test with real HTTP requests
    response := testApp.Request("POST", "/users").
        WithJSON(map[string]interface{}{
            "username": "testuser",
            "email":    "test@example.com",
        }).
        ExpectStatus(201).
        Get()
    
    assert.NotNil(t, response.JSON())
}

πŸ“ˆ Performance

  • High Throughput: Built on Echo framework for optimal performance
  • Low Memory Usage: Efficient memory management and garbage collection
  • Fast Startup: Minimal initialization overhead
  • Scalable: Support for horizontal and vertical scaling

πŸ”’ Security

  • Input Validation: Comprehensive request validation
  • Authentication: JWT-based authentication system
  • Authorization: Role-based access control
  • Rate Limiting: Built-in rate limiting strategies
  • CORS Support: Configurable cross-origin resource sharing

🌟 Why GoNest?

  • πŸš€ NestJS Familiarity: If you know NestJS, you'll feel at home
  • ⚑ Go Performance: Leverage Go's speed and efficiency
  • πŸ—οΈ Enterprise Ready: Built for production applications
  • πŸ”§ Developer Experience: Excellent tooling and documentation
  • πŸ“š Rich Ecosystem: Comprehensive feature set out of the box
  • πŸ§ͺ Testing First: Built-in testing utilities and patterns
  • ⚑ Quick Setup: Automated project initialization scripts

πŸ› οΈ Troubleshooting

Common Issues

Missing Dependencies Error

missing go.sum entry for module providing package github.com/labstack/echo/v4

Solution:

# Dependencies are downloaded automatically by the CLI
# If you encounter this error, run manually:
cd your-project-directory
go mod tidy

PowerShell Command Issues

The token '&&' is not a valid statement separator

Solution: Use separate commands in PowerShell:

cd my-app
go run cmd/server/main.go

Port Already in Use

bind: address already in use

Solution: Kill the process using port 8080 or change the port in your application.

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Areas for Contribution

  • πŸ› Bug fixes and improvements
  • ✨ New features and enhancements
  • πŸ“š Documentation improvements
  • πŸ§ͺ Test coverage expansion
  • πŸ”§ Performance optimizations

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • NestJS Team: For the excellent architectural inspiration
  • Echo Framework: For the high-performance HTTP foundation
  • Go Community: For the amazing ecosystem and tools

πŸ“ž Support


Build amazing applications with GoNest - The Go framework that brings NestJS elegance to Go! πŸš€

About

GoNest is a powerful, scalable Go framework inspired by NestJS that provides a complete solution for building enterprise-grade applications.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published