This document outlines the recommended import patterns for the CodeQual monorepo. Following consistent import patterns helps maintain code clarity and prevents module resolution issues.
For types and utilities exported from the main package entry point:
// Recommended
import { AgentProvider, AgentRole, AnalysisResult } from '@codequal/core';Use this pattern whenever possible, as it's the most maintainable and least likely to cause issues.
For specific modules not exported from the main entry point:
// Use when necessary
import { createLogger } from '@codequal/core/utils';
import { Agent } from '@codequal/core/types/agent';Only use subpath imports when the specific item you need isn't exported from the main package entry point.
For imports within the same package:
// For imports within the same package
import { formatResult } from '../utils/formatter';
import { ConfigOptions } from './types';Use relative imports for modules within the same package to maintain clear boundaries between packages.
Make key types and utilities available from the main entry point:
// packages/core/src/index.ts
export * from './types/agent';
export * from './config/agent-registry';
export * from './utils';This allows consumers to use top-level imports for commonly used items.
Configure package.json to allow direct access to specific subpaths:
"exports": {
".": "./dist/index.js",
"./utils": "./dist/utils/index.js",
"./types/*": "./dist/types/*.js"
}This is necessary to support subpath imports at runtime.
TypeScript uses the path mappings in tsconfig.json to resolve imports:
"paths": {
"@codequal/core": ["../core/src"],
"@codequal/core/*": ["../core/src/*"]
}TypeScript will look in these locations during compilation.
Node.js uses the package.json exports field to resolve imports:
"exports": {
".": "./dist/index.js",
"./utils": "./dist/utils/index.js"
}Node.js will look at these file paths at runtime.
Missing the top-level path mapping in tsconfig.json:
// Incomplete - missing top-level import path
"paths": {
"@codequal/core/*": ["../core/src/*"]
}
// Complete - includes both patterns
"paths": {
"@codequal/core": ["../core/src"],
"@codequal/core/*": ["../core/src/*"]
}Forgetting to configure exports in package.json:
// Missing exports configuration
{
"main": "dist/index.js",
"types": "dist/index.d.ts"
}
// Complete configuration
{
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./utils": "./dist/utils/index.js"
}
}Mixing different import styles unnecessarily:
// Inconsistent - harder to maintain
import { AgentProvider } from '@codequal/core/config/agent-registry';
import { AnalysisResult } from '@codequal/core';
// Consistent - easier to maintain
import { AgentProvider, AnalysisResult } from '@codequal/core';The core package exports key types, interfaces, and utilities:
// Importing from core
import {
Agent,
AnalysisResult,
AgentProvider,
AgentRole,
createLogger
} from '@codequal/core';The database package provides database models and utilities:
// Importing from database
import { PRReviewModel, RepositoryModel } from '@codequal/database';
import { getSupabase } from '@codequal/database/supabase/client';The agents package provides agent implementations:
// Importing from agents
import { ClaudeAgent, ChatGPTAgent } from '@codequal/agents';
import { BaseAgent } from '@codequal/agents/base/base-agent';Following these consistent import patterns will help maintain code clarity and prevent module resolution issues in the CodeQual monorepo. When in doubt, prefer top-level imports, and ensure that frequently used types and utilities are properly re-exported from package entry points.