# seaql/sea-orm architecture

> Architecture diagram of the GitHub repository seaql/sea-orm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/seaql/sea-orm
- Repository: https://github.com/seaql/sea-orm

## Overview

##### Layer Structure (Top to Bottom)

**┌─ Application Layer ─────────────────────┐**
- Entity Models                         │
- Active Models                         │
- Relation Definitions                  │
- ┘

Second Layer (ORM Core):
**┌─ Query Building ─┐ ┌─ Execution ──────┐**
- Select        │ │ - Connection Pool │
- Insert        │ │ - Transaction    │
- Update        │ │ - Cursor         │
- Delete        │ │ - Paginator      │
- ┘ └─────────────────────┘

Third Layer (Database Abstraction):
**┌─ Database Drivers ────────────────────┐**
- SQLx Implementations:                 │
- PostgreSQL                         │
- MySQL                              │
- SQLite                             │
- ┘

##### Key Relationships to Highlight

- Entity definitions → Query Builder
- Query Builder → Executor
- Executor → Database Drivers
- Migration System → Database
- Codegen → Entity Definitions

##### Integration Points

Connections to:
- Web Frameworks (Actix, Axum, Rocket)
- GraphQL (Seaography)
- Admin Dashboards
- gRPC Services

##### Special Features to Highlight

Create callouts for:
- Async Support
- Dynamic Query Building
- Mock Testing Capabilities
- Migration Management
- Code Generation

##### Data Flow Indicators

- Sync Operations (Solid)

##### Additional Notes

Annotations for:
- Configuration Points
- Extension Points
- Testing Integration
- Performance Monitoring

- Async-first design
- Dynamic query building
- Service-oriented architecture
- Testing capabilities
- Integration flexibility

This system design should help developers understand both the high-level architecture and the detailed interactions between components, while highlighting SeaORM's unique features as an async ORM for Rust.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#333
    classDef db fill:#90EE90,stroke:#333
    classDef integration fill:#FFB347,stroke:#333
    classDef tools fill:#DDA0DD,stroke:#333
    classDef app fill:#FFE4B5,stroke:#333

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        EntityModels["Entity Models"]
        ActiveModels["Active Models"]
        Relations["Relation Definitions"]
    end

    %% Core ORM Layer
    subgraph CoreLayer["ORM Core"]
        %% Query Building
        subgraph QueryBuilder["Query Building"]
            Select["Select"]
            Insert["Insert"]
            Update["Update"]
            Delete["Delete"]
        end

        %% Execution
        subgraph Execution["Execution"]
            ConnPool["Connection Pool"]
            Transaction["Transaction"]
            Cursor["Cursor"]
            Paginator["Paginator"]
        end
    end

    %% Database Layer
    subgraph DBLayer["Database Layer"]
        Postgres["PostgreSQL"]
        MySQL["MySQL"]
        SQLite["SQLite"]
    end

    %% Supporting Systems
    subgraph Support["Supporting Systems"]
        CodeGen["Code Generation"]
        Macros["Macro System"]
        CLI["CLI Tools"]
        Migration["Migration System"]
    end

    %% Integration Points
    subgraph Integrations["Framework Integrations"]
        Actix["Actix"]
        Axum["Axum"]
        Rocket["Rocket"]
        GraphQL["GraphQL/Seaography"]
    end

    %% Relationships
    EntityModels --> QueryBuilder
    ActiveModels --> QueryBuilder
    Relations --> QueryBuilder
    QueryBuilder --> Execution
    Execution --> DBLayer
    Migration --> DBLayer
    CodeGen --> EntityModels
    
    %% Integration Connections
    Execution --> Integrations
    
    %% Click Events
    click EntityModels "https://github.com/SeaQL/sea-orm/tree/master/src/entity/"
    click ActiveModels "https://github.com/SeaQL/sea-orm/blob/master/src/entity/active_model.rs"
    click QueryBuilder "https://github.com/SeaQL/sea-orm/tree/master/src/query/"
    click Select "https://github.com/SeaQL/sea-orm/blob/master/src/query/select.rs"
    click Insert "https://github.com/SeaQL/sea-orm/blob/master/src/query/insert.rs"
    click Update "https://github.com/SeaQL/sea-orm/blob/master/src/query/update.rs"
    click Delete "https://github.com/SeaQL/sea-orm/blob/master/src/query/delete.rs"
    click Execution "https://github.com/SeaQL/sea-orm/tree/master/src/executor/"
    click ConnPool "https://github.com/SeaQL/sea-orm/blob/master/src/database/connection.rs"
    click Transaction "https://github.com/SeaQL/sea-orm/blob/master/src/database/transaction.rs"
    click Migration "https://github.com/SeaQL/sea-orm/tree/master/sea-orm-migration/src/"
    click CodeGen "https://github.com/SeaQL/sea-orm/tree/master/sea-orm-codegen/src/"
    click Macros "https://github.com/SeaQL/sea-orm/tree/master/sea-orm-macros/src/"
    click CLI "https://github.com/SeaQL/sea-orm/tree/master/sea-orm-cli/src/"
    click Actix "https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example/"
    click Axum "https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example/"
    click Rocket "https://github.com/SeaQL/sea-orm/tree/master/sea-orm-rocket/"

    %% Style Applications
    class EntityModels,ActiveModels,Relations app
    class Select,Insert,Update,Delete,ConnPool,Transaction,Cursor,Paginator core
    class Postgres,MySQL,SQLite db
    class CodeGen,Macros,CLI,Migration tools
    class Actix,Axum,Rocket,GraphQL integration
```
