Skip to content

Core Package

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

Đây là một thẻ định danh ngắn gọn. Core có lý do chính đáng để khác với template service 8-file chuẩn - cấu trúc đã hoàn chỉnh của nó (architecture, components/*, configuration/*, database/*, utilities/*) được mô tả trong các trang con liên kết bên dưới.

Thẻ định danh

Thuộc tínhGiá trị
Package@nx/core
LoạiThư viện dùng chung / mở rộng framework (không có 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 trungNơi duy nhất chứa mọi schema trong monorepo - <domain>/<entity>/{schema.ts, model.ts, constants.ts, index.ts} trải trên 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(), các helper merchant-access + postgres + transform + slugsrc/utilities/
Constants & typesStatuses (của IGNIS, dùng lại - không tự định nghĩa enum), PostgresSchemas, AppFixedRoles, các validation, decorator dùng chungsrc/common/

Điểm giao tiếp xuyên package

Kafka/CDC là điểm 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
Các service khác (invoice, ledger, licensing, outreach, tax, helpdesk, search, asset)VerifierApplicationDùng lại schema, repo, và contract 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, AppFixedRoles, 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

Các domain schema

Schema nằm dưới src/models/schemas/<domain>/<entity>/; repository được phản chiếu tương ứng dưới src/repositories/<domain>/. Có 14 domain - các service package dùng lại các schema này, chúng không tự định nghĩa schema riêng.

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

Các trang con database/ hiện chỉ mô tả một snapshot 7-schema. Xem Database Overview cho các schema đã được ghi; bố cục 14-domain đầy đủ mới là nguồn chuẩn duy nhất (.agents/knowledge/packages/core.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.