Coding Standards
The real lint, format, and TypeScript rules enforced across the Anvio monorepo.
3 min read
Anvio's coding standards come from three files at the repo root: eslint.config.js, prettier.config.js, and tsconfig.base.json. Every package extends these — there is no per-package override for style.
TypeScript (tsconfig.base.json)
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"composite": true,
"incremental": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": ["node_modules", "dist"]
}Practical consequences:
strict: true— no implicitany, strict null checks, everywhere.module/moduleResolution: NodeNext— relative imports must include the file extension:import { foo } from './bar.js', even though the source file isbar.ts. This trips up newcomers coming frombundlerresolution.noUnusedLocals/noUnusedParameters— dead variables fail the build, not just lint. Prefix an intentionally-unused parameter with_to satisfy both TypeScript and the ESLint rule below.noFallthroughCasesInSwitch— everyswitchcase needs an explicitbreak,return, orthrow. This is why the tool gateway's dispatch switch (packages/tools/src/builtins/index.ts) returns from every branch.composite: true+declaration/declarationMap— packages build as TypeScript project references;pnpm buildrunstsc -p tsconfig.jsonper package via Turborepo, respecting the dependency graph.
ESLint (eslint.config.js)
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ['**/dist/**', '**/node_modules/**', '**/.turbo/**'],
},
{
rules: {
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-explicit-any': 'warn',
},
},
);- Base:
eslint:recommended+typescript-eslint:recommended. no-unused-varsis an error, but allows a leading underscore (_req,_unused) — matches thenoUnusedParametersTypeScript rule above.no-explicit-anyis a warning, not an error —anyis discouraged but not banned outright (useful at process/IPC boundaries like the MCP stdio client).dist/,node_modules/, and.turbo/are excluded everywhere.
Run it with:
pnpm lint # turbo run lint (all packages, respects build deps)
pnpm --filter @anvio/tools lint # single packagePrettier (prettier.config.js)
export default {
semi: true,
singleQuote: true,
trailingComma: 'all',
printWidth: 100,
tabWidth: 2,
};Semicolons required, single quotes, trailing commas everywhere valid (all, not es5), 100-character line width, 2-space indent.
pnpm format # write
pnpm format:check # CI check, no writesTesting
Anvio uses Vitest, not Jest. Test files are colocated as *.spec.ts next to the implementation (for example packages/tools/src/builtins/utility-tools.spec.ts), not in a separate __tests__ directory.
pnpm test # vitest run --config vitest.config.mts (unit tests)
pnpm test:integration # tests/integration only, no turbo cacheModule boundaries as a coding standard
The folder structure dependency rule (apps → platform → packages → core) is enforced by convention and package.json dependencies, not by a custom ESLint import-boundary rule today. When adding code, the practical checks are:
- Does this belong in
packages/core? Only if it's a schema, type, or port with zero dependencies on other Anvio packages. - Does an
apps/*file contain business logic? If yes, move it into a package —apps/should only wire NestJS modules/controllers to package exports. - Are you importing a package's internal file directly (bypassing
src/index.ts)? Don't — import the package's public export instead.
There is no automated lint rule that blocks illegal cross-layer imports today. Reviewers enforce the dependency rule manually in code review — see docs/02-architecture.md and ADR 0002.
NestJS usage (apps/ only)
Per ADR 0002, NestJS is scoped to apps/ as the composition root — dependency injection and module wiring, nothing else. Domain logic (agent runtime, tool execution, model routing) stays in packages/ as plain TypeScript classes and functions with no framework dependency, so they can be unit-tested and reused by the CLI without booting Nest.
Last updated on