Monorepo Tooling (Nx & Yarn)
Relevant source files
The following files were used as context for generating this wiki page:
The nestjs-query project operates as a TypeScript monorepo managed by Nx and Yarn 4 workspaces. This architecture centralizes reusable libraries, runnable examples, and documentation into a single repository to streamline development and dependency management. The tooling ensures consistent build, test, and linting workflows across all sub-projects.
Sources: AGENTS.md:5-9, README.md:46-47
Architecture and Structure
The repository organizes code into three primary top-level directories. Reusable framework-independent logic and persistence adapters reside in packages/. Functional application examples and end-to-end test suites are located in examples/. The project's documentation site, built with Docusaurus, is housed in documentation/.
Sources: AGENTS.md:7-9, AGENTS.md:42-46, documentation/project.json:4
Dependency Relationships
Libraries within the monorepo often depend on the core package. Nx manages these implicit and explicit dependencies to determine the correct order for builds and tests.
The diagram shows the dependency flow where core logic serves as the foundation for integration packages and examples.
Sources: packages/query-graphql/project.json:34, packages/query-mongoose/project.json:32, examples/project.json:8
Nx Workflows and Targets
Nx coordinates tasks through targets defined in each project's project.json file. Common targets include build, test, lint, version, and publish.
Core Commands
You interact with the monorepo using the yarn nx <target> <project> syntax. Nx caches results for build and lint operations to accelerate subsequent runs.
| Target | Command Example | Purpose |
|---|---|---|
| Build | yarn nx build core | Compiles TypeScript source to the dist/ directory. |
| Test | yarn nx test core | Executes Jest unit tests for the specific project. |
| Lint | yarn nx lint core | Runs ESLint based on root and local configurations. |
| E2E | yarn nx e2e examples | Runs end-to-end tests located in the examples directory. |
| Show | yarn nx show projects | Lists all projects currently defined in the workspace. |
Sources: AGENTS.md:12, AGENTS.md:27-33, README.md:58-61, nx.json:32-48
Task Pipeline
Nx uses targetDependencies to ensure that a project's dependencies are built before the project itself. For example, the build target depends on the build target of all upstream dependencies.
Sources: nx.json:10-15, nx.json:28-31
Project Configuration
Each module contains a project.json file defining its role and available operations.
- Libraries: Configured with
projectType: "library"and typically use the@nx/js:tscexecutor for builds. Output is directed todist/packages/<name>. - Applications: Configured with
projectType: "application". Examples include the documentation site and E2E test suites. - Versioning: Managed via
@jscutlery/semver, allowing for synchronized versioning across the workspace.
Sources: packages/core/project.json:5-28, documentation/project.json:4-10, project.json:4-16
Development Environment (Yarn)
The project requires Yarn 4 for dependency management. Before starting development, you must initialize the workspace.
- Run
npm installto set up initial environment. - Run
npm run bootstrapto link packages. - Run
npm run buildto compile the initial state of all libraries.
Sources: CONTRIBUTING.md:112-117, AGENTS.md:12
Commit Conventions
The monorepo enforces Conventional Commits. Commits must follow the format <type>(<scope>): <subject>. Nx and semantic-versioning tools use these messages to generate changelogs and determine version increments.
Sources: CONTRIBUTING.md:213-228, AGENTS.md:20
Summary
Monorepo tooling in nestjs-query relies on Nx for task orchestration and Yarn for workspace management. This structure facilitates the development of a modular system where the core package provides primitives for various persistence and GraphQL integrations, all verified through standardized Nx targets.