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 postgres

This command will:

  • Create a new directory called my_blog

  • Generate 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:4000

  • Posts Index: http://localhost:4000/posts

  • New Post: http://localhost:4000/posts/new

Generated Files Explained

1. Model (src/models/post.cr)

2. Endpoint (src/endpoints/posts/index_endpoint.cr)

3. Contract (src/contracts/posts/create_contract.cr)

4. Page (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

  1. Add Authentication - Secure your blog

  2. Add Real-time Features - Live comments or reactions

  3. Create an API - Build a REST API for your blog

  4. Add Testing - Write comprehensive tests

Learn More

Advanced Features

Community Examples

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