# metaldz/eloquent-orm.js architecture

> Architecture diagram of the GitHub repository metaldz/eloquent-orm.js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/metaldz/eloquent-orm.js
- Repository: https://github.com/metaldz/eloquent-orm.js

## Overview

Eloquent ORM JS is a Laravel-inspired Node.js/TypeScript ORM and CLI. Its main runtime path exposes models and query helpers, resolves a configured database connection, and performs persistence through SQL or MongoDB drivers; model mixins add relationships, caching, and lifecycle behavior. A parallel CLI supports scaffolding and database migration/seed workflows, with cache setup and management as another capability. The graph uses README claims for unsampled CLI features and omits uncertain internal dispatch details; sampled source establishes the model, connection, cache, and scaffold links shown.

Main entry points: [`src/index.ts`](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/index.ts) (Public API), [`src/core/model/BaseModel.ts`](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/BaseModel.ts) (Model API), [`src/core/model/CoreModel.ts`](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/CoreModel.ts) (Persistence and queries), [`src/core/connection/TransactionManager.ts`](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/TransactionManager.ts) (Transactions and locks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["ORM runtime"]
  node_public_api["Public API<br/>[index.ts]"]
  node_model["Model API<br/>[BaseModel.ts]"]
  node_core_model["Persistence and queries<br/>[CoreModel.ts]"]
  node_safe_finder["Safe finders<br/>[SafeFinder.ts]"]
  node_relationships["Relations and mixins"]
end

subgraph group_storage["Connections and schema"]
  node_schema_blueprint["Schema blueprint<br/>[SchemaBlueprint.ts]"]
  node_schema_builder["Schema builder<br/>[SchemaBuilder.ts]"]
  node_db_config["Database configuration<br/>[database.ts]"]
  node_connection_factory["Connection factory"]
  node_db_connection["Database connections"]
  node_driver_adapter["Driver adapter<br/>[DriverAdapter.ts]"]
  node_transactions["Transactions and locks"]
end

subgraph group_cli["CLI workflows"]
  node_cli["CLI command runtime<br/>[eloquent.ts]"]
  node_scaffold_commands["Scaffold generators"]
  node_controller_generator["Controller generator<br/>[makeController.ts]"]
  node_template_engine["Template engine<br/>[TemplateEngine.ts]"]
  node_scaffold_support["Scaffold support"]
  node_file_writer["Artifact writer<br/>[fileWriter.ts]"]
  node_migration_seed["Migration and seed commands"]
end

subgraph group_cache["Caching"]
  node_cache_setup["Cache setup<br/>[setupCache.ts]"]
  node_cache_manager["Cache manager<br/>[CacheManager.ts]"]
  node_cache_drivers["Cache drivers"]
  node_query_cache["Query cache mixin<br/>[QueryCacheMixin.ts]"]
end

node_developer(("Application developer"))
node_database[("SQL / MongoDB")]
node_cli_user(("CLI user"))
node_cache_store[("Cache backend")]

node_developer -->|"uses"| node_public_api
node_public_api -->|"exports"| node_model
node_public_api -->|"exports"| node_schema_blueprint
node_public_api -->|"exports"| node_schema_builder
node_public_api -->|"exports"| node_cache_manager
node_public_api -->|"exports"| node_transactions
node_model -->|"composes"| node_core_model
node_model -->|"mixes in"| node_relationships
node_model -->|"mixes in"| node_query_cache
node_core_model -->|"uses"| node_safe_finder
node_core_model -->|"gets connection"| node_connection_factory
node_core_model -->|"validates schema"| node_schema_blueprint
node_connection_factory -->|"reads config"| node_db_config
node_connection_factory -->|"creates connection"| node_db_connection
node_db_connection -->|"connects"| node_database
node_transactions -->|"gets connection"| node_connection_factory
node_transactions -->|"opens connection"| node_db_connection
node_transactions -->|"creates adapter"| node_driver_adapter
node_cli_user -->|"runs commands"| node_cli
node_cli -.->|"dispatches"| node_scaffold_commands
node_cli -.->|"dispatches"| node_migration_seed
node_scaffold_commands -->|"includes"| node_controller_generator
node_controller_generator -->|"renders template"| node_template_engine
node_controller_generator -->|"resolves artifact"| node_scaffold_support
node_controller_generator -->|"writes output"| node_file_writer
node_cache_setup -->|"selects drivers"| node_cache_drivers
node_cache_setup -->|"configures"| node_cache_manager
node_cache_manager -->|"reads and writes"| node_cache_store
node_query_cache -->|"uses"| node_cache_manager

click node_public_api "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/index.ts"
click node_model "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/BaseModel.ts"
click node_core_model "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/CoreModel.ts"
click node_safe_finder "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/SafeFinder.ts"
click node_relationships "https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/core/orm"
click node_schema_blueprint "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/schema/SchemaBlueprint.ts"
click node_schema_builder "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/schema/SchemaBuilder.ts"
click node_db_config "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/config/database.ts"
click node_connection_factory "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/ConnectionFactory.ts"
click node_db_connection "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/DatabaseConnection.ts"
click node_driver_adapter "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/DriverAdapter.ts"
click node_transactions "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/TransactionManager.ts"
click node_cli "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/eloquent.ts"
click node_scaffold_commands "https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/cli/commands"
click node_controller_generator "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/commands/makeController.ts"
click node_template_engine "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/utils/TemplateEngine.ts"
click node_scaffold_support "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/utils/ScaffoldGeneratorSupport.ts"
click node_file_writer "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/utils/fileWriter.ts"
click node_migration_seed "https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/cli/commands"
click node_cache_setup "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/cache/setupCache.ts"
click node_cache_manager "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/cache/CacheManager.ts"
click node_cache_drivers "https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/core/cache/drivers"
click node_query_cache "https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/orm/mixins/QueryCacheMixin.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_api,node_model,node_core_model,node_safe_finder,node_relationships,node_cli_user toneBlue
class node_schema_blueprint,node_schema_builder,node_db_config,node_connection_factory,node_db_connection,node_driver_adapter,node_transactions,node_database,node_cache_store toneAmber
class node_cli,node_scaffold_commands,node_controller_generator,node_template_engine,node_scaffold_support,node_file_writer,node_migration_seed toneMint
class node_cache_setup,node_cache_manager,node_cache_drivers,node_query_cache toneRose
class node_developer toneIndigo
```

## Components

### ORM runtime

- [Public API](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/index.ts): `src/index.ts`
- [Model API](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/BaseModel.ts): `src/core/model/BaseModel.ts`
- [Persistence and queries](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/CoreModel.ts): `src/core/model/CoreModel.ts`
- [Safe finders](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/model/SafeFinder.ts): `src/core/model/SafeFinder.ts`
- [Relations and mixins](https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/core/orm): `src/core/orm`

### Connections and schema

- [Schema blueprint](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/schema/SchemaBlueprint.ts): `src/core/schema/SchemaBlueprint.ts`
- [Schema builder](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/schema/SchemaBuilder.ts): `src/core/schema/SchemaBuilder.ts`
- [Database configuration](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/config/database.ts): `src/config/database.ts`
- [Connection factory](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/ConnectionFactory.ts): `src/core/connection/ConnectionFactory.ts`
- [Database connections](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/DatabaseConnection.ts): `src/core/connection/DatabaseConnection.ts`
- [Driver adapter](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/DriverAdapter.ts): `src/core/connection/DriverAdapter.ts`
- [Transactions and locks](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/connection/TransactionManager.ts): `src/core/connection/TransactionManager.ts`

### CLI workflows

- [CLI command runtime](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/eloquent.ts): `src/cli/eloquent.ts`
- [Scaffold generators](https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/cli/commands): `src/cli/commands`
- [Controller generator](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/commands/makeController.ts): `src/cli/commands/makeController.ts`
- [Template engine](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/utils/TemplateEngine.ts): `src/cli/utils/TemplateEngine.ts`
- [Scaffold support](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/utils/ScaffoldGeneratorSupport.ts): `src/cli/utils/ScaffoldGeneratorSupport.ts`
- [Artifact writer](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/cli/utils/fileWriter.ts): `src/cli/utils/fileWriter.ts`
- [Migration and seed commands](https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/cli/commands): `src/cli/commands`

### Caching

- [Cache setup](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/cache/setupCache.ts): `src/core/cache/setupCache.ts`
- [Cache manager](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/cache/CacheManager.ts): `src/core/cache/CacheManager.ts`
- [Cache drivers](https://github.com/metaldz/eloquent-orm.js/tree/ai_master/src/core/cache/drivers): `src/core/cache/drivers`
- [Query cache mixin](https://github.com/metaldz/eloquent-orm.js/blob/ai_master/src/core/orm/mixins/QueryCacheMixin.ts): `src/core/orm/mixins/QueryCacheMixin.ts`

### Other components

- **Application developer**
- **SQL / MongoDB**
- **CLI user**
- **Cache backend**

## Connections

- Application developer → Public API: uses (evidence: `README.md`)
- Public API → Model API: exports (evidence: `src/index.ts`)
- Public API → Schema blueprint: exports (evidence: `src/index.ts`)
- Public API → Schema builder: exports (evidence: `src/index.ts`)
- Public API → Cache manager: exports (evidence: `src/index.ts`)
- Public API → Transactions and locks: exports (evidence: `src/index.ts`)
- Model API → Persistence and queries: composes (evidence: `src/core/model/BaseModel.ts`)
- Model API → Relations and mixins: mixes in (evidence: `src/core/model/BaseModel.ts`)
- Model API → Query cache mixin: mixes in (evidence: `src/core/model/BaseModel.ts`)
- Persistence and queries → Safe finders: uses (evidence: `src/core/model/CoreModel.ts`)
- Persistence and queries → Connection factory: gets connection (evidence: `src/core/model/CoreModel.ts`)
- Persistence and queries → Schema blueprint: validates schema (evidence: `src/core/model/CoreModel.ts`)
- Connection factory → Database configuration: reads config (evidence: `src/core/connection/ConnectionFactory.ts`)
- Connection factory → Database connections: creates connection (evidence: `src/core/connection/ConnectionFactory.ts`)
- Database connections → SQL / MongoDB: connects (evidence: `src/core/connection/DatabaseConnection.ts`)
- Transactions and locks → Connection factory: gets connection (evidence: `src/core/connection/TransactionManager.ts`)
- Transactions and locks → Database connections: opens connection (evidence: `src/core/connection/TransactionManager.ts`)
- Transactions and locks → Driver adapter: creates adapter (evidence: `src/core/connection/TransactionManager.ts`)
- CLI user → CLI command runtime: runs commands (evidence: `README.md`)
- CLI command runtime → Scaffold generators: dispatches
- CLI command runtime → Migration and seed commands: dispatches
- Scaffold generators → Controller generator: includes (evidence: `src/cli/commands/makeController.ts`)
- Controller generator → Template engine: renders template (evidence: `src/cli/commands/makeController.ts`)
- Controller generator → Scaffold support: resolves artifact (evidence: `src/cli/commands/makeController.ts`)
- Controller generator → Artifact writer: writes output (evidence: `src/cli/commands/makeController.ts`)
- Cache setup → Cache drivers: selects drivers (evidence: `src/core/cache/setupCache.ts`)
- Cache setup → Cache manager: configures (evidence: `src/core/cache/setupCache.ts`)
- Cache manager → Cache backend: reads and writes (evidence: `src/core/cache/CacheManager.ts`)
- Query cache mixin → Cache manager: uses (evidence: `src/core/orm/mixins/QueryCacheMixin.ts`)
