by gus

ChartDB is an open-source, web-based database diagramming tool that instantly visualizes your schema via a single Smart Query. Supports PostgreSQL, MySQL, SQLite, MariaDB, SQL Server, CockroachDB, and ClickHouse — no account or password required.
ChartDB is an open-source, web-based database schema diagram editor built with React and TypeScript. It supports importing database metadata from PostgreSQL, MySQL, SQL Server, MariaDB, SQLite, CockroachDB, and ClickHouse, and exporting schemas as SQL DDL across dialects. The typical buyer embeds the diagram editor into a developer tooling platform or database administration UI, or reuses its SQL import/export pipeline in a backend service.
assets/ - Static images: database logos, example screenshots, template previewscomponents/ - Shared React UI components (buttons, modals, editors, etc.)context/ - React context providers for diagram state and application configurationdialogs/ - Modal dialog components for import, export, and diagram operationshelmet/ - HTML <head> management via React Helmet for page metadatahooks/ - Custom React hooks for diagram data access and UI interactionsi18n/ - Internationalization config and translation fileslib/ - Core domain logic: SQL import, SQL export, metadata parsing, domain typespages/ - Top-level route page componentstemplates-data/ - Predefined schema templates for common applicationstypes/ - Shared TypeScript type declarationsapp.tsx - Root application componentglobals.css / index.css - Global and base stylesmain.tsx - Application entry point and React DOM mountpolyfills.ts - Browser polyfillsrouter.tsx - React Router route definitionssafari-compat.ts - Safari-specific compatibility patchestypes.d.ts - Ambient module declarationsvite-env.d.ts - Vite environment type shimswindow.d.ts - Window object augmentationsnpm install @ai-sdk/openai @dbml/core @dbml/parse \
@dnd-kit/sortable @monaco-editor/react \
@radix-ui/react-accordion @radix-ui/react-alert-dialog \
@radix-ui/react-avatar @radix-ui/react-checkbox \
@radix-ui/react-collapsible @radix-ui/react-context-menu \
@radix-ui/react-dialog @radix-ui/react-dropdown-menu \
@radix-ui/react-hover-card @radix-ui/react-icons \
@radix-ui/react-label @radix-ui/react-menubar \
@radix-ui/react-popover @radix-ui/react-scroll-area \
@radix-ui/react-select @radix-ui/react-separator \
@radix-ui/react-slot @radix-ui/react-tabs \
@radix-ui/react-toast @radix-ui/react-toggle \
react react-dom react-router-dom \
react-helmet-async i18next react-i18next
Spin up an isolated sandbox and run it server-side — no local setup.
Tetrees AI Review of this version
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Pipeline avcp-2026-08-04.1 · SHA-256 6da061640c1ee0e2…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Reviewed Aug 4, 2026
Push this product straight into your AI IDE, web builder or cloud IDE.
Connect Tetrees to a compatible AI IDE, list products you own, and request the verified ZIP without exposing seller upload controls.
No reviews yet.
Sign in to join the discussion
Loading discussion…
No native modules, pod installs, or Expo prebuild steps are required. This is a pure web project. A Vite build pipeline is expected; if you are integrating into a non-Vite project, add path alias support (see setup below).
Copy source files. Place the contents of source/ into src/ in your project root (or a subdirectory like src/chartdb/).
Configure path aliases. The source uses @/ to refer to src/. In tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
In vite.config.ts:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
resolve: {
alias: { '@': path.resolve(__dirname, 'src') },
},
});
Set environment variables. Create a .env file:
VITE_OPENAI_API_KEY=sk-... # Optional: enables AI-powered DDL export
Entry point. Use src/main.tsx as the Vite entry point. It mounts <App /> from app.tsx into #root.
Styles. Import src/index.css and src/globals.css in your entry file or CSS bundle. Tailwind CSS is expected; ensure a tailwind.config.js covers the src/ directory.
TypeScript strictness. The source targets "strict": true. Loosen only if you encounter third-party type errors.
loadFromDatabaseMetadataimport { loadFromDatabaseMetadata } from '@/lib/data/import-metadata/import';
import { DatabaseType } from '@/lib/domain';
const diagram = await loadFromDatabaseMetadata({
databaseType: DatabaseType.POSTGRESQL,
databaseMetadata: metadata, // DatabaseMetadata object from smart query result
diagramNumber?: number, // optional: used to name the diagram
databaseEdition?: DatabaseEdition // optional: e.g. supabase, timescale
}): Promise<Diagram>
Use this when you have already executed the ChartDB "smart query" against a live database and received a DatabaseMetadata JSON object. It parses tables, relationships, custom types, views, and dependencies, then adjusts table positions for a clean initial layout.
hasCrossDialectSupportimport { hasCrossDialectSupport } from '@/lib/data/sql-export/cross-dialect';
import { DatabaseType } from '@/lib/domain';
function hasCrossDialectSupport(
sourceDatabaseType: DatabaseType,
targetDatabaseType: DatabaseType
): boolean
Call this before presenting dialect conversion options in your UI. Returns true only when a deterministic (non-AI) conversion path exists between the two database types. Currently, PostgreSQL → MySQL, MariaDB, and SQL Server are supported.
exportPostgreSQLToMySQL / exportPostgreSQLToMSSQLimport {
exportPostgreSQLToMySQL,
exportPostgreSQLToMSSQL,
} from '@/lib/data/sql-export/cross-dialect';
These functions perform deterministic cross-dialect DDL conversion from a PostgreSQL diagram to MySQL/MariaDB or SQL Server syntax, respectively. Use them when the user wants to migrate or compare schemas across database engines without requiring an OpenAI key.
You have the JSON output from ChartDB's smart query (run against a PostgreSQL database) and want to construct a Diagram object for rendering or further processing.
import { loadFromDatabaseMetadata } from '@/lib/data/import-metadata/import';
import { DatabaseType } from '@/lib/domain';
import type { DatabaseMetadata } from '@/lib/data/import-metadata/metadata-types/database-metadata';
const rawMetadata: DatabaseMetadata = JSON.parse(process.env.DB_METADATA_JSON!);
async function buildDiagram() {
const diagram = await loadFromDatabaseMetadata({
databaseType: DatabaseType.POSTGRESQL,
databaseMetadata: rawMetadata,
diagramNumber: 1,
});
console.log('Tables:', diagram.tables?.length);
console.log('Relationships:', diagram.relationships?.length);
return diagram;
}
buildDiagram().catch(console.error);
Before showing a "Export to MySQL" button, verify the conversion is supported, then run it.
import {
hasCrossDialectSupport,
exportPostgreSQLToMySQL,
} from '@/lib/data/sql-export/cross-dialect';
import { DatabaseType } from '@/lib/domain';
import type { Diagram } from '@/lib/domain';
function exportDiagram(diagram: Diagram, target: DatabaseType): string | null {
const source = DatabaseType.POSTGRESQL;
if (!hasCrossDialectSupport(source, target)) {
console.warn(`No deterministic conversion from ${source} to ${target}`);
return null;
}
if (target === DatabaseType.MYSQL || target === DatabaseType.MARIADB) {
return exportPostgreSQLToMySQL(diagram);
}
if (target === DatabaseType.SQL_SERVER) {
return exportPostgreSQLToMSSQL(diagram);
}
return null;
}
Use the SQL import pipeline to parse a user-supplied DDL script (auto-detected dialect).
import { importSQL } from '@/lib/data/sql-import';
import { DatabaseType } from '@/lib/domain';
async function parseDDL(sql: string) {
// importSQL auto-detects pg_dump, SQL Server, Oracle, MySQL, SQLite
const diagram = await importSQL(sql, DatabaseType.POSTGRESQL);
if (!diagram) {
throw new Error('Failed to parse SQL DDL');
}
console.log('Parsed tables:', diagram.tables?.map(t => t.name));
return diagram;
}
parseDDL(`
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE
);
`).catch(console.error);
assets/ - All static image assets; database vendor logos in light/dark variants plus example and template screenshots.components/ - Reusable React UI components used across pages and dialogs.context/ - React contexts that hold global diagram state, storage, and configuration; wrap your app with these providers.dialogs/ - Self-contained dialog components for operations like import from SQL, export DDL, table editing.helmet/ - Page-level <Helmet> components for setting <title> and meta tags per route.hooks/ - Custom hooks abstracting diagram data queries and UI state (e.g., undo/redo, selected table).i18n/ - i18next initialization and all locale JSON files; add translations here.lib/ - The engine: lib/domain defines all core types; lib/data/sql-import parses SQL; lib/data/sql-export generates SQL; lib/data/import-metadata converts smart-query JSON to diagrams.pages/ - Route-level page components connected to the router.templates-data/ - Hardcoded schema templates (e.g., Airbnb, Akaunting) available in the template gallery.types/ - Shared TypeScript interfaces not tied to a specific module.app.tsx - Composes providers, router, and global layout.main.tsx - Vite entry; calls ReactDOM.createRoot.router.tsx - React Router createBrowserRouter configuration.polyfills.ts - Polyfills for older browser APIs.safari-compat.ts - Patches for Safari-specific rendering bugs.@/ alias not resolved at runtime - Ensure both tsconfig.json paths and vite.config.ts resolve.alias point @ to the same absolute src/ directory; one without the other causes silent failures.VITE_OPENAI_API_KEY missing causes AI export to silently fail - The key is optional but must be present in .env at build time; runtime injection does not work with Vite's import.meta.env baking.@dbml/core ESM/CJS interop errors - If bundling for Node.js (e.g., an Express backend using the import pipeline), set "type": "module" in your package.json or use a dynamic import() wrapper; @dbml/core ships ESM only.'./src/**/*.{ts,tsx}' to tailwind.config.js content; the source uses Tailwind utility classes throughout and they will be purged if the path is not covered.adjustTablePositions returns empty array - This happens when tables is an empty array before relationships are built; ensure createTablesFromMetadata receives a valid DatabaseMetadata object with a non-empty tables key.@monaco-editor/react requires a browser DOM; do not import diagram editor page components in server-rendered code; use dynamic imports with ssr: false if using Next.js.I have integrated the ChartDB source (chartdb@1.20.1) into my project under src/.
The USAGE.md file is at the root of this block and describes all real exports and file locations.
Please help me integrate ChartDB step by step into my existing [describe your project: e.g., "Express + React app"].
Context:
- Source lives in src/ with path alias @/ mapped to src/
- Core imports come from @/lib/domain, @/lib/data/import-metadata/import, @/lib/data/sql-import, @/lib/data/sql-export/cross-dialect
- Key functions: loadFromDatabaseMetadata, hasCrossDialectSupport, exportPostgreSQLToMySQL, exportPostgreSQLToMSSQL
- The app entry is src/main.tsx; providers are in src/context/
Tasks:
1. Wire the path alias in my vite.config.ts and tsconfig.json
2. Mount the ChartDB <App /> inside my existing React shell
3. Show me how to call loadFromDatabaseMetadata with a sample DatabaseMetadata payload
4. Add a UI button that calls hasCrossDialectSupport and, if true, calls exportPostgreSQLToMySQL and downloads the result as a .sql file
5. Point out any missing dependencies I need to install based on USAGE.md
Only use imports and function signatures documented in USAGE.md. Do not invent new APIs.
ChartDB is released under the AGPL-3.0 license (GNU Affero General Public License v3.0). Any modifications to the source that are deployed as a network service must be made available to users under the same license. See source/LICENSE if present, or the upstream repository at https://github.com/chartdb/chartdb. The upstream npm package is user@example.com.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
The full install guide and integration prompts unlock after purchase.
Automation, Utilities & Developer Tools
Free