01: Creating Your Project
Use the Igniter.js CLI to scaffold a production-ready Next.js application
The Igniter.js CLI
The Igniter.js CLI is your best friend for building applications with Igniter.js. It's a powerful command-line tool that:
- ๐๏ธ Scaffolds new projects with interactive setup
- ๐ Generates features automatically from Prisma schemas
- ๐ Creates controllers and procedures with proper structure
- ๐ Generates TypeScript client and OpenAPI docs automatically
- ๐ Runs development server with hot-reload and interactive dashboard
Think of it as your personal assistant that handles all the boilerplate so you can focus on building features.
Creating Your Project
Let's create your link shortening SaaS! Open your terminal and run:
npx @igniter-js/cli init shortifyThis command launches an interactive setup wizard that will guide you through configuring your project.
Using a different package manager?
The CLI works with any package manager:
- npm:
npx @igniter-js/cli init shortify - pnpm:
pnpx @igniter-js/cli init shortify - yarn:
yarn dlx @igniter-js/cli init shortify - bun:
bunx @igniter-js/cli init shortify
Interactive Setup Wizard
The CLI will ask you a series of questions to customize your project. Here's what to choose for our SaaS:
1. Select a Framework
? Which framework would you like to use?
โฏ Next.js (Recommended for full-stack apps)
Vite (For frontend + separate API)
Remix
Express
Tanstack StartChoose: Next.js - It's perfect for full-stack applications and gives us Server Components, API Routes, and excellent TypeScript support.
2. Choose Your Database
? Which database would you like to use?
โฏ PostgreSQL (Recommended for production)
MySQL
SQLite (For development only)
None (I'll set it up later)Choose: PostgreSQL - It's robust, scalable, and has excellent Prisma support. We'll use a free hosted instance later.
3. Select Your ORM
? Which ORM would you like to use?
โฏ Prisma (Recommended - Type-safe, great DX)
Drizzle
NoneChoose: Prisma - Best developer experience, auto-generated types, and amazing tooling.
4. Choose Features
? Select the features you want to enable (use space to select):
โฏ Store (Redis caching)
โฏ Jobs (Background task processing with BullMQ)
โฏ Logging (Structured logging)
โฏ Telemetry (OpenTelemetry for monitoring)For now, let's start simple and select:
- โ Logging - Essential for debugging
- โ Telemetry - Good to have from the start
We'll add Store and Jobs later when we implement analytics and background processing.
5. Package Manager
? Which package manager would you like to use?
โฏ npm
pnpm
yarn
bunChoose your preferred package manager - I recommend pnpm or bun for faster installs, but npm works perfectly fine too.
6. Additional Options
? Would you like to initialize a Git repository? (Y/n)
? Would you like to set up Docker Compose? (Y/n)
? Would you like to install dependencies now? (Y/n)- Git: โ Yes (essential for version control)
- Docker Compose: โ No (we'll use cloud services)
- Install dependencies: โ Yes (saves time)
What Just Happened?
After you complete the wizard, the CLI will:
- โจ Create your project directory (
shortify/) - ๐ฆ Generate all necessary files (configuration, boilerplate, etc.)
- ๐ง Configure your selected features
- ๐ฅ Install all dependencies
- ๐ฏ Initialize a Git repository
- ๐ Display next steps
You'll see output like this:
โ Project created successfully!
โ Dependencies installed
โ Git repository initialized
๐ Your Igniter.js project is ready!
๐ Project: shortify
๐ Framework: Next.js
๐พ Database: PostgreSQL (Prisma)
โจ Features: Logging, Telemetry
Next steps:
1. cd shortify
2. Copy .env.example to .env and configure your environment
3. Run 'npm run dev' to start the development server
Happy building! ๐ฅExploring Your Project
Let's navigate into your new project and explore what was generated:
cd shortifyHere's the structure you'll see:
Key Files Explained
Let's understand what each important file does:
src/igniter.ts
The main Igniter.js instance. This is where you configure all your features, adapters, and plugins.
// This file was generated with your selected features
export const igniter = Igniter
.context(createIgniterAppContext())
.logger(logger) // โ You selected Logging
.telemetry(telemetry) // โ You selected Telemetry
.config({
baseURL: 'http://localhost:3000',
basePATH: '/api/v1',
})
.create()src/igniter.router.ts
Your API router. All controllers are registered here.
export const AppRouter = igniter.router({
controllers: {
example: exampleController, // โ Example controller
// Your new controllers will be added here
},
})src/app/api/[[...igniter]]/route.ts
The Next.js API route that connects Igniter.js to Next.js. This is the magic glue!
prisma/schema.prisma
Your database schema. We'll design our tables here in the next chapter.
Setting Up Environment Variables
Before running your project, you need to configure environment variables. The CLI created an .env.example file with all the variables you need.
Copy it to create your local environment file:
cp .env.example .envNow open .env in your code editor. You'll see something like:
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/shortify?schema=public"
# Next.js
NEXT_PUBLIC_APP_URL="http://localhost:3000"
# Igniter.js
NEXT_PUBLIC_IGNITER_API_URL="http://localhost:3000"
NEXT_PUBLIC_IGNITER_API_BASE_PATH="/api/v1"Don't worry about the database yet!
We'll set up a free PostgreSQL database in the next chapter. For now, you can leave the DATABASE_URL as is - we won't be using the database yet.
Running Your Development Server
Now for the exciting part - let's start your application! Run:
npm run devThis command does three things:
- ๐ Starts the Next.js development server
- ๐ฅ Starts Igniter.js with hot-reload
- ๐ฏ Opens Igniter Studio (interactive API dashboard)
You'll see output like:
โฒ Next.js 15.0.0
- Local: http://localhost:3000
- Network: http://192.168.1.100:3000
๐ฅ Igniter.js
โ Router loaded successfully
โ 1 controller registered (example)
โ 1 endpoint available
โ Client schema generated
โ OpenAPI docs generated
๐ Igniter Studio: http://localhost:3000/api/v1/studio
๐ OpenAPI Docs: http://localhost:3000/api/v1/docs
Ready in 1.2sTesting Your API
Open your browser and navigate to:
http://localhost:3000 - Your Next.js homepage http://localhost:3000/api/v1/studio - Igniter Studio (API dashboard)
Using Igniter Studio
Igniter Studio is an interactive API playground that lets you:
- ๐ See all your endpoints
- ๐งช Test API calls directly in the browser
- ๐ View request/response schemas
- ๐ Inspect the generated TypeScript types
Try calling the example endpoint:
- Click on "example" in the sidebar
- Click on "GET /hello"
- Click "Execute"
You should see a response:
{
"message": "Hello from example!"
}๐ Congratulations! Your Igniter.js application is running!
Understanding the CLI Commands
Now that your project is running, let's learn about the other powerful CLI commands you'll use throughout development:
igniter dev
npx igniter devStarts the development server with:
- ๐ฅ Hot-reload for Igniter.js changes
- ๐ Framework server (Next.js in our case)
- ๐ฏ Interactive dashboard with live API explorer
- ๐ Auto-generated OpenAPI docs
Pro Tip
The dev command is smart! It automatically detects your framework (Next.js) and runs the appropriate commands. You can also customize it with flags:
npx igniter dev --port 4000 # Custom port
npx igniter dev --no-interactive # Disable interactive modeigniter generate schema
npx igniter generate schemaGenerates the TypeScript client from your Igniter.js router. This runs automatically during dev, but you can also run it manually for:
- CI/CD pipelines
- Pre-commit hooks
- Manual type generation
igniter generate docs
npx igniter generate docsGenerates OpenAPI specification and optionally a Scalar UI for your API documentation.
npx igniter generate docs --ui # Generate interactive HTML docsigniter generate feature
npx igniter generate feature users --schema prisma:UserThis is where the magic happens! This command:
- Reads your Prisma schema
- Generates a complete CRUD controller
- Creates type-safe queries and mutations
- Sets up proper file structure
We'll use this extensively in Chapter 4!
Project Structure Deep Dive
Let's understand how your project is organized:
Frontend Layer (src/app/)
src/app/
โโโ layout.tsx # Root layout, providers
โโโ page.tsx # Homepage
โโโ api/
โโโ [[...igniter]]/ # Igniter.js catch-all route
โโโ route.tsThis is your Next.js App Router structure. The [[...igniter]] route is special - it catches all API requests and forwards them to Igniter.js.
Backend Layer (src/features/)
src/features/
โโโ example/
โโโ controllers/
โโโ example.controller.tsThis is your Igniter.js API. Each feature is self-contained with its controllers, procedures, and business logic. This feature-based architecture keeps your code organized as your app grows.
Configuration (src/igniter.*.ts)
src/
โโโ igniter.ts # Main Igniter instance
โโโ igniter.context.ts # Application context & DI
โโโ igniter.router.ts # API router
โโโ igniter.client.ts # Auto-generated clientThese files work together to create your API:
igniter.ts: Configures features and adaptersigniter.context.ts: Defines what's available globally (DB, logger, etc.)igniter.router.ts: Registers all your controllersigniter.client.ts: Auto-generated type-safe client for the frontend
Services (src/services/)
src/services/
โโโ logger.ts # Structured logging
โโโ telemetry.ts # OpenTelemetry setupThese are your infrastructure services - things like logging, caching, job processing, etc.
Next Steps
Your development environment is ready! You've:
- โ Created a new Igniter.js project with the CLI
- โ Configured your project with the right features
- โ Started your development server
- โ Tested your first API endpoint
- โ Learned about the CLI commands
In the next chapter, we'll design our database schema and set up Prisma to manage our data.