Skip to content

Core Package

@nx/corethư viện nền tảng của monorepo BANA. Nó không phải microservice — nó không ship runtime riêng. Mọi backend package khác import và mở rộng nó, nên core phải được build trước.

Đây là một thẻ định danh nhẹ. Core hợp lệ đi chệch khỏi template service 8-file chuẩn — cấu trúc trưởng thành của nó (architecture, components/*, configuration/*, database/*, utilities/*) được ghi trong các sub-page liên kết bên dưới.

Thẻ định danh

Thuộc tínhGiá trị
Package@nx/core
TypeThư viện dùng chung / mở rộng framework (không runtime độc lập)
Snowflake worker ID0 (dành cho core)
FrameworkIGNIS (@venizia/ignis, @venizia/ignis-helpers)
RuntimeBun
ORMDrizzle ORM + node-postgres (PostgreSQL)
Buildbun run rebuild (clean + tsc + tsc-alias) — không bao giờ tsc thô
Sourcepackages/core/src/

Core cung cấp gì

Khả năngLà gìNằm ở
Lớp application cơ sởBaseApplication (middleware dùng chung), IssuerApplication (JWKS issuer, ES256 — Identity), VerifierApplication (JWKS verifier — mọi service khác), DefaultApplication (JWT đối xứng legacy)src/application/
Helper bootstrapbootstrapApplication(), bootstrapMigration(), createAppConfig(), createMigrationProcessLoader()src/helpers/bootstraps/, src/common/app-config.ts
Drizzle schema tập trungNhà duy nhất cho mọi schema trong monorepo — <domain>/<entity>/{schema.ts, model.ts, constants.ts, index.ts} qua 14 domainsrc/models/schemas/<domain>/<entity>/
Định nghĩa cột dùng chunggenerateCommonColumnDefs() (id, timestamps, soft-delete, metadata jsonb), isoTimestamp(), helper cột i18nsrc/models/schemas/common/
RepositoriesMột mỗi entity, gom theo domain; extend SoftDeletableRepository hoặc ArchivedRepositorysrc/repositories/<domain>/
Lớp repository cơ sởSoftDeletableRepository (re-export từ @venizia/ignis), ArchivedRepository (vòng đời archive theo status)src/base/repository/
Lớp service cơ sởBaseSocketEventService (emit WebSocket qua Signal), MerchantScopedService (CRUD phạm vi merchant)src/base/service/
Snowflake IdGeneratorSingleton bọc IGNIS SnowflakeUidHelpersrc/utilities/id-generator.utility.ts
Hợp đồng topic Kafka / CDCKafkaTopics (tên sự kiện domain + prefixer build()), CDCKafkaTopics (Debezium), CdcTablessrc/common/kafka/, src/common/cdc/
Event busInterface IEventBus + adapter Redis Pub/Sub; định nghĩa sự kiện có kiểusrc/helpers/event-bus/, src/common/events/
RedisRedisConnectionFactory (single / cluster)src/helpers/redis/
Tiện ích dùng chungCryptoUtility, dayjs (cấu hình timezone), useRequestContext(), helper merchant-access + postgres + transform + slugsrc/utilities/
Constants & typesStatuses (IGNIS, tái dùng — không enum tuỳ chỉnh), PostgresSchemas, FixedUserRoles, validations, decorator dùng chungsrc/common/

Đường nối xuyên package

Kafka/CDC là đường nối giao tiếp xuyên package chủ đạo — không phải một hệ thống queue BullMQ.

Cơ chếMục đích
KafkaTopicsTên topic sự kiện domain (vd PAYMENT_SUCCESS, INVENTORY_ISSUED_FOR_SALE, LEDGER_GENERATE), với build({ paths }) prefix nx.seller
CDCKafkaTopicsTopic CDC Debezium dựng từ CdcTables (vd MERCHANT, PRODUCT, SALE_ORDER)
Event bus (IEventBus)Trừu tượng pub/sub in-process với adapter Redis Pub/Sub
RedisQuản lý kết nối dùng chung cho caching và pub/sub

Ai phụ thuộc Core

Mọi backend package phụ thuộc @nx/core và kết nối tới cùng database qua PostgresCoreDataSource được re-export.

PackageApplication baseVai trò
@nx/identityIssuerApplicationJWT issuer (JWKS, ES256); auth, RBAC, users
@nx/commerceVerifierApplicationProducts, pricing, merchants, organizers
@nx/saleVerifierApplicationSale orders, checkout
@nx/financeVerifierApplicationIncome/expense, wallets
@nx/paymentVerifierApplicationĐiều phối payment, webhooks
@nx/inventoryVerifierApplicationQuản lý stock, purchase orders
@nx/signalVerifierApplicationWebSocket service tập trung
Service khác (invoice, ledger, licensing, outreach, tax, helpdesk, search, asset)VerifierApplicationTiêu thụ schema, repo, và contracts của core

Bản đồ tài liệu

TrangBạn sẽ tìm thấy gì
ArchitecturePhân cấp application, vòng đời, mẫu runtime
Components
Components OverviewChỉ mục lớp cơ sở và hạ tầng dùng chung
DefaultApplicationLớp app cơ sở, middleware, method vòng đời
SoftDeletableRepositoryMẫu soft-delete + restore (re-export từ IGNIS)
BaseSocketEventServiceBroadcast sự kiện WebSocket
Network ServicesIdentityNetworkService HTTP xuyên service
Bootstrap HelpersbootstrapApplication / bootstrapMigration
RedisConnectionFactoryKết nối Redis single/cluster
Event BusIEventBus + adapter Redis Pub/Sub
Configuration
Configuration OverviewEnvironment, constants, events, topics
Environment VariablesTham chiếu EnvironmentKeys
ConstantsPostgresSchemas, FixedUserRoles, v.v.
EventsĐịnh nghĩa sự kiện + builder topic WebSocket
Queues / KafkaHợp đồng messaging xuyên package
Database
Database OverviewBố cục schema, generateCommonColumnDefs, DataSource
Public SchemaUsers, products, merchants, organizers
Pricing SchemaFares, costs, taxes
Allocation SchemaSắp chỗ sự kiện
Sale SchemaSale orders + items
Inventory SchemaStock, purchase orders, vendors
Finance SchemaWallets, categories, transactions
Payment SchemaCấu hình webhook
Outreach SchemaDomain outreach
ERDSơ đồ thực thể-quan hệ
MigrationsCLI migrator theo domain, Drizzle Kit, seeds
Utilities
Utilities OverviewChỉ mục tiện ích dùng chung
IdGeneratorSingleton Snowflake ID
CryptoUtilityMã hoá + ký HMAC
DateUtilitydayjs cấu hình timezone
RequestContextAuth context + định dạng response

Domain Schema

Schema nằm dưới src/models/schemas/<domain>/<entity>/; repository phản chiếu chúng dưới src/repositories/<domain>/. Có 14 domain — service package tiêu thụ các schema này, chúng không định nghĩa riêng.

public · pricing · allocation · sale · inventory · finance · payment · invoice · ledger · identity · licensing · outreach · tax · helpdesk

Các sub-page database/ hiện ghi một ảnh chụp 7-schema. Xem Database Overview cho các schema đã ghi; bố cục 14-domain đầy đủ là nguồn sự thật (packages/core/AGENTS.md).

Build & Scripts

ScriptMục đích
bun run rebuildClean + build (luôn dùng cái này)
bun run lint:fixESLint + Prettier auto-fix
bun run testChạy tests (cần .env.test)
bun run db:generate / db:migrateSinh / áp migration cho một domain
bun run db:generate:all / db:migrate:allMọi domain

Tham chiếu IGNIS

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.