A multi-tenant platform for auto-parts stores and store networks, built with Go, PostgreSQL, Next.js, and Keycloak. The frontend supports Persian and right-to-left workflows.
- Inventory, purchasing, sales, settlements, and returns
- Customer and supplier accounts, operating expenses, and accounting reports
- Cross-store inventory search, reservations, and procurement
- Store dashboards, inventory analytics, and daily closing
- Keycloak authentication with tenant- and store-scoped authorization
Monetary integer values use Iranian toman (IRT application code).
- Local development
- Production operations runbook
- API specifications
- Product documentation
- Operations documentation
The repository also includes phase-specific PHASE_*_RUN.md guides and RELEASE_NOTES_* files. Consult the guide for the component or migration you are working on.
- Go 1.23 API
- PostgreSQL 18.4
- Keycloak 26.7.0
- Next.js 16 + React 19.2 + TypeScript
keycloak-js26.2.4- pgx/v5
- Modular monolith
- Standard
net/http
Keycloak owns authentication, passwords, browser login sessions, password reset, and realm roles.
The Go API does not receive user passwords. It accepts Keycloak access tokens and verifies:
- RS256 signature against Keycloak JWKS
- exact issuer
autoparts-apiaudience- expiration / not-before
tenant_idclaimstore_idclaim- application realm roles
Business authorization remains in Go. Tenant/store IDs are never accepted from a client header as a trusted security context.
owneradmincashierwarehouseaccountantmechanicconsumer
cp .env.example .env
docker compose up --buildServices:
- Web: http://localhost:3000
- API: http://localhost:8080
- Keycloak: http://localhost:8081
- Keycloak Admin Console: http://localhost:8081/admin
- PostgreSQL: localhost:5432
Store application user:
owner@example.com
ChangeMe123!
Keycloak admin console defaults:
admin
admin-change-me
Change the admin password in .env before using the environment beyond local development.
- PostgreSQL starts and applies the existing SQL init migrations on a fresh volume.
db-prepareidempotently creates the dedicatedkeycloakdatabase/user and inserts a small demo store dataset.- Keycloak starts and imports
keycloak/autoparts-realm.jsonif theautopartsrealm does not already exist. - The Go API validates Keycloak bearer tokens. It no longer exposes
/v1/auth/loginor/v1/auth/bootstrap. - The Next.js app uses Authorization Code flow + PKCE through
keycloak-js.
The realm maps these user attributes into access tokens:
tenant_id
store_id
Realm roles are read from:
realm_access.roles
The web client adds the API audience:
autoparts-api
The startup realm import is intentionally convenient for local development. If the autoparts realm already exists, Keycloak skips importing it. If you modify the realm JSON and want a clean re-import during development, either update the realm through the Admin Console or recreate the local Keycloak database/volume intentionally.
Do not delete a production database/volume to apply realm configuration changes.
/login- redirects authentication to Keycloak/store- store dashboard/store/sales- operational sale screen/store/sales/history- paginated sale history, filters and CSV export/store/sales/{id}- printable sale invoice/store/purchases- purchase entry and receiving screen/store/purchases/history- paginated purchase history, filters and CSV export/store/purchases/{id}- printable purchase document/store/inventory- inventory, low-stock, adjustment, and reorder-point screen/store/accounts- customer/supplier balances, settlement, and account statements/store/expenses- operating expense entry/store/reports- store profit/loss reporting/store/audit- owner/admin security and mutation audit log/store/reports/inventory- inventory valuation, low-stock, velocity and dead-stock analysis/store/closing- cash/card report and daily closing/store/returns- sale/purchase returns/store/network- publish stock/prices to the cross-store network/store/procurement- store-to-store network procurement, seller workflow, and receiving/store/orders- incoming mechanic reservations/mechanic- public network search/mechanic/orders- authenticated mechanic/consumer reservation tracking
The old HMAC token/password implementation is still present temporarily under internal/platform/auth so earlier migrations/tests remain understandable, but it is no longer wired into cmd/api. The users and memberships tables are also retained for a later migration/identity-linking decision.
Docker builds use a retrying Go proxy chain and checksum verification. If your network has trouble with the defaults, edit .env:
GO_MODULE_PROXY=https://goproxy.cn|https://proxy.golang.org|direct
GO_SUMDB=sum.golang.google.cn
keycloak/autoparts-realm.jsondev/postgres/prepare.shdev/postgres/seed.sqlinternal/platform/auth/keycloak.goweb/components/auth-provider.tsxweb/lib/keycloak.tsRELEASE_NOTES_PHASE4_3.md
web/app/store/inventory/page.tsxweb/app/store/purchases/page.tsxweb/lib/api.tsweb/lib/mock.tsdocs/product/PHASE_5_ACCEPTANCE.mdRELEASE_NOTES_PHASE5.md
Reservations lock inventory_balances.reserved and therefore reduce public availability immediately. Reservation creation/confirmation is still logistics-only. Phase 9 added atomic fulfillment: a ready reservation becomes a real posted sale exactly once, consuming both on_hand and the held reserved quantity while posting payment/AR, COGS, journals and outbox events in the same transaction.
Operating expenses now post balanced journals automatically. The UI also exposes customer/supplier party-ledger statements and a store-level profit/loss report calculated from posted sales, sales returns, perpetual COGS and operating expenses.
Development mechanic login for a fresh realm:
mechanic@example.com
ChangeMe123!
Phase 11 turns the core transaction engine into a more complete daily store workflow. Sales and purchases now have paginated history APIs and printable document screens, the dashboard reads live backend metrics, inventory reporting exposes value/velocity/dead-stock signals, and cash/card movements can be reconciled into an idempotent daily closing snapshot. Late transactions after a close are not silently hidden: the cash report exposes changed_after_close so the operator can see that the saved snapshot no longer matches current activity. CSV exports are generated client-side from the authorized data already returned by the API.
Stores can now procure inventory directly from other network-enabled stores. Creating a procurement request immediately holds seller inventory; the seller accepts and marks it ready; the buyer then receives it. Receive is a single SERIALIZABLE cross-tenant transaction that posts the seller credit sale/AR/COGS and buyer credit purchase/AP while moving inventory and preserving weighted-average valuation. Network counterpart customer/supplier records are linked automatically, and the procurement stores both document IDs for auditability.
Phase 13 adds vehicle make/model/variant fitment, alternate OEM/equivalent search terms, relevance-ranked network search, and the /store/fitment catalog-maintenance UI. See PHASE_13_RUN.md.
Phase 14 adds liveness/readiness/version endpoints, structured JSON HTTP logging, request IDs, strict CORS and security headers, rate limiting, panic recovery, graceful shutdown and a tenant-scoped audit trail for mutating requests. A separate docker-compose.prod.yml disables demo seeding and dev-user reconciliation, bootstraps only production-safe Keycloak realm/client configuration, binds application ports to loopback for a TLS reverse proxy, and includes deployment preflight plus PostgreSQL backup/restore tooling. See docs/ops/PRODUCTION_RUNBOOK.md.
Phase 15.6 adds a network-value dashboard, action center, safe CSV migration/import flow, and saved-vehicle/recent-search UX for mechanic users. The import flow initializes only untouched opening inventory and preserves balances that already have operational history. See PHASE_15_6_RUN.md.
Store Edge 0.15.8 علاوه بر فروش آفلاین، gateway محلی سختافزار صندوق است: receipt/label/A4 printer، barcode keyboard-wedge، cash drawer و POS provider bridge. Installer تولیدی ویندوز از Phase 15.7.1 حفظ شده و نسخه 0.15.8 را بهصورت Windows Service با auto-start نصب میکند. Pairing-origin fix فاز 15.7.1.1 نیز در این baseline ادغام شده است.
Runbook: PHASE_15_8_RUN.md
Store Edge دیگر مستقیماً بهعنوان process/service قابل توقف اجرا نمیشود. یک Manager محلی روی 127.0.0.1:17623 همیشه فعال میماند و Worker فروش آفلاین/سختافزار روی 127.0.0.1:17624 را Start/Stop/Restart میکند. صفحه /store/edge lifecycle را برای Windows و Linux مدیریت میکند و مسیر بروزرسانی امضاشده SHA-256 + Ed25519 نیز اضافه شده است. Runbook: PHASE_15_8_1_RUN.md.
/store/edge حالا قبل از نصب Manager سیستمعامل/معماری را تشخیص میدهد و Installer رسمی Windows یا Linux را پیشنهاد میکند. Windows x64 با Setup امضاشدنی و Linux Debian/Ubuntu با DEB روی amd64/arm64 پوشش داده میشوند. بعد از تأیید نصب توسط خود سیستمعامل، صفحه بهصورت خودکار Manager را روی loopback پیدا میکند و تمام Start/Stop/Restart/Update از همان UI انجام میشود. Release assets با tagهای store-agent-v* تولید و روی GitHub Release منتشر میشوند. Runbook: PHASE_15_8_1_1_RUN.md.
بخش /store/checks مدیریت واقعی چک و بانک را به هسته حسابداری اضافه میکند: چک دریافتنی/پرداختی، سررسید، واگذاری و وصول، برگشتی، خرجکردن چک برای تأمینکننده و گردش حساب بانکی. ثبت و تغییر وضعیت چکها با party ledger و double-entry journal اتمیک است و تاریخ شمسی مانند ۱۴۰۵/۰۵/۲۷ پذیرفته میشود. Migration: 015_checks_banking.sql. Runbook: PHASE_15_9_RUN.md.