Prerequisites
Before you begin, ensure you have the following installed on your system:- Rust 1.70+ - The Rust programming language and toolchain
- PostgreSQL 12+ - Primary database system
- sqlx-cli - Database migration tool for SQLx
Ironclad uses PostgreSQL as its primary database. MongoDB support is optional and can be configured separately.
Installing Rust
If you don’t have Rust installed, download and install it using rustup:Download rustup
Visit rustup.rs or run the following command:
Installing PostgreSQL
Install PostgreSQL 12 or higher for your operating system:Installing SQLx CLI
The SQLx CLI tool is required for running database migrations:The
--features postgres flag installs only PostgreSQL support. You can add other databases if needed.Project Setup
Configure environment variables
Copy the example environment file and configure your settings:Edit the
.env file with your configuration:.env
Run database migrations
Apply the database schema using SQLx migrations:This will create the necessary tables including users, roles, and test items.
Verify Installation
Once the server is running, you should see output similar to:Optional: MongoDB Setup
If you want to use MongoDB alongside PostgreSQL:Install MongoDB
Install MongoDB following the official instructions.
Configuration Reference
Server Configuration
| Variable | Default | Description |
|---|---|---|
SERVER_HOST | 127.0.0.1 | Server bind address |
SERVER_PORT | 8080 | Server port |
ENVIRONMENT | development | Environment mode (development/production) |
Database Configuration
| Variable | Default | Description |
|---|---|---|
DATABASE_URL | - | PostgreSQL connection string |
DB_MAX_CONNECTIONS | 5 | Maximum database connections in pool |
Security Configuration
| Variable | Default | Description |
|---|---|---|
BCRYPT_COST | 12 | Bcrypt hashing cost (4-31) |
JWT_SECRET | - | Secret key for JWT token signing |
JWT_EXPIRATION | 86400 | Token expiration time in seconds (24 hours) |
Bcrypt Cost: The default cost of 12 provides good security. Lower values (4-8) should only be used for local testing as they are insecure. Higher values increase CPU load significantly.
Common Development Commands
Here are some useful commands for development:Troubleshooting
Database Connection Failed
If you see database connection errors:- Verify PostgreSQL is running:
pg_isready - Check your
DATABASE_URLin.env - Ensure the database exists:
psql -l - Test the connection:
cargo run --bin ironclad -- db-check
Port Already in Use
If port 8080 is already in use, changeSERVER_PORT in your .env file:
Migration Errors
If migrations fail:Next Steps
Now that you have Ironclad installed, you’re ready to build your first endpoint:- Quick Start Tutorial - Build your first API endpoint
- Project Structure - Understand the codebase organization