Imported from raihanrizkialfarezaa/rizqi-mart-system (
AGENTS.md). Install upstream withnpx skills add raihanrizkialfarezaa/rizqi-mart-system. Copyright stays with the author.
Rizqi Mart System - Agent Instructions
Guidelines for agents working in this repository.
๐งช Verification & Testing
- Test Database: Testing requires a running local MySQL instance. The test DB is configured via
.env.testasrizqi_mart_test(defined invitest.config.mjs). Do not use SQLite/in-memory. - Verification Command: Run
npm run test:runfor vitest tests. Avoid interactive runners. - Auto-Sync Schema: The test runner automatically syncs the schema using
npx prisma db push --skip-generate --accept-data-loss(via__tests__/setup/vitest.setup.ts). - Database Cleanups: Tables are cleaned
beforeEachtest viacleanDatabase()in__tests__/setup/test-db.tsusing a strict foreign-key-safe order.
๐ฆ TypeScript & Type Quirks
- Factory ID Mismatches: In
__tests__/fixtures/factories.ts, some signatures (e.g.,createTestStockBatch,createTestSalesOrderItem,createTestPurchaseOrder) type parent IDs asnumber(e.g.,productId: number). However, all IDs inschema.prismaareString(CUID). Cast these inputs (e.g.,productId as any) to bypass compiler errors. - Decimal Types: Financial and quantity values are mapped to Prisma's
Decimaltype. Wrap values innew Decimal(...)(imported fromdecimal.js) or use helpers inlib/utils/decimal.ts. - SalesOrder Relations: The type
SalesOrderWithItemsreturned bygetSalesOrderByIddoes not statically exposestatusHistory,deliveryNote,invoice, orpaymentsin its TypeScript declaration, even though they are fetched at runtime. Use type casts or local interfaces when accessing them.
๐ Authentication
- Local Dev Auth: Production uses Clerk, but local dev/testing uses a custom JWT session-based mock provider (see
lib/auth/session.tsandlib/auth/AuthProvider.tsx). - Login Credentials: The local test login accepts any email present in the database and any password.
๐ Critical Business Rules
- No Prices on Delivery Notes (Surat Jalan): Delivery notes must never expose item prices. Only the
Invoicecontains prices. - EFO Stock Allocation: Stocks are allocated using Expiry-First-Out (EFO) based on
StockBatch.expiryDate, falling back to FIFO. - Payment Validation: Payments via CASH are immediately marked
LUNAS. Transfer/QRIS payments under Rp 500,000 require manual validation, whereas payments >= Rp 500,000 are markedLUNASonce proof is provided.