Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs-mstore.faisalaffan.com/llms.txt

Use this file to discover all available pages before exploring further.

Technology Stack

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

🎯 Core Stack

Web Framework

GoFiber v2.52

Fast HTTP framework built on Fasthttp
  • Express-like API
  • Zero memory allocation router
  • Built-in middleware support

Fasthttp v1.65

High-performance HTTP engine
  • 10x faster than net/http
  • Zero-allocation design
  • Connection pooling
Usage:
import "github.com/gofiber/fiber/v2"

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

Database

GORM v1.30

ORM library untuk Go
  • Auto migrations
  • Associations & preloading
  • Hooks & callbacks
  • Soft deletes

MySQL Driver v1.8

Official MySQL driver
  • Connection pooling
  • Prepared statements
  • Transaction support
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{})

MongoDB Driver v1.17

Official MongoDB driver
  • BSON support
  • Aggregation pipeline
  • Change streams

Redis v9.7

Redis client untuk Go
  • Pipelining
  • Pub/Sub
  • Cluster support

Authentication & Security

JWT v5.2

JSON Web Token implementation
  • HS256, RS256 support
  • Claims validation
  • Token refresh

Crypto

Go cryptography library
  • bcrypt password hashing
  • AES encryption
  • TLS support
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

Resty v2.16

HTTP client untuk API calls
  • Automatic retry
  • Request/response middleware
  • Debug logging
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

NATS v1.44

Cloud-native messaging
  • Pub/Sub
  • Request/Reply
  • Queue groups

RabbitMQ v1.10

Message queue broker
  • AMQP 0.9.1
  • Reliable delivery
  • Dead letter queues

Kafka v0.4

Event streaming platform
  • High throughput
  • Partitioning
  • Consumer groups
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

MQTT v1.5

MQTT client untuk IoT
  • QoS levels
  • Retained messages
  • Last will & testament

WebSocket v1.3

WebSocket support untuk Fiber
  • Real-time bidirectional
  • Connection pooling
  • Auto reconnect
Use Cases:
  • MQTT: QRIS payment notification real-time
  • WebSocket: Live order updates, stock alerts

πŸ” Observability (LGTM Stack)

Logging

Zap v1.27

Structured logging
  • Zero-allocation
  • JSON output
  • Log levels

ECS Zap v1.0

Elastic Common Schema
  • Standardized format
  • Loki integration
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

OpenTelemetry v1.34

Distributed tracing
  • Span creation
  • Context propagation
  • Trace sampling

Jaeger Client v2.30

Jaeger tracing client
  • Trace visualization
  • Service dependencies
  • Performance analysis
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

OpenTelemetry Metrics v1.34

Metrics collection & export
  • Counter, Gauge, Histogram
  • OTLP export to Mimir
  • Custom 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

Swaggo v1.16

Swagger documentation
  • Auto-generate from comments
  • OpenAPI 3.0 support

Validator v10.23

Struct validation
  • Tag-based rules
  • Custom validators

Testify v1.10

Testing toolkit
  • Assertions
  • Mocking
  • Test suites
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

Godog v0.15

BDD testing framework
  • Gherkin syntax
  • Feature files
  • Step definitions

Pact v2.4

Contract testing
  • Consumer-driven contracts
  • Provider verification
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

Cobra v1.9

CLI framework
  • Commands & subcommands
  • Flags & arguments

Godotenv v1.5

Environment variables
  • .env file loading

Env v6.10

Struct-based config
  • Tag-based parsing
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

Excelize v2.9

Excel file processing
  • Read/Write XLSX
  • Formulas & styles

UUID v1.6

UUID generation
  • v4 random UUIDs

QR Code v2.2

QR code generation
  • PNG/JPEG output
  • Custom styling
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

go-i18n v2.4

Internationalization support
  • Message translation
  • Pluralization
  • Locale detection
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

Firebase Admin v3.13

Firebase Admin SDK
  • Firestore
  • Authentication
  • Cloud Messaging

AWS SDK v1.55

AWS SDK untuk Go
  • S3 storage
  • SQS queues
  • SNS notifications

πŸ“Š GraphQL

gqlgen v0.17

GraphQL server library
  • Schema-first approach
  • Code generation
  • Subscriptions support
Usage:
type Query {
  transaction(id: ID!): Transaction
  transactions(filter: TransactionFilter): [Transaction!]!
}

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

🎨 Expression & Rules Engine

Expr v1.17

Expression language
  • Dynamic rule evaluation
  • Type-safe expressions
  • Custom functions
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