Skip to content

🚀 Nika Framework

Nika is a modern backend framework for Go, designed for scalability, clean architecture, and developer productivity.

Release License Go version Stars


Overview

Nika is a progressive Go web framework that helps you build efficient, scalable, and maintainable server-side applications.

Built on top of Gin, Nika leverages Gin's high-performance HTTP routing while adding a layer of organization through Modules, Providers, Controllers, and a powerful DI container.

Features

  • 🏗️ Modular Architecture — Self-contained modules with Imports/Exports to share providers between them
  • 💉 Dependency Injection — Built-in DI container with automatic resolution
  • 🎯 Struct-tag Routing — Define routes directly on controller fields
  • 🔌 Common Packages — Ready-to-use integrations for MongoDB, Redis, Cache, Validation, and Config
  • ⚡ High Performance — Powered by Gin's fast HTTP engine
  • 📦 Generic Repository — Type-safe MongoDB repository with full CRUD operations
  • ✅ Validation — Struct validation with custom rules (e.g., Iranian mobile, ObjectId)

Quick Start

go install github.com/nika-framework/nika-cli@latest

nika-cli new <app-name>

cd <app-name>

nika-cli start --watch
go get github.com/nika-framework/nika
package main

import (
    "fmt"
    "github.com/nika-framework/nika"
)

func main() {
    app := nika.NewApp()

    rootModule := src.NewAppModule()
    app.LoadModule(rootModule)

    port := "3001"
    fmt.Printf("🚀 Nika is running on http://localhost:%s\n", port)
    app.Listen(":" + port)
}

Architecture

Nika follows the Module → Provider → Controller pattern, extended with Imports/Exports for sharing providers between modules:

┌────────────────────────────────────────────────────────────────┐
│                              App                               │
│                                                                │
│  ┌──────────────────────────────────────────────────────────┐  │
│  │  Root Module                                              │  │
│  │                                                          │  │
│  │  ┌───────────────────────────┐   ┌────────────────────┐  │  │
│  │  │  Auth Module              │   │  Users Module      │  │  │
│  │  │                           │   │                    │  │  │
│  │  │  Controllers              │   │  Controllers       │  │  │
│  │  │  Providers                │   │  Providers         │  │  │
│  │  │  Exports ─────────────────┼───►  injects exports   │  │  │
│  │  │                           │   │                    │  │  │
│  │  └───────────────────────────┘   └────────────────────┘  │  │
│  │                                                          │  │
│  └──────────────────────────────────────────────────────────┘  │
│                                                                │
│  ┌──────────────────────────────────────────────────────────┐  │
│  │  DI Container (module-scoped)                            │  │
│  └──────────────────────────────────────────────────────────┘  │
│                                                                │
│  ┌──────────────────────────────────────────────────────────┐  │
│  │  Gin HTTP Engine                                          │  │
│  └──────────────────────────────────────────────────────────┘  │
└────────────────────────────────────────────────────────────────┘

Every module implements the nika.Module interface:

type Module interface {
    Imports()     []Module
    Controllers() []interface{}
    Providers()   []interface{}
    Exports()     []interface{}
}
  • Providers are private by default — imported modules can inject only the providers that this module returns from Exports().
  • Exports() publishes selected providers (or the interfaces their constructors return) so that any module importing this module can inject them.
  • Imports() loads sub-modules recursively and merges their exports into the importing module's container.

An Exports() entry must be declared by the module's Providers() or be available from one of its Imports(); imported providers can be re-exported.

In the diagram above, UsersModule imports AuthModule and injects the providers it exports — everything else inside AuthModule stays private.

Common Packages

Package Description
common/config Environment-based configuration with .env support
common/mongodb MongoDB connection and generic repository pattern
common/cache Cache abstraction with Redis and File drivers
common/validator Struct validation with custom rules
common/response Standardized JSON response helpers

Documentation

Browse the documentation using the sidebar navigation. Start with First Steps to create your first application.

License

MIT © Sajad Mohammadi Nejad