Creating Your First Project
Learn how to create and structure your first Khadem backend project. We'll walk you through project scaffolding, understanding the structure, and running your application.
Prerequisites
Before creating a project, ensure you have:
- Dart SDK 3.0.0+ installed
- Khadem CLI installed globally — Installation Guide
Create a New Project
Use the Khadem CLI to scaffold a new project with all the necessary files, folders, and configurations:
# Create a new Khadem project
khadem new --name=my_first_api
# Navigate into the project directory
cd my_first_api
# Install project dependencies
dart pub getProject Structure
Complete folder structure with organized directories
Dependencies
All required packages and configurations included
Ready to Go
Start building immediately with pre-configured setup
Environment Configuration
Configure your application by editing the .env file in your project root. This file contains environment-specific settings:
# Application Configuration
APP_NAME=MyFirstAPI
APP_ENV=development
APP_PORT=8080
APP_LOCALE=en
# Database Configuration (MySQL)
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=my_first_api_db
DB_USERNAME=root
DB_PASSWORD=
# JWT Authentication
JWT_SECRET="your-super-secret-jwt-key-here"
JWT_ACCESS_EXPIRY_MINUTES=60
JWT_REFRESH_EXPIRY_DAYS=30Configuration Groups
- APP_* — Application settings
- DB_* — Database connection
- JWT_* — Authentication tokens
Security Note
Never commit .env files to version control. Keep sensitive data like JWT_SECRET secure.
Running Your Project
Start the development server with hot reload support:
# Run the application in development mode with hot reload
khadem serve
# Your application is now running!
HTTP Server
REST API endpoint
http://localhost:8080WebSocket Server
Real-time communication
ws://localhost:8080Hot Reload: Press r in the terminal to hot reload your application after making changes to your Dart files. Quick and easy!
Project Setup Checklist
Verify everything is set up correctly before proceeding:
Project created successfully
Verify with khadem new --name=my_api
Dependencies installed
Run dart pub get in project directory
Environment variables configured
Edit .env with your settings
Development server running
Start with khadem serve and visit http://localhost:9000
Need Assistance?
Stuck or have questions? Our community is here to help you get started!
