reinhardt-apps
Application configuration and registry for Reinhardt framework.
Overview
reinhardt-apps provides the application configuration system inspired by Django's INSTALLED_APPS. It enables:
- Application discovery and registration
- App-specific configuration
- Integration with migrations, admin panel, and other framework features
Important Note: Unlike Django, installed_apps! in Reinhardt is for user applications only. Built-in framework features (auth, sessions, admin, etc.) are enabled via Cargo feature flags, not through installed_apps!.
Installation
Add reinhardt to your Cargo.toml:
[]
= { = "0.2.2", = "reinhardt-web", = ["apps"] }
# Or use a preset:
# reinhardt = { version = "0.2.2", package = "reinhardt-web", features = ["standard"] } # Recommended
# reinhardt = { version = "0.2.2", package = "reinhardt-web", features = ["full"] } # All features
Then import app features:
use ;
Note: App features are included in the standard and full feature presets.
Usage
Define installed apps using the installed_apps! macro:
use installed_apps;
installed_apps!
For built-in framework features, use Cargo feature flags:
[]
= {
version = "0.2.2",
= "reinhardt-web",
= ["auth", "sessions", "admin"]
}
Then import them directly in your code:
use *;
use *;
use *;
What the Macro Generates
The installed_apps! macro automatically generates:
// Generated enum
// Display implementation
// Helper methods
Features
Type-safe App References
Use the generated enum for type-safe app references:
// Type-safe reference
let app = Users;
println!; // "users"
// List all apps
let all = all_apps;
Automatic Discovery
The app registry enables automatic discovery for:
- Migrations: Discover migration files for each app
- Admin Panel: Auto-register models from each app
- Static Files: Collect static files from app directories
- Templates: Load templates from app template directories
Framework Integration
The installed_apps! macro integrates with:
// src/config/apps.rs
use installed_apps;
installed_apps!
Framework features are enabled separately via Cargo.toml:
[]
= {
version = "0.2.2",
= "reinhardt-web",
= ["auth", "sessions", "admin", "static-files"]
}
App Naming Conventions
User Apps
User-defined apps use simple names matching their directory:
users: "users",
blog: "blog",
api: "api",
Framework Features (NOT via installed_apps!)
Framework features are enabled via Cargo feature flags:
| Feature | Cargo.toml | Import |
|---|---|---|
| Authentication | features = ["auth"] |
use reinhardt::auth::*; |
| Admin Panel | features = ["admin"] |
use reinhardt::admin::*; |
| Sessions | features = ["sessions"] |
use reinhardt::auth::sessions::*; |
| Static Files | features = ["static-files"] |
use reinhardt::staticfiles::*; |
| Database | features = ["database"] |
use reinhardt::db::*; |
Compile-time Validation
The macro performs compile-time validation:
- Path Format: Validates module path format
- Module Existence: Checks that
reinhardt.*modules exist (for framework references) - Unique Names: Ensures app names are unique
// Valid: User app
installed_apps!
// Invalid: Non-existent framework module
installed_apps!
Note: If you see compile errors about missing reinhardt.contrib.* modules, this is because those modules don't exist. Use Cargo feature flags instead (see above).
Example Project Structure
my-project/
├── src/
│ ├── config/
│ │ ├── apps.rs # installed_apps! definition
│ │ ├── settings.rs
│ │ └── urls.rs
│ └── apps/
│ ├── users/
│ │ ├── lib.rs
│ │ ├── models.rs
│ │ └── views.rs
│ └── posts/
│ ├── lib.rs
│ ├── models.rs
│ └── views.rs
└── Cargo.toml
// src/config/apps.rs
use installed_apps;
installed_apps!
# Cargo.toml
[]
= {
version = "0.2.2",
= "reinhardt-web",
= ["auth", "sessions", "database"]
}
Integration with Other Components
Migrations
// Migrations automatically discover apps
use MigrationRunner;
let runner = new;
let installed = all_apps;
runner.migrate.await?;
Admin Panel
// Admin panel auto-discovers models from apps
use AdminSite;
let admin = new;
admin.autodiscover.await?;
Settings Integration
// src/config/settings.rs
use Settings;
Migrating from Django
If you're familiar with Django's INSTALLED_APPS, here are the key differences:
Django (Python):
=
Reinhardt (Rust):
# Cargo.toml
[]
= { = "0.2.2", = "reinhardt-web", = ["auth", "admin"] }
// src/config/apps.rs
installed_apps!
Why the difference?
- ✅ Compile-time optimization: Unused features are not compiled
- ✅ Smaller binaries: Only include what you need
- ✅ Type safety: Features are validated at compile time
License
Licensed under the BSD 3-Clause License.