Project Structure

Understand the complete structure and configuration of a Clarinet project.

A Clarinet project follows a carefully designed structure that separates contracts, tests, and configuration. Understanding this structure helps you organize code effectively and configure tools for an efficient development workflow.

Core project layout

Every Clarinet project contains these essential directories and files:

- my-project/
  - .vscode/
  - contracts/
    - main.clar
    - trait.clar
  - deployments/
  - settings/
    - Devnet.toml
    - Mainnet.toml
    - Testnet.toml
  - tests/
    - main.test.ts
  - .gitignore
  - Clarinet.toml
  - package.json
  - tsconfig.json
  - vitest.config.js

Each component serves a specific purpose in your development workflow. The sections below explain how they work together to create a complete development environment.

The project manifest

Clarinet.toml

The Clarinet.toml file is the heart of your project. It defines project metadata and tracks all contracts:

The manifest handles several critical functions:

  • Contract registration: Every contract must be listed here

  • Stacks epoch and Clarity version: Specifies Clarity version and epoch for each contract

  • Boot sequence: Lists contracts to deploy on clarinet devnet start

Epoch configuration

You can specify the epoch in two ways:

Using "latest" ensures your contracts always use the newest Clarity features and optimizations available in your version of Clarinet.

Testing infrastructure

Package configuration

The package.json defines your testing environment and dependencies:

Package
Purpose

@stacks/clarinet-sdk

WebAssembly-compiled Clarinet for Node.js

@stacks/transactions

Clarity value manipulation in TypeScript

vitest

Modern testing framework with native TypeScript support

vitest-environment-clarinet

Simnet bootstrapping for tests

Vitest configuration

The vitest.config.js configures the testing framework:

This configuration enables:

  • Clarinet environment: Automatic simnet setup for each test

  • Single fork mode: Efficient test execution with proper isolation

  • Coverage tracking: Generate reports in multiple formats

  • Custom setup: Add project-specific test utilities

TypeScript configuration

The tsconfig.json provides TypeScript support:

Properly setting the include property ensures TypeScript picks up the helpers defined in the Clarinet SDK package along with your tests.

Network configurations

Environment settings

Each network has its own configuration file in the settings directory:

These settings control:

  • Network ports: API, RPC, and explorer endpoints

  • Account configuration: Test wallets with STX balances

  • Chain parameters: Network-specific blockchain settings

Common issues

Imports failing in tests

If you're encountering import errors in your tests, update your TypeScript configuration to use Vite's bundler resolution:

This configuration ensures TypeScript understands Vite's module resolution strategy and allows importing .ts files directly.

Last updated

Was this helpful?