Quick Start
This guide will walk you through creating your first Azu application in just a few minutes. By the end of this tutorial, you'll have a running web application with a database, complete with CRUD operations.
Prerequisites
Database server running (PostgreSQL, MySQL, or SQLite)
Basic familiarity with Crystal syntax
Step 1: Create a New Project
Let's create a blog application:
azu new my_blog --database postgresThis command will:
Create a new directory called
my_blogGenerate the complete project structure
Configure PostgreSQL as the database
Set up all necessary dependencies
Initialize a Git repository
Output:
Step 2: Navigate to Your Project
Let's examine the generated project structure:
Step 3: Set Up the Database
Create your database:
Output:
Run initial migrations:
Output:
Step 4: Start the Development Server
Launch the development server with hot reloading:
Output:
Open your browser and navigate to http://localhost:4000. You should see the Azu welcome page!
Step 5: Generate Your First Resource
Let's create a complete blog post resource with CRUD operations:
Output:
Step 6: Create the Database Migration
Generate a migration for the posts table:
Output:
Run the migration:
Output:
Step 7: Explore Your Application
The development server should automatically reload your application. Visit these URLs:
Homepage:
http://localhost:4000Posts Index:
http://localhost:4000/postsNew Post:
http://localhost:4000/posts/new
Generated Files Explained
1. Model (src/models/post.cr)
src/models/post.cr)2. Endpoint (src/endpoints/posts/index_endpoint.cr)
src/endpoints/posts/index_endpoint.cr)3. Contract (src/contracts/posts/create_contract.cr)
src/contracts/posts/create_contract.cr)4. Page (src/pages/posts/index_page.cr)
src/pages/posts/index_page.cr)Step 8: Test Your Application
Run the test suite:
Output:
Step 9: Add Sample Data
Seed your database with sample data:
Output:
Step 10: Customize Your Application
Add Custom Styling
Edit public/assets/css/cover.css to customize your application's appearance:
Add a Custom Endpoint
Generate a custom endpoint for published posts only:
Edit the generated endpoint:
Next Steps
Congratulations! You've successfully created your first Azu application. Here's what you can explore next:
Immediate Next Steps
Add Authentication - Secure your blog
Add Real-time Features - Live comments or reactions
Create an API - Build a REST API for your blog
Add Testing - Write comprehensive tests
Learn More
Command Reference - All available CLI commands
Generators Guide - Detailed generator documentation
Development Workflows - Common development patterns
Configuration - Advanced configuration options
Advanced Features
Database Relationships - Model associations
Background Jobs - Async processing
Deployment - Deploy to production
Performance Optimization - Scale your application
Community Examples
Blog Tutorial - Extended blog with user authentication
API Tutorial - Build a complete REST API
Chat Tutorial - Real-time chat application
Troubleshooting
Server Won't Start
Port Already in Use
Database Connection Error
Hot Reloading Not Working
Congratulations! π You've built your first Azu application. The development server will automatically reload when you make changes, so start experimenting and building something amazing!
Need Help? Check out the troubleshooting guide or create an issue on GitHub.
Last updated