What is a Module?
A Module in Modelence is similar to a feature module in other frameworks. It groups related functionality together, making your codebase more maintainable and easier to reason about.Module Structure
A typical module includes:- Stores - MongoDB collection definitions
- Queries - Read operations that fetch data
- Mutations - Write operations that modify data
- Configuration - Module-specific settings
- Cron Jobs - Scheduled tasks (optional)
Stores
Stores define your MongoDB collections with schemas, indexes, and custom methods. Including stores in your module ensures they’re automatically provisioned when the server starts.Authentication & Authorization
You can restrict access to queries and mutations using authentication requirements:Queries
Queries are functions that retrieve data without modifying it. They’re similar to GET endpoints in REST or queries in GraphQL.Query Parameters
Queries receive two arguments:- Input parameters - Data passed from the client
- Context - Server-side context including:
user- Current authenticated user (if logged in)req- Express request objectres- Express response object