Skip to main content

Technology Stack

Dokumentasi lengkap library, framework, dan tools yang digunakan di MStore Backend Go.

🎯 Core Stack

Web Framework

Usage:
import "github.com/gofiber/fiber/v2"

app := fiber.New(fiber.Config{
    Prefork:       false,
    CaseSensitive: true,
    StrictRouting: true,
    ServerHeader:  "MStore-Backend",
})

Database

Usage:
import (
    "gorm.io/gorm"
    "gorm.io/driver/mysql"
)

dsn := "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})

Authentication & Security

Usage:
import "github.com/golang-jwt/jwt/v5"

token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
    "user_id": 123,
    "exp":     time.Now().Add(24 * time.Hour).Unix(),
})

tokenString, err := token.SignedString([]byte(secretKey))

πŸ“‘ External Integrations

Payment Gateway

Providers:
  • Xendit: QRIS, E-Wallet, VA, Credit Card
  • Midtrans: Snap API, Core API
Usage:
import "github.com/go-resty/resty/v2"

client := resty.New()
resp, err := client.R().
    SetBasicAuth(apiKey, "").
    SetHeader("Content-Type", "application/json").
    SetBody(payload).
    Post("https://api.xendit.co/qr_codes")

Message Broker

Usage (NATS):
import "github.com/nats-io/nats.go"

nc, err := nats.Connect("nats://localhost:4222")
defer nc.Close()

// Publish
nc.Publish("transaction.created", []byte(payload))

// Subscribe
nc.Subscribe("transaction.created", func(m *nats.Msg) {
    // Handle message
})

IoT & Real-time

Use Cases:
  • MQTT: QRIS payment notification real-time
  • WebSocket: Live order updates, stock alerts

πŸ” Observability (LGTM Stack)

Logging

Usage:
import "go.uber.org/zap"

logger, _ := zap.NewProduction()
defer logger.Sync()

logger.Info("transaction created",
    zap.String("transaction_code", code),
    zap.Int64("amount", 50000),
)

Tracing

Usage:
import (
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/trace"
)

tracer := otel.Tracer("mstore-backend")
ctx, span := tracer.Start(ctx, "CreateTransaction")
defer span.End()

span.SetAttributes(
    attribute.String("transaction.code", code),
    attribute.Int64("transaction.amount", amount),
)

Metrics

Usage:
meter := otel.Meter("mstore-backend")
counter, _ := meter.Int64Counter("transactions.created")

counter.Add(ctx, 1, 
    metric.WithAttributes(
        attribute.String("branch", branchCode),
        attribute.String("payment_method", "CASH"),
    ),
)

πŸ› οΈ Development Tools

Code Quality

Usage (Validator):
import "github.com/go-playground/validator/v10"

type CreateTransactionRequest struct {
    BranchCode string  `json:"branch_code" validate:"required"`
    Amount     float64 `json:"amount" validate:"required,gt=0"`
}

validate := validator.New()
err := validate.Struct(req)

Testing

Usage (Godog):
Feature: Transaction Creation
  Scenario: Create CASH transaction
    Given I am authenticated as cashier
    When I create a transaction with amount 50000
    Then transaction should be created successfully
    And status should be "draft"

CLI & Configuration

Usage (Cobra):
import "github.com/spf13/cobra"

var rootCmd = &cobra.Command{
    Use:   "mstore",
    Short: "MStore Backend CLI",
}

var serverCmd = &cobra.Command{
    Use:   "server",
    Short: "Start HTTP server",
    Run: func(cmd *cobra.Command, args []string) {
        // Start server
    },
}

rootCmd.AddCommand(serverCmd)
rootCmd.Execute()

πŸ“¦ Utilities

Data Processing

Usage (Excelize):
import "github.com/xuri/excelize/v2"

f := excelize.NewFile()
f.SetCellValue("Sheet1", "A1", "Product Name")
f.SetCellValue("Sheet1", "B1", "Price")
f.SaveAs("products.xlsx")

Internationalization

Usage:
import "github.com/nicksnyder/go-i18n/v2/i18n"

bundle := i18n.NewBundle(language.English)
bundle.RegisterUnmarshalFunc("json", json.Unmarshal)
bundle.LoadMessageFile("locale/en.json")

localizer := i18n.NewLocalizer(bundle, "id")
msg := localizer.MustLocalize(&i18n.LocalizeConfig{
    MessageID: "transaction.created",
})

πŸ”₯ Firebase & Cloud


πŸ“Š GraphQL

Usage:
type Query {
  transaction(id: ID!): Transaction
  transactions(filter: TransactionFilter): [Transaction!]!
}

type Transaction {
  id: ID!
  transactionCode: String!
  amount: Float!
  status: TransactionStatus!
}

🎨 Expression & Rules Engine

Usage:
import "github.com/expr-lang/expr"

// Dynamic discount rule
code := `amount > 100000 ? amount * 0.1 : 0`
program, _ := expr.Compile(code)

env := map[string]interface{}{
    "amount": 150000,
}
discount, _ := expr.Run(program, env)

πŸ“ˆ Version Matrix

CategoryLibraryVersionStatus
FrameworkGoFiberv2.52.9βœ… Stable
DatabaseGORMv1.30.0βœ… Stable
DatabaseMongoDB Driverv1.17.1βœ… Stable
CacheRedisv9.7.0βœ… Stable
AuthJWTv5.2.1βœ… Stable
HTTP ClientRestyv2.16.5βœ… Stable
Message BrokerNATSv1.44.0βœ… Stable
Message BrokerRabbitMQv1.10.0βœ… Stable
Message BrokerKafkav0.4.47βœ… Stable
IoTMQTTv1.5.0βœ… Stable
LoggingZapv1.27.0βœ… Stable
TracingOpenTelemetryv1.34.0βœ… Stable
ValidationValidatorv10.23.0βœ… Stable
TestingTestifyv1.10.0βœ… Stable
TestingGodogv0.15.0βœ… Stable
CLICobrav1.9.1βœ… Stable
ExcelExcelizev2.9.1βœ… Stable
GraphQLgqlgenv0.17.56βœ… Stable
FirebaseFirebase Adminv3.13.0βœ… Stable
AWSAWS SDKv1.55.5βœ… Stable

πŸš€ Performance Characteristics

Benchmarks

OperationThroughputLatency (P95)
HTTP Request (Fiber)100k req/s< 10ms
Database Query (GORM)10k qps< 5ms
Redis Get100k ops/s< 1ms
NATS Publish1M msg/s< 0.5ms
JSON Marshal1M ops/s< 1Β΅s

πŸ’‘ Best Practices

DO βœ…

  • Use connection pooling untuk database & Redis
  • Implement circuit breaker untuk external APIs
  • Use context timeout untuk semua operations
  • Enable OpenTelemetry instrumentation
  • Use structured logging (Zap)
  • Implement graceful shutdown
  • Use dependency injection

DON’T ❌

  • Jangan hardcode credentials
  • Jangan skip error handling
  • Jangan block goroutines indefinitely
  • Jangan ignore context cancellation
  • Jangan log sensitive data
  • Jangan skip input validation

Service Template

Template service dengan best practices

API Styleguide

Panduan API design & conventions

Testing Guide

Unit, integration, dan E2E testing

Observability

LGTM stack setup & monitoring

Need Help? Contact backend team atau check GitHub Issues