Nexus Common
Nexus Common is a foundational crate that provides shared configuration, database connectors, data models and media processing utilities used throughout the Nexus indexer stack.
Overview
The nexus-common crate offers:
-
Configuration Management: TOML-based loader with default file generation, home‑dir expansion, and asynchronous loading
-
Database Connectivity:
Connect to Neo4j and Redis using dedicated connectors. Use functions such asget_neo4j_graph()andget_redis_conn()to obtain connections for executing queries and handling errors. -
Data Models:
Define core entities such as Files, Users, Posts, Tags, Notifications, and Follows. Each model provides functionality for caching, indexing, and graph operations. -
Indexing and Caching:
Utilities to index and retrieve records from Redis. Includes support for pagination, lexicographical range queries, and sorted sets. -
Shared Types and Traits:
Common types such asPagination,Timeframe, andStreamSortingalong with a collection of traits are provided to ensure a consistent interface across the Nexus backend. -
Media Processing:
Process media files with support for image and video variant creation. The crate includes processors (likeImageProcessorand a prototypeVideoProcessor) that generate different file variants (e.g. main, feed, small) and manage content types.
This crate is designed as a backbone for other services (e.g, homeserver watcher and API) crates in the Nexus stack, enabling consistent access to core functionalities and shared data structures.
Module Overview
Configuration Management
- Module:
config/ - Features:
ConfigLoader, default templates, home-dir expansion, async loading
Database Connectivity
- Module:
db/ - Features:
Neo4jConnector,RedisConnector,get_neo4j_graph(),get_redis_conn(), error handling
Data Models
The data models cover the core domain entities and their graph/cache operations:
- Files: Representing file details, blobs, and URLs
- Users: Including user details, counts, relationships, and search capabilities
- Posts: Covering post details, counts, relationships, bookmarks, and views
- Tags: Managing tag details, global taggers, and search operations
- Follows: Handling follower, following, and friends relationships
- Notifications: Representing user notifications
Shared Types
The crate provides common types and utilities (types/) that are used across different modules, such as:
Paginationfor paginated queriesTimeframefor filtering data based on time rangesStreamSortingfor ordering streams
Media Processing
- Module:
media/ - Features:
ImageProcessor,VideoProcessor,FileVariant, andVariantControllerfor automated processing pipelines
MIME-type management and storage directory configuration
Getting Started
To add nexus-common to your project, include it in your Cargo.toml dependencies:
Quick Examples
Configuration Loading
Below is an example demonstrating how to load a configuration using the provided loader trait:
use ;
use Path;
use DynError;
async
Database Connectivity
Below is an example demonstrating how to get the connectors of the data bases:
use ;
use Neo4JConfig;
use DynError;
async
Data Models & Caching
Demonstrates cache-first retrieval of domain entities, attempting to load from Redis and falling back to Neo4j if not found
use UserDetails;
use DynError;
use ;
async
Contributing
Contributions to nexus-common are welcome! Please open issues or submit pull requests on the project's repository. Follow the established coding conventions and include tests for new features.
License
This project is licensed under the MIT License.