Core Architecture
Relevant source files
The following files were used as context for generating this wiki page:
Nestjs-query follows a modular, monorepo architecture built with TypeScript. The system provides framework-independent primitives that facilitate the creation of CRUD (Create, Read, Update, Delete) endpoints, primarily focusing on GraphQL and REST integrations.
The architecture decouples the presentation layer (GraphQL/REST) from the persistence layer (TypeORM, Mongoose, etc.) by using a central core package. This core package defines the standard interfaces and utility types that all other integration packages implement.
Sources: README.md, packages/core/README.md, AGENTS.md
Package Structure and Responsibilities
The project is organized into a monorepo using Yarn workspaces and Nx. It separates logic into three distinct categories: core primitives, integration adapters, and consumer examples.
| Package Category | Description | Key Packages |
|---|---|---|
| Core | Defines interfaces, query primitives, and service abstractions. | @ptc-org/nestjs-query-core |
| Integrations | Provides implementations for specific transport or persistence layers. | query-graphql, query-rest, query-typeorm, query-mongoose |
| Documentation | Contains the Docusaurus-based technical documentation. | documentation |
| Examples | Demonstrates usage through end-to-end applications. | examples/basic, examples/federation-v2-e2e |
Sources: AGENTS.md, README.md, packages/core/project.json
Dependency Flow
The architecture enforces a strict dependency flow where integration packages depend on the core library, but the core library remains independent of specific databases or transport protocols.
The diagram shows that all specific implementation packages depend on the core primitives to ensure consistent behavior across different stacks.
Sources: AGENTS.md, packages/core/README.md, packages/query-graphql/project.json, packages/query-typeorm/project.json
Core Primitives
The @ptc-org/nestjs-query-core package serves as the foundation of the architecture. It contains the essential building blocks used to define how data is filtered, paged, and sorted.
- Query Primitives: Standardized ways to define filters and pagination logic.
- Service Interfaces: Abstract definitions for CRUD operations that persistence adapters must implement.
- DTO Primitives: Base structures for Data Transfer Objects used across different layers.
Sources: packages/core/README.md, AGENTS.md, README.md
Data Interaction Flow
The system facilitates data movement from the external interface down to the database through a series of specialized components.
This flow illustrates how the query-graphql or query-rest packages interact with the core service interfaces, which are then fulfilled by persistence-specific adapters like query-typeorm.
Sources: documentation/sidebars.js, README.md, documentation/src/pages/index.js
Conceptual Modules
The architecture is categorized into several conceptual pillars as reflected in the project documentation and folder structure.
Persistence Adapters
These modules implement the core service interfaces for specific ORMs or ODMs. Supported adapters include TypeORM, Sequelize, Mongoose, and Typegoose. These adapters handle the translation of generic query objects into engine-specific queries (e.g., SQL WHERE clauses or Mongoose filter objects).
Sources: documentation/sidebars.js, README.md
Presentation Adapters
- GraphQL: Provides code-first CRUD resolvers with built-in support for filtering, paging, and sorting. It supports advanced features like dataloaders, subscriptions, and federation.
- REST: Provides controllers and OpenAPI integration for standard HTTP endpoints.
Sources: documentation/sidebars.js, documentation/src/pages/index.js, examples/basic-rest/open-api.json
Assemblers
Assemblers act as an advanced architectural layer used to transform data between different representations, such as converting a database Entity to a public-facing DTO.
Sources: documentation/sidebars.js
Summary
The nestjs-query core architecture provides a highly decoupled, monorepo-based framework for NestJS applications. By centralizing logic in the core package and providing pluggable adapters for persistence and transport layers, it ensures that CRUD operations remain consistent and type-safe regardless of the underlying database or API protocol used.