FletX CLI Guide¶
TL;DR¶
The FletX CLI (
fletx) automates project scaffolding, component generation, and development workflows:
| Bash | |
|---|---|
The Problem You're Solving¶
Managing a FletX project requires:
- Scaffolding: Creating the initial project structure with proper folders and configurations
- Consistency: Generating components (controllers, services, pages) that follow FletX conventions
- Development: Running your app locally during development with feedback and debugging
- Testing: Validating your code works as expected
Without the CLI, you'd manually create files, remember folder structures, and write boilerplate code every time. The FletX CLI eliminates this friction.
The Solution: Progressive Commands¶
The CLI provides four core commands. Let's explore them from beginner to advanced.
Pattern 1: Create Your First Project¶
Scenario: You're starting a brand-new FletX application.
What happens: The CLI uses a template to scaffold your entire project structure, including necessary dependencies and configuration files.
Pattern 2: Add Customization During Creation¶
Scenario: You want to document your project metadata from the start.
| Bash | |
|---|---|
Key options:
--author: Set the project author (also reads$USERenv variable)--description: Project description forpyproject.toml--version: Initial version number--python-version: Minimum Python version required--no-install: Skip automatic dependency installation (useful if you customizerequirements.txtfirst)--directory: Create project in a specific folder instead of current directory
Pattern 3: Generate Code Components¶
Scenario: Your project exists, and you need to add a new feature. You don't want to manually create the file structure.
| Bash | |
|---|---|
What's generated:
| Bash | |
|---|---|
Each generated file includes:
- Proper imports and class structure
- Docstrings explaining purpose and usage
- Lifecycle hooks (if applicable, e.g., for controllers)
- TypeHints for better IDE support
Advanced: Generate with test file
| Bash | |
|---|---|
Supported component types:
controller: Contains reactive state and business logicservice: Reusable utility class (no UI logic)page: Full screen with navigation and lifecyclecomponent: Reusable UI widget (part of pages)middleware: Route interceptorguard: Route protection logic
Pattern 4: Run Your Project¶
Scenario 1: Simple local development
| Bash | |
|---|---|
Scenario 2: Web development with hot reload
When you save a file, the app automatically reloads—perfect for iterating on UI and logic.
Scenario 3: Debug mode with logging
This shows internal logs, making it easier to diagnose issues.
Scenario 4: Desktop or mobile testing
| Bash | |
|---|---|
Scenario 5: Environment-specific configuration
| Bash | |
|---|---|
Your FletX app can read these via os.environ.get().
Pattern 5: Run Tests¶
Scenario 1: Quick test verification
Scenario 2: Run specific test file
| Bash | |
|---|---|
Scenario 3: Run tests matching a keyword
Scenario 4: Generate a coverage report
Scenario 5: Debug test failures interactively
Real-World Example: Build a Todo App¶
Let's build a minimal todo app step-by-step using the CLI:
Step 1: Create the project¶
| Bash | |
|---|---|
Step 2: Generate core components¶
| Bash | |
|---|---|
Step 3: Examine generated code¶
| Bash | |
|---|---|
Each file has the correct imports and basic structure ready for you to fill in logic.
Step 4: Implement logic (you edit the files)¶
In app/controllers/todo_list_controller.py:
Step 5: Run with hot reload¶
| Bash | |
|---|---|
Step 6: Test your controller¶
Common CLI Workflows¶
Workflow 1: Rapid Prototyping¶
| Bash | |
|---|---|
Workflow 2: Team Collaboration¶
| Bash | |
|---|---|
Workflow 3: CI/CD Integration¶
| Bash | |
|---|---|
CLI Reference: Complete Options¶
fletx new <name>¶
| Option | Type | Default | Purpose |
|---|---|---|---|
--template |
string | project |
Choose project template |
--directory |
path | current dir | Where to create the project |
--author |
string | $USER |
Project author name |
--description |
string | Generated | Project description |
--version |
string | 0.1.0 |
Initial version |
--python-version |
string | 3.12 |
Min Python version |
--overwrite |
flag | false | Overwrite existing files |
--no-install |
flag | false | Skip dependency installation |
fletx generate <type> <name>¶
| Type | Purpose | Output |
|---|---|---|
controller |
Reactive state + logic | app/controllers/<name>_controller.py |
service |
Utility class | app/services/<name>_service.py |
page |
Full screen | app/pages/<name>_page.py |
component |
Reusable widget | app/components/<name>_component.py |
middleware |
Route interceptor | app/middlewares/<name>_middleware.py |
guard |
Route protection | app/guards/<name>_guard.py |
Options:
| Option | Type | Purpose |
|---|---|---|
--output-dir |
path | Custom output directory |
--template |
string | Specific template name |
--overwrite |
flag | Overwrite existing component |
--with-test |
flag | Generate test file automatically |
fletx run [target]¶
| Option | Type | Default | Purpose |
|---|---|---|---|
--host or -h |
string | localhost |
Bind address |
--port or -p |
int | 8550 |
Port number |
--debug |
flag | false | Enable debug logging |
--watch or -W |
flag | false | Auto-reload on file changes |
--web or -w |
flag | false | Open in browser |
--desktop or -d |
flag | false | Force desktop mode |
--android or -A |
flag | false | Deploy to Android |
--ios or -X |
flag | false | Deploy to iOS |
--env or -e |
string | - | Set env var (KEY=VALUE) |
--install-deps or -r |
flag | false | Install requirements first |
--verbose or -v |
flag | false | Verbose logging |
fletx test [path]¶
| Option | Type | Purpose |
|---|---|---|
-k / --keyword |
string | Run tests matching keyword |
-v / --verbose |
flag | Verbose output |
--coverage |
flag | Generate coverage report |
--pdb |
flag | Debug on failure |
Best Practices¶
| Practice | Why | How |
|---|---|---|
| Use templates for consistency | Ensures all projects follow your team's architecture | fletx new app --template team-standard |
| Generate with tests | Catches bugs early and documents expected behavior | fletx generate controller X --with-test |
Use --watch during development |
Immediate feedback speeds up iteration | fletx run --web --watch |
| Test before committing | Prevents broken code in the repository | fletx test in git hooks or CI |
Use --env for sensitive config |
Avoids hardcoding secrets | --env API_KEY=$SECRET_KEY |
| Version your Python requirement | Prevents compatibility issues across machines | --python-version 3.11 in new command |
Troubleshooting¶
"Project already exists"¶
| Bash | |
|---|---|
"Template not found"¶
| Bash | |
|---|---|
"Port 8550 already in use"¶
"Module not found when running"¶
| Bash | |
|---|---|
"Tests don't run"¶
Common Pitfalls¶
Pitfall 1: Generating a component that already exists (overwrites your code)
| Bash | |
|---|---|
Pitfall 2: Running fletx run from the wrong directory
| Bash | |
|---|---|
Pitfall 3: Forgetting --watch during active development
| Bash | |
|---|---|
Next Steps¶
- Architecture: Understand how controllers, pages, and services connect
- Controllers: Learn to build reactive state and business logic
- Pages: Create screens and handle navigation
- Services: Build reusable utilities and integrations
- Dependency Injection: Manage component dependencies elegantly
- State Management: Use reactive primitives (RxInt, RxList, etc.)
- Decorators: Control execution timing and memoization