Canonical File & Directory Structure Standard
This standard defines canonical file naming and placement across the Nexload SDK ecosystem. Autonomous agents and human engineers must follow the nexload-way roles and the generated role table below when creating, refactoring, or modernizing packages and applications.
Core Architectural Principles
Section titled “Core Architectural Principles”- Predictable Discovery: A developer or agent inspecting
src/should grasp module boundaries within 10 seconds. - Explicit Dependency Flow: Dependencies flow inward; internal helper utilities never leak through root barrel exports.
- Mandatory Kebab-Case: Every file and folder name uses
kebab-case. Never usecamelCaseorPascalCasefilenames. Only framework convention and generated files keep the name their tool requires, such aspayload-types.tsorrouteTree.gen.ts. - Co-location of Tests: Every test sits next to the file it tests and repeats its full file name:
pricing.service.test.tsandpricing.service.integration.test.tsbesidepricing.service.ts. Never use a separatetest/,tests/or__tests__/folder (ST-10). - Private Boundary Markers: A leading
_marks a module-private file, such as_price-row.comp.tsx. Import it only from inside its own module and never export it fromindex.ts(ST-05). Do not create aninternal/folder; the_prefix is the only private marker.
File Roles & Naming
Section titled “File Roles & Naming”File layout, role suffixes and naming follow the nexload-way skill (skills/nexload/way/); do not hand-write layouts from this page.
Run nexload-doctrine verify from @nexload-sdk/eslint-config to check a tree against the same manifest.
Load the nexload-way skill before creating, renaming or moving files. The table below is generated from its manifest.
| role | ext | meaning | folders | example | symbol |
|---|---|---|---|---|---|
page | tsx | Renders a full page | modules/<feature>/ | checkout.page.tsx | CheckoutPage |
layout | tsx | Shared frame for several pages of a module | modules/<feature>/ | account.layout.tsx | AccountLayout |
skeleton | tsx | Loading state of a page or section | next to its page | checkout.skeleton.tsx | CheckoutSkeleton |
comp | tsx | React component (prefix _ when private to the module) | modules/<feature>/ or shared/ui/ | modules/products/card.comp.tsx | ProductCard |
hook | ts | React hook | modules/<feature>/ | modules/carts/state.hook.ts | useCartState |
provider | tsx | React context provider | modules/<feature>/ | modules/carts/cart.provider.tsx | CartProvider |
util | ts | Pure helper function | next to the module with _, or shared/lib/ | shared/lib/slug.util.ts | formatSlug |
schema | ts | Zod validation schema | modules/<feature>/ | modules/orders/checkout.schema.ts | checkoutSchema |
adapter | ts | Connects to an external service (gateway, SMS) | modules/<domain>/ | modules/payments/zibal.adapter.ts | createZibalAdapter |
service | ts | Runs domain logic or a use case | modules/<domain>/ | modules/orders/pricing.service.ts | calcOrderTotal |
router | ts | Registers RPC or HTTP routes | modules/<domain>/ | modules/payments/payment.router.ts | paymentRouter |
mapper | ts | Converts data between layers | modules/<domain>/ | modules/products/product.mapper.ts | toProductDto |
dto | ts | Describes the input or output of an endpoint | modules/<domain>/ | modules/customers/create.dto.ts | CreateCustomerDto |
contract | ts | API contract between apps | packages/contracts/src/ | catalog.contract.ts | catalogContract |
entity | ts | Canonical model of an entity | packages/schema/src/<domain>/ | payments/payment.entity.ts | paymentEntity |
collection | ts | Payload collection | modules/<domain>/ | modules/orders/order.collection.ts | Orders |
global | ts | Payload global | modules/<domain>/ | modules/settings/store.global.ts | StoreSettings |
before-validate | ts | Payload collection beforeValidate hook (module-private) | next to the collection | _<what>.before-validate.ts | verb-named function |
before-change | ts | Payload collection beforeChange hook (module-private) | next to the collection | _total.before-change.ts | computeOrderTotal |
after-change | ts | Payload collection afterChange hook (module-private) | next to the collection | _<what>.after-change.ts | verb-named function |
after-read | ts | Payload collection afterRead hook (module-private) | next to the collection | _<what>.after-read.ts | verb-named function |
after-delete | ts | Payload collection afterDelete hook (module-private) | next to the collection | _<what>.after-delete.ts | verb-named function |
access | ts | Payload access rule | modules/<domain>/ | modules/customers/customer.access.ts | customerAccess |
operations | ts | Typed operations on the Payload Local API | modules/<domain>/ | modules/payments/payment.operations.ts | paymentOperations |
job | ts | Background job or task | modules/<domain>/ | modules/orders/expiry.job.ts | orderExpiryJob |
endpoint | ts | Custom endpoint | modules/<domain>/ | modules/catalog/preview.endpoint.ts | catalogPreviewEndpoint |
types | ts | Types only | next to the owner | modules/products/card.types.ts | ProductCardProps |
constants | ts | Module constants | modules/<feature>/ | modules/shop/shop.constants.ts | shopPageSize |
errors | ts | Module error classes or codes | modules/<domain>/ | modules/payments/payment.errors.ts | PaymentDeclinedError |
Anti-Patterns to Avoid
Section titled “Anti-Patterns to Avoid”- ❌ Deep Relative Import Leaks: Importing another module’s files, such as
../orders/pricing.serviceor../orders/_price-row.comp. Import another module only through itsindex.ts(ST-04, ST-05). - ❌ Mixed Case or Role-less Filenames: Files like
UserProfile.tsxordataFetcher.ts. Use a kebab-case<what>plus a role from the table (ST-06, ST-07):modules/users/profile.comp.tsx, and name a fetcher after what it does, such asmodules/orders/order.operations.ts. Runnexload-doctrine suggest <path> --kind <role>for the exact name. - ❌ Barrel Bloat: Re-exporting every private function in
src/index.ts. Only export public interfaces, contracts, and entry functions. - ❌ Circular Dependencies: Cycles between a
<what>.types.tsfile and implementation files. Types must remain leaf nodes.