Project Structure
Understanding how Ryx is organized will help you navigate the codebase and contribute effectively.
High-Level Layoutโ
Ryx/
โโโ Cargo.toml # Workspace configuration
โโโ pyproject.toml # maturin build config
โโโ Makefile # Dev shortcuts (dev, build, test, clean)
โ
โโโ ryx-core/ # CORE TYPES (Rust)
โ โโโ src/ # Connection/Transaction enums, Base types
โ
โโโ ryx-backend/ # DB ADAPTERS (Rust)
โ โโโ src/ # Executor, RowView, Decoding logic
โ
โโโ ryx-query/ # SQL COMPILER (Rust)
โ โโโ src/ # AST, Compiler, Lookup registry
โ
โโโ ryx-python/ # PyO3 BINDINGS (Rust)
โ โโโ src/ # Module entry, Type bridge, Bound objects
โ
โโโ ryx/ # PYTHON PACKAGE
โ โโโ __init__.py # Public API surface
โ โโโ __main__.py # CLI (python -m ryx)
โ โโโ models.py # Model, Metaclass, Manager
โ โโโ queryset.py # QuerySet, Q, aggregates
โ โโโ fields.py # 30+ field types
โ โโโ validators.py # 12 validators
โ โโโ signals.py # Signal system + 8 built-in signals
โ โโโ transaction.py # Async transaction context manager
โ โโโ relations.py # select_related / prefetch_related
โ โโโ descriptors.py # FK/M2M attribute access
โ โโโ exceptions.py # Exception hierarchy
โ โโโ bulk.py # Bulk operations
โ โโโ cache.py # Pluggable query cache
โ โโโ migrations/
โ โโโ state.py # SchemaState + diff engine
โ โโโ ddl.py # Backend-aware DDL generator
โ โโโ runner.py # MigrationRunner
โ โโโ autodetect.py # Autodetector + file writer
โ
โโโ tests/ # Test suites
โโโ examples/ # 9 progressive examples
Two Layers, One Packageโ
Ryx is split into two layers that work together:
Rust Engine (Workspace)โ
The compiled engine is split into specialized crates for maintainability:
ryx-coreโ Defines the foundational types and traits.ryx-queryโ Transforms Python-like queries into optimized SQL.ryx-backendโ Handles database communication and zero-allocation row decoding.ryx-pythonโ The PyO3 bridge that exposes Rust logic to Python.
Python Package (ryx/)โ
The ergonomic API that handles:
- Model definitions โ Declarative class-based models with metaclass magic
- Query building โ Chainable, lazy QuerySet API
- Field types โ 30+ fields with validation and type conversion
- Migrations โ Schema introspection, diff detection, DDL generation
- Signals โ Observer pattern for lifecycle events
- CLI โ Management commands for migrations, shell, etc.
How They Connectโ
# Python side
posts = await Post.objects.filter(active=True).limit(10)
โ
โผ
# QuerySet builds a QueryNode (Python โ Rust via PyO3)
โ
โผ
# Rust compiles QueryNode โ SQL
# SELECT * FROM "posts" WHERE "active" = ? LIMIT 10
โ
โผ
# Rust executes via sqlx and returns rows
โ
โผ
# Python decodes rows into Model instances
Key Design Principlesโ
- Immutable builders โ Every QuerySet method returns a new QuerySet
- GIL minimization โ Rust holds no GIL during SQL execution
- Async-native โ Everything is async from the ground up
- Sync-compatible โ Bridge helpers for sync environments
- Backend-agnostic โ Single code path for PG, MySQL, SQLite
Next Stepsโ
โ Models โ Define your first models โ Rust Core Internals โ Deep dive into the compiled engine