Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
2593d1e
refactor: rename HTTP handler files from dashes to snake_case :hammer:
ClaraTersi Apr 8, 2026
d5376f4
refactor: move CreateTransactionJSON to transaction.go :hammer:
ClaraTersi Apr 8, 2026
4a5eca8
refactor: move transaction input types from postgres adapter to pkg/t…
ClaraTersi Apr 8, 2026
40c6dd2
docs: regenerate swagger specs after input type relocation :books:
ClaraTersi Apr 8, 2026
fc27e26
fix: use value types for required Send fields in transaction inputs :…
ClaraTersi Apr 8, 2026
2502e86
refactor: move transaction status derivation to Transaction.InitialSt…
ClaraTersi Apr 8, 2026
7ed0544
refactor: move CreateTransactionAnnotation to transaction.go :hammer:
ClaraTersi Apr 8, 2026
73bd1ba
refactor: move CreateTransactionInflow to transaction.go :hammer:
ClaraTersi Apr 8, 2026
56ea5d3
refactor: move CreateTransactionOutflow to transaction.go :hammer:
ClaraTersi Apr 8, 2026
f2588d1
refactor: move CreateTransactionDSL to transaction.go, delete empty f…
ClaraTersi Apr 8, 2026
b1b694c
refactor: remove dead CreateTransaction use case and tests :hammer:
ClaraTersi Apr 8, 2026
e860b58
refactor: rename transaction_creation_helpers to transaction_create :…
ClaraTersi Apr 8, 2026
6ca8c4a
refactor: move GetTransaction to transaction.go :hammer:
ClaraTersi Apr 8, 2026
1ebf2ba
refactor: rename transactionScope to transactionPathParams :hammer:
ClaraTersi Apr 8, 2026
1bf0b42
refactor: rename scope to params for path parameters :hammer:
ClaraTersi Apr 8, 2026
de0c25c
refactor: inline generateTransactionID with structured logging :hammer:
ClaraTersi Apr 8, 2026
89a2a3c
fix: rename duplicate span to handler.create_transaction.orchestrate …
ClaraTersi Apr 8, 2026
7b8db0d
refactor: move checkTransactionDate to transaction_helper.go :hammer:
ClaraTersi Apr 8, 2026
e13eebb
fix: remove double-logged error in checkTransactionDate caller :bug:
ClaraTersi Apr 8, 2026
36554f0
fix: use constant.EntityTransaction and structured log for value vali…
ClaraTersi Apr 8, 2026
65d34b9
refactor: move ApplyDefaultBalanceKeys to transaction_helper.go as fr…
ClaraTersi Apr 8, 2026
5453eb6
refactor: move handleAccountFields to transaction_helper.go :hammer:
ClaraTersi Apr 8, 2026
7a1671c
refactor: split handleAccountFields into concatAccountAliases and spl…
ClaraTersi Apr 8, 2026
433e3c9
fix: stop mutating input slice in concat/splitAccountAliases :bug:
ClaraTersi Apr 8, 2026
00a1ef8
refactor: move alias helpers to pkg/transaction with idempotent Mutat…
ClaraTersi Apr 8, 2026
0838b35
fix: copy Amount value before taking pointer to avoid aliasing into t…
ClaraTersi Apr 9, 2026
21a3619
fix: ensure correct transaction status handling by using a shallow co…
ClaraTersi Apr 9, 2026
6625ec0
fix: remove debug log lines and unused tenantID fetch from CreateWrit…
ClaraTersi Apr 9, 2026
a203f2d
refactor: rename parserDSL parameter to transactionInput in CreateWri…
ClaraTersi Apr 9, 2026
d9e046d
perf: pre-allocate strings.Builder capacity in all Redis key function…
ClaraTersi Apr 9, 2026
608b329
refactor: move unexported helpers below exported interface in consume…
ClaraTersi Apr 9, 2026
2286211
refactor: remove mock-interaction unit tests from Redis repository an…
ClaraTersi Apr 9, 2026
03b7237
refactor: move checkTransactionDate to pkg/transaction/validations.go…
ClaraTersi Apr 9, 2026
bc3be77
refactor: move idempotency deserialization into CreateOrCheckIdempote…
ClaraTersi Apr 9, 2026
0dc8678
fix: replace fmt.Sprintf with structured log field in ValidateSendSou…
ClaraTersi Apr 9, 2026
a11f3a0
refactor: error handling in balance validation tests and improve erro…
ClaraTersi Apr 9, 2026
f2ac774
fix: return error from GetParsedLedgerSettings instead of silently fa…
ClaraTersi Apr 9, 2026
d0ea6bb
refactor: rename MergeSettingsWithDefaults to FillDefaultSettings and…
ClaraTersi Apr 9, 2026
2bd5e09
fix: return typed LedgerSettings struct from GET/PATCH settings handl…
ClaraTersi Apr 9, 2026
3ca44c2
fix: remove unnecessary ParseLedgerSettings call used only for debug …
ClaraTersi Apr 9, 2026
5ebc998
refactor: simplify propagateRouteValidation by deriving isPending fro…
ClaraTersi Apr 9, 2026
1a05044
refactor: move PropagateRouteValidation from handler to pkg/transacti…
ClaraTersi Apr 9, 2026
ff4d07e
refactor: move StatusToAction from handler to pkg/transaction :hammer:
ClaraTersi Apr 9, 2026
25f96c1
refactor: split createTransaction into createTransaction and createRe…
ClaraTersi Apr 9, 2026
fb6af1c
refactor: transaction backup cache handling by removing redundant sen…
ClaraTersi Apr 9, 2026
3d7fab4
fix: structured logging in error path :bug:
ClaraTersi Apr 9, 2026
0a34fe7
refactor: split GetBalances into pure read (GetBalances) and mutation…
ClaraTersi Apr 9, 2026
c3f3e6b
fix: accept pending transactions when destination route has commit bu…
ClaraTersi Apr 9, 2026
6cbc5cd
chore: update Go toolchain to 1.26.2 and upgrade dependencies :wrench:
ClaraTersi Apr 9, 2026
870434f
fix: add Host header to TestMidazErrorMapper requests for Go 1.26.2 c…
ClaraTersi Apr 9, 2026
e845b48
fix: resolve lint errors (dogsled, unused) and add nolint directives …
ClaraTersi Apr 9, 2026
2df2f95
fix: skip destination route count validation and account rules for ho…
ClaraTersi Apr 9, 2026
fbbace3
refactor: rename remainingAliases to uncachedAliases for clarity :ham…
ClaraTersi Apr 9, 2026
046ee4e
refactor: improve getBalancesFromCache with pre-alloc, observability …
ClaraTersi Apr 9, 2026
9626a1a
perf: move empty input check before getDB in ListByAliasesWithKeys :r…
ClaraTersi Apr 9, 2026
03db4d4
refactor: use structured logging in ListByAliasesWithKeys getDB error…
ClaraTersi Apr 9, 2026
702b278
refactor: fix alias#key parsing, dedup error and use structured loggi…
ClaraTersi Apr 9, 2026
79184c0
fix: end query span explicitly on both success and error paths :bug:
ClaraTersi Apr 9, 2026
d62a845
refactor: convert balance Create to Squirrel with RETURNING and retur…
ClaraTersi Apr 9, 2026
a1cf298
fix: skip direction validation for cancel reversal operations on sour…
ClaraTersi Apr 9, 2026
23899de
refactor: use structured logging in ListByAliasesWithKeys rows iterat…
ClaraTersi Apr 9, 2026
99cf957
refactor: move buildBalanceOperations to transaction handler helper :…
ClaraTersi Apr 10, 2026
7ee0646
fix: read LOG_LEVEL from env instead of hardcoded info in main.go :bug:
ClaraTersi Apr 10, 2026
6c7ad99
refactor: update buildBalanceOperations to accept context for improve…
ClaraTersi Apr 10, 2026
9815180
refactor: break ValidateAccountingRules into focused methods, validat…
ClaraTersi Apr 10, 2026
8b4d662
fix: use ledger settings validateAccountType flag instead of env var …
ClaraTersi Apr 10, 2026
d491259
refactor: enhance ValidateAccountingRules documentation and improve e…
ClaraTersi Apr 10, 2026
5930a79
docs: fix stale godoc referencing removed validateAccountType gate :b…
ClaraTersi Apr 10, 2026
e1b8bfe
refactor: introduce input struct for improved readability and maintai…
ClaraTersi Apr 10, 2026
6764ebc
refactor: add OTel attributes and structured logging to ProcessBalanc…
ClaraTersi Apr 10, 2026
3bc3b01
refactor: extract logger/tracer from context in ProcessBalanceAtomicO…
ClaraTersi Apr 10, 2026
993dbda
refactor: document Lua ARGV mapping and error string matching in Proc…
ClaraTersi Apr 10, 2026
43382af
refactor: remove always-enabled balanceSyncScheduleFlag from Lua scri…
ClaraTersi Apr 10, 2026
2d6882c
refactor: replace double marshal/unmarshal with json.RawMessage in ba…
ClaraTersi Apr 10, 2026
135963a
refactor: ensure balance cloning in atomic operations to prevent data…
ClaraTersi Apr 10, 2026
87b4e29
refactor: replace all fmt.Sprintf logs with structured fields in Redi…
ClaraTersi Apr 10, 2026
1fe6386
fix: address code review findings across transaction flow (lock leak,…
ClaraTersi Apr 10, 2026
ef09ca3
docs: expand AccountingEntry description with conditional credit/debi…
ClaraTersi Apr 10, 2026
1b4913d
refactor: rename pkg/transaction to pkg/mtransaction and fix swagger …
ClaraTersi Apr 11, 2026
d914c46
docs: fix AccountingEntry description to match validator (destination…
ClaraTersi Apr 11, 2026
009e800
refactor: replace remaining fmt.Sprintf logs with structured fields i…
ClaraTersi Apr 11, 2026
7433eea
fix: use defer for child spans and preserve parent context in balance…
ClaraTersi Apr 11, 2026
5aa9aab
fix: classify DB error as infrastructure error in GetBalances span :bug:
ClaraTersi Apr 11, 2026
3195bc9
style: fix import ordering in mtransaction/input.go :gem:
ClaraTersi Apr 11, 2026
306d3df
docs: add format:uuid tag to FromTo.RouteID and Transaction.RouteID :…
ClaraTersi Apr 11, 2026
ff06343
docs: remove incorrect swagger:type object from Metadata fields and c…
ClaraTersi Apr 11, 2026
2e52778
docs: hide internal Amount fields from swagger with swaggerignore :bo…
ClaraTersi Apr 11, 2026
a5fc060
fix: fail-fast on idempotency hash serialization failure instead of u…
ClaraTersi Apr 11, 2026
d20aa17
fix: clean up Redis backup queue entry on GetBalances failure :bug:
ClaraTersi Apr 11, 2026
6cda1d3
fix: downgrade accounting rule validation log from Error to Warn :bug:
ClaraTersi Apr 11, 2026
8481060
fix: preserve original WriteTransaction error for telemetry, return s…
ClaraTersi Apr 11, 2026
f0921df
style: fix import ordering in transaction_helper.go :gem:
ClaraTersi Apr 11, 2026
aa24b96
fix: add missing deleteLockOnError on BuildOperations failure path in…
ClaraTersi Apr 11, 2026
8f95914
style: fix import ordering in validate_accounting_routes.go :gem:
ClaraTersi Apr 11, 2026
3a2f002
style: fix import ordering in input_test.go :gem:
ClaraTersi Apr 11, 2026
b407300
fix: check GOPATH/bin for dev tools and warn when not in PATH :bug:
ClaraTersi Apr 11, 2026
cb59079
docs: promote sensitive data logging rule above log level table :books:
ClaraTersi Apr 11, 2026
90fb9c4
fix: remove swagger type directives from field comments to prevent le…
ClaraTersi Apr 11, 2026
6e6772e
fix: align ProcessBalanceOperations log level with span classificatio…
ClaraTersi Apr 11, 2026
0537179
style: fix import ordering in transaction.go :gem:
ClaraTersi Apr 11, 2026
b55a081
docs: correct MutateConcatAliases/MutateSplitAliases godoc to reflect…
ClaraTersi Apr 11, 2026
cda9dd4
fix: always release idempotency key on SendTransactionToRedisQueue fa…
ClaraTersi Apr 11, 2026
69856d9
docs: explain why idempotency key and backup queue are preserved afte…
ClaraTersi Apr 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ Full rules in `docs/PROJECT_RULES.md` (1130 lines). Key points:
14. **Query builder**: Use `squirrel` for all SQL query construction (SELECT, INSERT, UPDATE). Do not use raw SQL string concatenation with `strconv.Itoa` for parameter placeholders.
15. **Entity name constants**: Use `constant.Entity*` instead of `reflect.TypeOf(mmodel.Foo{}).Name()`. See `pkg/constant/entity.go`.
16. **Timestamps on create**: Capture `time.Now()` once and reuse for both `CreatedAt` and `UpdatedAt` to guarantee identical values.
17. **Declaration order**: Within a file, declare in this order: exported interface → exported types → constructor → exported methods → unexported helpers. The interface is the contract readers look for first.
18. **Repository tests**: Repository/adapter code (thin wrappers around Redis, Postgres, etc.) should be covered by integration tests with testcontainers, not unit tests. Unit-testing mock interactions only verifies you called the mock correctly — it does not catch real issues like key format mismatches, TTL semantics, or Lua script behavior. Unit tests in adapter packages should be reserved for pure functions and business logic branches that don't require external dependencies.

## Observability Conventions

Expand All @@ -597,6 +599,33 @@ logger.Log(ctx, libLog.LevelInfo, "Organization created", libLog.String("id", or
logger.Log(ctx, libLog.LevelError, fmt.Sprintf("Failed to create organization: %v", err))
```

### Log Level Guidelines

**Never log sensitive data (balances, financial values, PII) at any log level.**

Use the correct log level based on **who caused the problem**, not just what went wrong:

| Level | When to use | Example |
|-------|------------|---------|
| **Debug** | Operational details useful only during development or troubleshooting. | Cache key written, Lua script completed, batch stats |
| **Info** | Significant state changes or milestones in a business flow. Should be sparse enough to read in production without filtering. | Transaction created, balance sync flushed, idempotency key claimed |
Comment thread
ClaraTersi marked this conversation as resolved.
| **Warn** | **Business validation failures** (the caller sent invalid data, not a system fault). The system is healthy; the request was rejected. Also used for degraded-but-recoverable situations (e.g., cache connection error with DB fallback). Note: a normal cache miss (TTL expiry) is not a warning — it is the expected flow and needs no log at all. | Insufficient funds, asset mismatch, account sending disabled, accounting rule violation, Redis connection error with DB fallback |
| **Error** | **Infrastructure or system failures** that indicate something is broken and may need operator attention. The system could not fulfill a valid request. | Redis connection refused, DB query failed, Lua script execution error, message broker unavailable |

Key principle: if the fix requires the **caller** to change their request → **Warn**. If the fix requires an **operator** to investigate the system → **Error**.

```go
// Business validation failure — Warn (caller's problem)
logger.Log(ctx, libLog.LevelWarn, "Balance rule validation failed", libLog.Err(err))

// Infrastructure failure — Error (system's problem)
logger.Log(ctx, libLog.LevelError, "Failed to execute atomic balance operation", libLog.Err(err))

// Operational detail — Debug (development only)
logger.Log(ctx, libLog.LevelDebug, "Lua script executed successfully",
libLog.String("backup_queue", prefixedKeys[0]))
```

Comment thread
ClaraTersi marked this conversation as resolved.
### Span Lifecycle
- Always use `defer span.End()` immediately after `tracer.Start`.
- Child spans for I/O operations (DB exec, external calls) should use `defer` and must not
Expand Down
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,29 @@ generate-docs:
dev-setup:
$(call print_title,"Setting up development environment for all components")
@echo "Installing development tools..."
@command -v gitleaks >/dev/null 2>&1 || (echo "Installing gitleaks..." && go install github.com/zricethezav/gitleaks/v8@latest) || echo "⚠️ Failed to install gitleaks"
@command -v gofumpt >/dev/null 2>&1 || (echo "Installing gofumpt..." && go install mvdan.cc/gofumpt@latest) || echo "⚠️ Failed to install gofumpt"
@command -v goimports >/dev/null 2>&1 || (echo "Installing goimports..." && go install golang.org/x/tools/cmd/goimports@latest) || echo "⚠️ Failed to install goimports"
@command -v gosec >/dev/null 2>&1 || (echo "Installing gosec..." && go install github.com/securego/gosec/v2/cmd/gosec@latest) || echo "⚠️ Failed to install gosec"
@command -v golangci-lint >/dev/null 2>&1 || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)) || echo "⚠️ Failed to install golangci-lint"
@GOBIN="$$(go env GOPATH)/bin"; \
check_or_install() { \
local name="$$1" pkg="$$2"; \
if command -v "$$name" >/dev/null 2>&1 || [ -x "$$GOBIN/$$name" ]; then \
echo " ✓ $$name already installed"; \
else \
echo " ⏳ Installing $$name..."; \
go install "$$pkg" || echo " ⚠️ Failed to install $$name"; \
fi; \
}; \
check_or_install gitleaks github.com/zricethezav/gitleaks/v8@latest; \
check_or_install gofumpt mvdan.cc/gofumpt@latest; \
check_or_install goimports golang.org/x/tools/cmd/goimports@latest; \
check_or_install gosec github.com/securego/gosec/v2/cmd/gosec@latest; \
check_or_install golangci-lint github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
Comment thread
ClaraTersi marked this conversation as resolved.
@GOBIN="$$(go env GOPATH)/bin"; \
if ! echo "$$PATH" | tr ':' '\n' | grep -qx "$$GOBIN"; then \
echo ""; \
echo " ⚠️ $$GOBIN is not in your PATH."; \
echo " Add to your shell profile: export PATH=\"\$$PATH:$$GOBIN\""; \
echo " Without this, git hooks (gofumpt, goimports) will be silently skipped."; \
echo ""; \
fi
@echo "Setting up git hooks..."
@$(MAKE) setup-git-hooks
@for dir in $(COMPONENTS); do \
Expand Down
2 changes: 1 addition & 1 deletion components/crm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1.4
# ci: force rebuild crm image - 2026-04-01

FROM --platform=$BUILDPLATFORM golang:1.25.8-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.2-alpine AS builder

WORKDIR /crm-app

Expand Down
3 changes: 0 additions & 3 deletions components/ledger/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ MULTI_TENANT_ENABLED=false
# MULTI_TENANT_REDIS_PASSWORD=
# MULTI_TENANT_REDIS_TLS=false

# ACCOUNTING CONFIG
ACCOUNT_TYPE_VALIDATION=

# DB POSTGRESQL PRIMARY - Onboarding
DB_ONBOARDING_HOST=midaz-postgres-primary
DB_ONBOARDING_USER=midaz
Expand Down
2 changes: 1 addition & 1 deletion components/ledger/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.25.8-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.2-alpine AS builder
# Force rebuild for develop branch - 2026-04-03 (5)

WORKDIR /ledger-app
Expand Down
Loading
Loading