# Example Projects

Real-world applications demonstrating Lux's unique capabilities. Clone these to learn by doing.

## API REST API

A full REST API for task management with JSON responses, routing, and CRUD operations.

### Demonstrates

- HttpServer effect
- Pattern matching for routing
- JSON serialization
- Effect tracking

    fn router(req): Response with {Http} =
        match (req.method, req.path) {
            ("GET", "/") => httpOk(welcome),
            ("GET", "/tasks") => httpOk(tasks),
            _ => httpNotFound("404")
        }

View Code

## TODO Todo App

A command-line todo application showcasing algebraic data types and pattern matching.

### Demonstrates

- ADTs for data modeling
- Pattern matching
- Recursive list operations
- Console effect

    type Priority =
        | Low
        | Medium
        | High

    type TodoItem =
        | TodoItem(Int, String, Bool, Priority)

View Code

## JSON JSON Parser

A recursive descent JSON parser demonstrating ADTs for AST representation.

### Demonstrates

- ADTs for AST
- Recursive parsing
- String manipulation
- Pure functions

    type JsonValue =
        | JsonNull
        | JsonBool(Bool)
        | JsonNumber(Int)
        | JsonString(String)
        | JsonArray(List<JsonValue>)
        | JsonObject(List<(String, JsonValue)>)

View Code

## GAME Guessing Game

A simple number guessing game demonstrating effects for randomness and I/O.

### Demonstrates

- Random effect
- Console I/O
- Recursive game loop
- User input handling

    fn playGame(): Unit
        with {Console, Random} = {
        let secret = Random.int(1, 100)
        Console.print("Guess a number!")
        guessLoop(secret, 0)
    }

View Code

## MD Markdown Converter

Convert Markdown to HTML using pattern matching and string processing.

### Demonstrates

- String manipulation
- Pattern matching
- Pure transformation
- List processing

    fn convertLine(line: String): String =
        if startsWith(line, "# ") then
            "<h1>" + rest(line, 2) + "</h1>"
        else if startsWith(line, "- ") then
            "<li>" + rest(line, 2) + "</li>"
        else "<p>" + line + "</p>"

View Code

## CALC Mini Interpreter

A tiny expression interpreter demonstrating language implementation patterns.

### Demonstrates

- ADTs for AST
- Recursive evaluation
- Environment handling
- Interpreter patterns

    type Expr =
        | Num(Int)
        | Add(Expr, Expr)
        | Mul(Expr, Expr)
        | Var(String)
        | Let(String, Expr, Expr)

View Code

## Featured: Task Manager API

### A Complete Showcase of Lux's Unique Features

This comprehensive example demonstrates all three of Lux's killer features working together.

#### 1. Algebraic Effects

Every side effect is explicit in function signatures. No hidden I/O.

#### 2. Behavioral Types

Compile-time guarantees: `is pure`, `is total`, `is idempotent`.

#### 3. Schema Evolution

Versioned types with automatic migration. Data structures evolve safely.

    // Task v1: Original data model
    type Task @v1 {
        id: String,
        title: String,
        done: Bool
    }

    // Task v2: Added priority field with migration
    type Task @v2 {
        id: String,
        title: String,
        done: Bool,
        priority: String,

        // Old tasks get "medium" priority by default
        from @v1 = {
            id: old.id,
            title: old.title,
            done: old.done,
            priority: "medium"
        }
    }

    // Pure, total, idempotent business logic
    fn validateTitle(title: String): Result<String, String>
        is pure, total =
        if String.length(title) == 0 then
            Err("Title cannot be empty")
        else
            Ok(title)

View Full Code Learn About Effects

## Build Your Own

Ready to start building with Lux?

Install Lux Take the Tour Browse Examples