Understanding the codebase structure
The Asset Tokenization Kit uses a Turborepo monorepo to manage multiple interconnected packages. This reference explains the directory structure, key modules, file conventions, and how packages depend on each other.
Monorepo overview
The repository is organized as a Bun workspace with Turborepo orchestrating builds, tests, and deployments across packages:
asset-tokenization-kit/
├── kit/ # Main application packages
│ ├── contracts/ # Smart contracts (Solidity)
│ ├── dapp/ # Web application (TanStack Start)
│ ├── subgraph/ # Blockchain indexer (TheGraph)
│ ├── charts/ # Kubernetes deployment (Helm)
│ └── e2e/ # End-to-end tests (Playwright)
├── packages/ # Shared libraries
│ ├── config/ # Shared configuration utilities
│ └── zod/ # Shared Zod schemas
├── tools/ # Build and development tooling
│ ├── eslint-config/
│ ├── i18n/
│ └── typescript-config/
├── .github/ # CI/CD workflows and actions
├── docker-compose.yml
├── package.json # Root workspace configuration
└── turbo.json # Turborepo pipeline definitionPackage dependencies
Packages use workspace protocol for internal dependencies:
{
"dependencies": {
"@atk/config": "workspace:*",
"@atk/zod": "workspace:*",
"contracts": "workspace:*"
}
}Package deep-dive
kit/contracts
Smart contract package using Foundry (primary) and Hardhat (deployment).
Directory structure:
contracts/
├── contracts/ # Solidity source code
│ ├── system/ # Core platform contracts
│ │ ├── ATKSystemImplementation.sol
│ │ ├── access-manager/
│ │ ├── identity-registry/
│ │ ├── tokens/factory/
│ │ └── topic-scheme-registry/
│ ├── smart/ # SMART Protocol (ERC-3643)
│ │ ├── interface/
│ │ ├── modules/ # Compliance modules
│ │ └── extensions/
│ ├── assets/ # Token implementations
│ │ ├── bond/
│ │ ├── deposit/
│ │ ├── equity/
│ │ ├── fund/
│ │ └── stable-coin/
│ ├── addons/ # Optional features
│ │ ├── airdrop/
│ │ ├── vault/
│ │ ├── xvp/
│ │ └── yield/
│ ├── onchainid/ # Identity contracts
│ └── vendor/ # Third-party contracts
├── test/ # Foundry tests
├── scripts/ # Deployment and admin scripts
│ └── hardhat/
│ ├── main.ts # Main deployment orchestrator
│ ├── actions/ # On-chain actions
│ ├── assets/ # Asset deployment helpers
│ ├── constants/
│ ├── entities/
│ ├── services/
│ └── utils/
├── ignition/ # Hardhat Ignition modules
│ └── modules/
│ └── onboarding/
├── .generated/ # Build outputs (gitignored)
│ ├── artifacts/ # Compiled contracts
│ ├── genesis.json # Pre-deployed contract state
│ └── portal/ # ABIs for Portal integration
├── foundry.toml
├── hardhat.config.ts
└── package.jsonKey files:
contracts/system/ATKSystemImplementation.sol- Main system contract coordinating all componentscontracts/assets/*/ATK*FactoryImplementation.sol- Token factory patternsscripts/hardhat/main.ts- Entry point for deployment scriptsfoundry.toml- Foundry configuration (compiler version, optimizer settings)hardhat.config.ts- Hardhat network and plugin configuration
Build outputs:
bun run compile:forgegenerates.generated/artifacts/bun run artifacts:genesisgenerates.generated/genesis.jsonbun run artifacts:abigenerates.generated/portal/ABIs
kit/dapp
Modern web application built with TanStack Start (React meta-framework).
Directory structure:
dapp/
├── src/ # Application source code
│ ├── routes/ # File-based routing (TanStack Router)
│ │ ├── __root.tsx # Root layout with providers
│ │ ├── _private/ # Protected routes (requires auth)
│ │ │ ├── _onboarded/
│ │ │ │ └── _sidebar/
│ │ │ │ ├── token/ # Token management pages
│ │ │ │ ├── participants/ # User/entity management
│ │ │ │ ├── platform-settings/
│ │ │ │ └── account/ # Profile and wallet
│ │ │ └── onboarding/
│ │ ├── api/ # API routes
│ │ │ ├── rpc.$.ts # ORPC handler
│ │ │ └── auth/ # Better Auth routes
│ │ ├── docs/ # Documentation integration
│ │ └── auth.tsx # Authentication pages
│ ├── components/ # React components
│ │ └── ui/ # shadcn/ui components (do not edit manually)
│ ├── orpc/ # Backend API implementation
│ │ ├── routes/ # API routers organized by domain
│ │ │ ├── system/
│ │ │ ├── account/
│ │ │ ├── actions/
│ │ │ └── exchange-rates/
│ │ └── helpers/ # Shared backend utilities
│ ├── hooks/ # React hooks
│ ├── lib/ # Core libraries
│ │ ├── auth/ # Better Auth configuration
│ │ ├── db/ # Drizzle ORM setup
│ │ │ ├── index.ts
│ │ │ ├── schema.ts
│ │ │ └── schemas/ # Table definitions
│ │ │ ├── auth.ts
│ │ │ ├── kyc.ts
│ │ │ ├── settings.ts
│ │ │ └── exchange-rates.ts
│ │ ├── compliance/ # Compliance encoding utilities
│ │ ├── constants/
│ │ ├── fragments/ # GraphQL fragments for TheGraph
│ │ ├── i18n/ # Internationalization
│ │ ├── observability/
│ │ ├── strategies/ # Business logic patterns
│ │ └── utils/ # General utilities
│ ├── providers/ # React context providers
│ ├── styles/ # Global CSS
│ └── types/ # TypeScript type definitions
├── content/ # Documentation content (MDX)
│ └── docs/
├── drizzle/ # Database migrations
├── locales/ # Translation files (i18n)
├── public/ # Static assets
├── test/ # Test setup and utilities
│ ├── setup/
│ ├── mocks/
│ └── fixtures/
├── .source/ # Fumadocs configuration
├── drizzle.config.ts # Drizzle Kit configuration
├── package.json
├── server.ts # Production server entry
├── vite.config.ts # Vite bundler configuration
└── vitest.config.ts # Test runner configurationKey files:
src/routes/__root.tsx- Root layout with theme provider, auth, query clientsrc/orpc/routes/*/- API implementation organized by domainsrc/lib/db/schemas/- Database table schemas (Drizzle ORM)src/lib/auth/index.ts- Authentication configuration (Better Auth)drizzle.config.ts- Database connection and migration settingsvitest.config.ts- Test configuration with unit and integration projects
Build outputs:
bun run buildgenerates.nitro/(production build)bun run db:generategeneratesdrizzle/migration files
kit/subgraph
TheGraph indexing protocol for blockchain data.
Directory structure:
subgraph/
├── src/ # TypeScript mapping handlers
│ ├── system.ts # System contract event handlers
│ ├── bond.ts # Bond asset event handlers
│ ├── deposit.ts
│ ├── equity.ts
│ ├── fund.ts
│ ├── stable-coin.ts
│ ├── identity-registry.ts
│ ├── claim-topics-registry.ts
│ ├── trusted-issuers-registry.ts
│ ├── compliance.ts
│ ├── fixed-yield-schedule.ts
│ └── utils/ # Shared utilities
├── schema.graphql # GraphQL schema definition
├── subgraph.yaml # Subgraph manifest
├── .generated/ # Build outputs (gitignored)
└── package.jsonKey files:
schema.graphql- Defines entities:Token,Transfer,Identity,Claim, etc.subgraph.yaml- Manifest linking contracts to event handlerssrc/*.ts- Event handler mappings transforming blockchain events to entities
Build outputs:
bun run codegengenerates.generated/schema.tsand entity types- Deployed subgraph accessible at
http://localhost:8000/subgraphs/name/atk/graphql
kit/charts
Helm charts for Kubernetes deployment.
Directory structure:
charts/
├── atk/ # Main umbrella chart
│ ├── charts/ # Sub-charts
│ │ ├── erpc/ # Ethereum RPC proxy
│ │ ├── graph-node/ # TheGraph indexer
│ │ ├── support/ # MinIO object storage
│ │ └── txsigner/ # Transaction signing service
│ ├── templates/ # Kubernetes manifests
│ ├── values.yaml # Default values
│ └── Chart.yaml
└── tools/ # Chart generation scriptsUsage:
- Deploy to Kubernetes:
helm install atk ./kit/charts/atk - Override values:
helm install atk ./kit/charts/atk -f custom-values.yaml
kit/e2e
Playwright end-to-end test suite.
Directory structure:
e2e/
├── ui-tests/ # UI workflow tests
│ ├── 01-auth.spec.ts
│ ├── 02-onboarding.spec.ts
│ ├── 03-token-deployment.spec.ts
│ └── ...
├── pages/ # Page Object Models
├── test-data/ # Test fixtures
├── utils/ # Test utilities
├── playwright.ui.config.ts
└── package.jsonRun tests:
bun run test:e2e:ui # Headless
bun run test:e2e:ui:debug # UI modeShared packages
packages/config
Configuration utilities shared across packages.
// Usage in kit/dapp
import { getSomeConfig } from "@atk/config";packages/zod
Zod schema definitions for validation and type inference.
// Usage across packages
import { AssetTypeSchema } from "@atk/zod";File naming conventions
TypeScript/React files
- Components: PascalCase (
TokenList.tsx) - Utilities: kebab-case (
format-currency.ts) - Hooks: kebab-case with
use-prefix (use-auth.ts) - Tests: Same name as file +
.test.tsor.spec.ts- Unit tests:
*.test.ts(Vitest) - Integration tests:
*.spec.ts(Vitest with real services) - E2E tests:
*.spec.ts(Playwright)
- Unit tests:
Solidity files
- Contracts: PascalCase (
ATKBondImplementation.sol) - Interfaces: PascalCase with
Iprefix (IATKBond.sol) - Libraries: PascalCase (
ComplianceUtils.sol) - Tests: PascalCase +
.t.solor.s.sol- Unit tests:
*.t.sol - Integration tests:
*.s.sol
- Unit tests:
Configuration files
- Root-level: kebab-case (
turbo.json,docker-compose.yml) - TypeScript config: PascalCase or kebab-case (
tsconfig.json,vite.config.ts)
Import path aliases
The dApp uses TypeScript path aliases for clean imports:
// Configured in tsconfig.json
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"],
"@test/*": ["./test/*"],
"@locales/*": ["./locales/*"]
}
}
}Usage:
// Instead of: import { cn } from "../../../lib/cn";
import { cn } from "@/lib/cn";
// Instead of: import { testUser } from "../../test/fixtures/users";
import { testUser } from "@test/fixtures/users";Code organization patterns
Feature-based organization (dApp)
Related files are grouped by feature, not file type:
src/routes/_private/_onboarded/_sidebar/token/
├── $factoryAddress/
│ ├── $tokenAddress/
│ │ ├── index.tsx # Token details page
│ │ ├── holders.tsx # Token holders tab
│ │ ├── compliance.tsx # Compliance tab
│ │ ├── yield.tsx # Yield tab
│ │ └── actions.tsx # Corporate actions tab
│ └── index.tsxDomain-driven organization (ORPC API)
API routes are organized by business domain:
src/orpc/routes/
├── system/ # System-level operations
├── account/ # User account management
├── actions/ # Corporate actions
├── exchange-rates/ # Currency exchange rates
└── common/ # Shared schemasEach domain contains:
*.contract.ts- ORPC contract definition (type-safe API spec)*.router.ts- Route implementation*.schema.ts- Zod validation schemas*.test.ts- Unit tests*.spec.ts- Integration tests
Layer separation (smart contracts)
Contracts follow a layered architecture:
- System layer (
contracts/system/) - Core platform infrastructure - SMART layer (
contracts/smart/) - ERC-3643 compliance framework - Asset layer (
contracts/assets/) - Token implementations - Addon layer (
contracts/addons/) - Optional features
Dependencies flow downward: Assets depend on SMART, SMART depends on System.
Build and development scripts
Root package.json
Commands that orchestrate across all packages:
{
"scripts": {
"dev": "turbo dev watch",
"dev:up": "docker compose up -d",
"dev:reset": "bash tools/dev-reset.sh",
"build": "turbo build",
"test": "turbo test",
"lint": "turbo lint",
"format": "turbo format",
"artifacts": "turbo run artifacts",
"ci": "turbo run ci"
}
}Package-specific scripts
Each package has its own build pipeline:
kit/contracts/package.json:
{
"scripts": {
"compile:forge": "settlemint scs foundry build",
"compile:hardhat": "settlemint scs hardhat build",
"test": "settlemint scs foundry test",
"artifacts:genesis": "bun run tools/artifacts-genesis.ts",
"artifacts:abi": "bun run tools/artifacts-abi.ts"
}
}kit/dapp/package.json:
{
"scripts": {
"dev": "bun --bun vite dev",
"build": "bun --bun vite build",
"test:unit": "vitest run --project unit",
"test:integration": "vitest run --project integration",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate"
}
}Turborepo pipeline
The turbo.json defines task dependencies and caching:
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".nitro/**"]
},
"test": {
"dependsOn": ["build"],
"cache": false
},
"artifacts": {
"dependsOn": ["compile", "codegen"],
"outputs": [".generated/**"]
}
}
}Pipeline execution:
turbo run build- Builds packages in dependency orderturbo run test --filter=dapp- Runs tests only for dApp packageturbo run artifacts --force- Ignores cache, regenerates all artifacts
Generated files and gitignore
The following directories are generated during build and excluded from Git:
.generated/ # All build artifacts
.nitro/ # dApp production build
.turbo/ # Turborepo cache
node_modules/ # Dependencies
dist/ # Package build outputs
drizzle/ # Database migrations (tracked)
coverage/ # Test coverage reports
.eslintcache # ESLint cacheNote: drizzle/ migrations are tracked in Git to ensure schema consistency
across environments.
Environment-specific configuration
Development (local)
- Uses
docker-compose.ymlfor services - Environment variables in
.env.local(gitignored) - Hot module replacement enabled
- Source maps included
Production (Kubernetes)
- Uses Helm charts in
kit/charts/ - Environment variables from Kubernetes secrets
- Optimized builds with minification
- Source maps excluded
Next steps
- Extend smart contracts: Extending contracts
- Build API endpoints: Using the API
- Deploy to production: Deployment guide
- Run tests: Testing and QA
- Surface docs for crawlers: robots.txt and sitemap.xml are generated automatically from the docs source so search engines index published guides.