Skip to content

Arete-Innovations/catalyst

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

91 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”₯ Catalyst Web Framework

License Rust

🌟 Overview

Catalyst is a "suckless" web framework for Rust that emphasizes simplicity, modularity, and performance. It combines powerful technologies:

  • πŸš€ Rocket for web server and routing
  • β›½ Diesel for ORM and database operations
  • πŸ”§ Tera for HTML templating
  • ⚑ HTMX for interactive frontend with minimal JavaScript
  • 🎨 MaterializeCSS for styling

🧘 The "Suckless" Philosophy

Catalyst embraces the suckless philosophy with these core principles:

πŸ” Simplicity

  • Code should be simple, minimal, and readable
  • Avoid unnecessary abstractions and dependencies
  • Prefer explicit over implicit behavior
  • Less code means fewer bugs and easier maintenance

πŸ› οΈ Modularity

  • Small, focused components that do one thing well
  • Compose functionality from minimal building blocks
  • Easy to understand, extend, and replace parts
  • Clear separation between generated and custom code

🎯 Pragmatism

  • Practical solutions over theoretical purity
  • Embrace proven technologies instead of trendy frameworks
  • Focus on developer productivity and maintainable code
  • Balance between hand-written and generated code

πŸš€ Performance

  • Lightweight and efficient implementations
  • Minimal runtime overhead
  • Server-side rendering with targeted interactivity
  • Built with Rust for memory safety and speed

🧠 Mental Model

  • Consistent patterns throughout the codebase
  • Clear, predictable structure
  • Low cognitive load for developers
  • Easy to reason about the system holistically

πŸ“‹ Key Features

πŸ” Authentication System

Catalyst includes a robust authentication system in the auth/ directories:

  • User Model (models/auth/users.rs): Complete user management with:

    • Password hashing and verification using bcrypt
    • Role-based permissions (admin, user, custom roles)
    • Account activation/deactivation
    • Profile management
    • Password reset workflows
    • Security features (transaction-based updates)
  • Auth Routes (routes/public/auth.rs): Ready-to-use authentication endpoints:

    • Login and registration
    • Password reset/recovery
    • Account verification
  • Auth Middleware (middleware/guards.rs & middleware/jwt.rs):

    • JWT token authentication
    • Role-based authorization guards
    • Session management
  • Auth Templates (templates/auth/):

    • Login and registration forms
    • Password reset interfaces

πŸ“ Generated vs. Custom Folders

The framework follows a clear separation between generated and custom code:

  • Generated Folders (*/generated/):

    • ⚠️ Files in these directories are automatically generated by Blast
    • ⚠️ Manual changes will be overwritten when running generation commands
    • Generated from database schema and migrations
    • Contains boilerplate CRUD operations and database models
  • Custom Folders (*/custom/):

    • βœ… Safe places for your custom implementation
    • Never overwritten by the framework
    • Automatically imported via the module system
    • Ideal for business logic and application-specific code

This separation ensures that you can regenerate database models without losing your custom implementation logic.

πŸ“ The cata_log! Macro

The cata_log! macro provides structured logging with source location tracking:

// Basic usage with different log levels
cata_log!(Debug, "Processing user request");
cata_log!(Info, "User logged in successfully");
cata_log!(Warning, "Rate limit approaching");
cata_log!(Error, "Database connection failed");
cata_log!(Trace, "Function enter: process_payment");

The actual implementation from services/logger.rs provides:

  • πŸ”„ Automatic file name, line number, and module path inclusion
  • 🎨 Color-coded output in the console by log level
  • ⏱️ Unix timestamp and local time with timezone
  • πŸ—‚οΈ Automatic log file organization by log level
  • πŸ’Ύ File logging without ANSI color codes
  • 🚨 Integrated panic hook for capturing application crashes
  • πŸ”„ Automatic log rotation and organization

Example output format:

1708562309-2025-01-01 12:34:56 EST [INFO] πŸ” [src/routes/auth.rs:42::login] User login successful: johndoe

πŸ›οΈ Framework Architecture

The framework follows a clear layered architecture that separates concerns:

  1. Routing Layer (via Rocket in routes/):

    • Handles HTTP requests and routing
    • Separated into public and private routes
    • Uses Rocket's path, query, and form extractors
    • Returns appropriate responses (Template, JSON, Redirect)
  2. Middleware Layer (in middleware/):

    • JWT authentication and token validation
    • Request guards for authorization
    • Response caching and compression
    • Error catchers for handling exceptions
  3. Service Layer (in services/):

    • Contains business logic separate from routes
    • Provides UI component builders
    • Manages file storage operations
    • Implements logging services and scheduled tasks
  4. Model Layer (in models/):

    • Implements domain logic with database operations
    • Uses transaction-based operations for data integrity
    • Provides CRUD operations and validation
    • Authentication and user management
  5. Data Layer (via Diesel ORM in database/):

    • Schema definitions and migrations
    • Connection pooling and management
    • Seed data for initial setup
  6. View Layer (via Tera templates in templates/):

    • Organizes templates by functional area
    • Uses partials for reusable components
    • Provides layouts and includes
  7. Asset Management (in assets/ and compiled to public/):

    • CSS Management:
      • SCSS compilation with automatic minification
      • All CSS files output as .min.css for consistent imports
      • Custom CSS files from src/assets/css
    • JS Processing:
      • All JS files output as .min.js
      • Organized in library-specific folders
    • Directory Structure:
      • /public/css/ - For all CSS files
      • /public/js/ - For all JavaScript files
      • /public/fonts/ - For all font files
    • Environment Handling:
      • Production: Minified content with .min.css/.min.js extensions
      • Development: Readable content with .min.css/.min.js extensions

πŸ“Š Project Structure

Catalyst projects follow this standard structure:

my_project/
β”œβ”€β”€ Cargo.toml                # Rust dependencies
β”œβ”€β”€ Catalyst.toml             # Framework configuration
β”œβ”€β”€ Rocket.toml               # Rocket server configuration
β”œβ”€β”€ diesel.toml               # Diesel ORM configuration
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs               # Application entry point
β”‚   β”œβ”€β”€ lib.rs                # Library exports
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/               # Routes
β”‚   β”‚   β”œβ”€β”€ mod.rs            # Route module exports
β”‚   β”‚   β”œβ”€β”€ public/           # Public routes accessible without authentication
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.rs       # Authentication routes (login, register)
β”‚   β”‚   β”‚   β”œβ”€β”€ home.rs       # Homepage and public pages
β”‚   β”‚   β”‚   └── mod.rs        # Public routes module exports
β”‚   β”‚   └── private/          # Protected routes requiring authentication
β”‚   β”‚       β”œβ”€β”€ admin.rs      # Admin panel routes
β”‚   β”‚       β”œβ”€β”€ api.rs        # API endpoints
β”‚   β”‚       β”œβ”€β”€ user.rs       # User dashboard routes
β”‚   β”‚       └── mod.rs        # Private routes module exports
β”‚   β”‚
β”‚   β”œβ”€β”€ models/               # Database models
β”‚   β”‚   β”œβ”€β”€ mod.rs            # Model module exports
β”‚   β”‚   β”œβ”€β”€ auth/             # Authentication models
β”‚   β”‚   β”‚   β”œβ”€β”€ users.rs      # User model with authentication methods
β”‚   β”‚   β”‚   └── mod.rs        # Auth models exports
β”‚   β”‚   β”œβ”€β”€ custom/           # Custom user-defined models (never overwritten)
β”‚   β”‚   β”‚   └── mod.rs        # Custom models exports
β”‚   β”‚   └── generated/        # Auto-generated models (don't edit!)
β”‚   β”‚       └── mod.rs        # Generated models exports
β”‚   β”‚
β”‚   β”œβ”€β”€ structs/              # Data structures
β”‚   β”‚   β”œβ”€β”€ mod.rs            # Struct module exports
β”‚   β”‚   β”œβ”€β”€ auth/             # Authentication structs
β”‚   β”‚   β”‚   β”œβ”€β”€ users.rs      # User structs (DTO, form structs)
β”‚   β”‚   β”‚   └── mod.rs        # Auth structs exports
β”‚   β”‚   β”œβ”€β”€ custom/           # Custom user-defined structs (never overwritten)
β”‚   β”‚   β”‚   β”œβ”€β”€ insertable/   # Custom insertable structs
β”‚   β”‚   β”‚   └── mod.rs        # Custom structs exports
β”‚   β”‚   └── generated/        # Auto-generated structs (don't edit!)
β”‚   β”‚       β”œβ”€β”€ insertable/   # Generated insertable structs
β”‚   β”‚       β”‚   └── mod.rs    # Generated insertable exports
β”‚   β”‚       └── mod.rs        # Generated structs exports
β”‚   β”‚
β”‚   β”œβ”€β”€ middleware/           # Rocket request guards and middleware
β”‚   β”‚   β”œβ”€β”€ mod.rs            # Middleware module exports
β”‚   β”‚   β”œβ”€β”€ catchers.rs       # Error handlers
β”‚   β”‚   β”œβ”€β”€ guards.rs         # Authentication guards
β”‚   β”‚   β”œβ”€β”€ jwt.rs            # JWT token handling
β”‚   β”‚   β”œβ”€β”€ cache.rs          # Response caching
β”‚   β”‚   └── compress.rs       # Response compression
β”‚   β”‚
β”‚   β”œβ”€β”€ services/             # Business logic layer
β”‚   β”‚   β”œβ”€β”€ mod.rs            # Services module exports
β”‚   β”‚   β”œβ”€β”€ builders/         # UI builders for components
β”‚   β”‚   β”‚   β”œβ”€β”€ context.rs    # Template context builder
β”‚   β”‚   β”‚   β”œβ”€β”€ list.rs       # List component builder
β”‚   β”‚   β”‚   β”œβ”€β”€ select.rs     # Dropdown builder
β”‚   β”‚   β”‚   β”œβ”€β”€ table.rs      # HTML table builder
β”‚   β”‚   β”‚   └── mod.rs        # Builder module exports
β”‚   β”‚   β”œβ”€β”€ default/          # Default framework services
β”‚   β”‚   β”‚   β”œβ”€β”€ logger.rs     # Logging services
β”‚   β”‚   β”‚   β”œβ”€β”€ storage.rs    # File storage services
β”‚   β”‚   β”‚   └── cronjobs.rs   # Scheduled tasks
β”‚   β”‚   └── sparks/           # User-defined service extensions
β”‚   β”‚
β”‚   β”œβ”€β”€ assets/               # Frontend assets
β”‚   β”‚   β”œβ”€β”€ css/              # CSS files
β”‚   β”‚   β”œβ”€β”€ js/               # JavaScript files
β”‚   β”‚   β”œβ”€β”€ img/              # Images
β”‚   β”‚   β”œβ”€β”€ locale/           # Internationalization files
β”‚   β”‚   β”‚   └── en.json       # English translations
β”‚   β”‚   └── sass/             # SCSS source files
β”‚   β”‚       └── components/   # SCSS components
β”‚   β”‚
β”‚   β”œβ”€β”€ database/             # Database connection and migrations
β”‚   β”‚   β”œβ”€β”€ mod.rs            # Database module exports
β”‚   β”‚   β”œβ”€β”€ db.rs             # Connection pool management
β”‚   β”‚   β”œβ”€β”€ schema.rs         # Database schema (generated by Diesel)
β”‚   β”‚   β”œβ”€β”€ migrations/       # Database migrations
β”‚   β”‚   └── seeds/            # Seed data for database
β”‚   β”‚
β”‚   └── bin/                  # Cronjob executables
β”‚
β”œβ”€β”€ templates/                # Tera template files
β”‚   β”œβ”€β”€ index.html.tera       # Main index template
β”‚   β”œβ”€β”€ admin/                # Admin panel templates
β”‚   β”‚   └── index.html.tera   # Admin dashboard
β”‚   β”œβ”€β”€ auth/                 # Authentication templates
β”‚   β”‚   β”œβ”€β”€ login.html.tera   # Login form
β”‚   β”‚   └── register.html.tera # Registration form
β”‚   β”œβ”€β”€ user/                 # User dashboard templates
β”‚   β”‚   └── index.html.tera   # User homepage
β”‚   β”œβ”€β”€ oops/                 # Error pages
β”‚   β”‚   └── index.html.tera   # Error page template
β”‚   └── partials/             # Reusable template parts
β”‚       β”œβ”€β”€ header.tera       # Page header
β”‚       β”œβ”€β”€ footer.tera       # Page footer
β”‚       └── navbar.tera       # Navigation bar
β”‚
β”œβ”€β”€ public/                   # Static files (auto-generated)
β”‚
└── storage/                  # Storage directory
    β”œβ”€β”€ logs/                 # Log files
    β”‚   β”œβ”€β”€ debug.log         # Debug level logs
    β”‚   β”œβ”€β”€ error.log         # Error level logs
    β”‚   β”œβ”€β”€ info.log          # Info level logs
    β”‚   β”œβ”€β”€ server.log        # Server logs
    β”‚   └── warning.log       # Warning level logs
    └── blast/                # Blast utilities

πŸ“ Configuration System

Catalyst uses Catalyst.toml as its main configuration file with a hierarchical structure that controls all aspects of your application:

Core Settings

[settings]
# Controls environment-specific behavior (dev/prod)
environment = "dev"
# Toggle compiler warnings display in console
show_compiler_warnings = false
# Project name used in many auto-generated features
project_name = "my_awesome_app"

Code Generation Configuration

[codegen]
# Directory paths for generated code
structs_dir = "src/structs/generated"
models_dir = "src/models/generated"
schema_file = "src/database/schema.rs"

# Post-generation hooks - scripts to run after code generation
[codegen.hooks]
enabled = true
post_structs = [
  "scripts/format_structs.sh",
  "cargo fmt"
]
post_models = [
  "scripts/validate_models.sh"
]
post_any = [
  "scripts/notify_generation_complete.sh"
]

# Tables to ignore in code generation
[codegen.models]
ignore = ["migrations", "schema_migrations"]

# Struct generation configuration
[codegen.structs]
# Tables to ignore in struct generation
ignore = ["migrations", "schema_migrations"]
# Traits to derive on generated structs
derives = [
  "Debug",
  "Queryable",
  "Clone",
  "Serialize",
  "Deserialize"
]
# Automatic imports for generated structs
imports = [
  "serde::Serialize",
  "serde::Deserialize",
  "diesel::Queryable"
]

🌍 Locale Management System

Catalyst includes a sophisticated internationalization system that's fully integrated with the framework:

Structure and Organization

Locale files are JSON-structured with a hierarchical organization:

{
  "app": {
    "name": "My Application",
    "welcome": "Welcome to our app!"
  },
  "nav": {
    "home": "Home",
    "about": "About",
    "login": "Log in",
    "register": "Register"
  },
  "pages": {
    "home": {
      "title": "Welcome Home",
      "subtitle": "Your journey starts here"
    },
    "about": {
      "title": "About Us",
      "team": {
        "title": "Our Team",
        "description": "Meet the people who make it happen"
      }
    }
  },
  "errors": {
    "notFound": "Page not found",
    "serverError": "Something went wrong"
  }
}

Advanced Features

  • Language Detection: Automatic language detection from browser settings
  • Fallbacks: Configurable fallback languages when translations are missing
  • Dev Mode: Shows missing translation keys in development
  • Pluralization Rules: Built-in support for proper pluralization
  • Language Switching: Easy language switching with session persistence

⚑ HTMX Integration

Catalyst integrates HTMX for creating dynamic, interactive web experiences with minimal JavaScript:

Server-Side Templates With Client-Side Interactivity

The framework encourages using HTMX for common web interactions:

<!-- Example of a dynamic form submission -->
<form hx-post="/auth/login" hx-target="#response-div">
  <input name="username" type="text">
  <input name="password" type="password">
  <button type="submit">Login</button>
</form>

<!-- Content loading when element enters viewport -->
<div hx-get="/api/dashboard-stats" hx-trigger="revealed">
  <p>Loading dashboard stats...</p>
</div>

<!-- Lazy-loaded content -->
<div hx-get="/api/recent-activity" hx-trigger="load delay:500ms">
  <div class="spinner"></div>
</div>

πŸš€ Getting Started

The easiest way to get started with Catalyst is to use the Blast CLI tool:

# Install Blast
git clone https://github.com/Arete-Innovations/blast
cd blast
./install_blast.sh

# Create a new Catalyst project
blast new my_project
cd my_project

# Initialize the project with database and assets
blast init

# Start the development server
blast serve

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“œ License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the LICENSE file for details.

The AGPL-3.0 is a strong copyleft license that requires making the complete source code available to users who interact with the software over a network. This ensures that all modifications and improvements remain free and open source.

About

πŸ”₯ Catalyst - THE Rust framework where webdev sucks less

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5