NEXON CLI
A clean architecture code generator for Flutter BLoC projects. It automates feature scaffolding and method boilerplate, aligning with your architecture (domain/data/presentation) and API patterns.
This is the basic setup — we will keep refining it and make it the best in future iterations.
Key Features
- Generate a full feature structure: domain, data, presentation folders and boilerplate.
- Generate BLoC handlers with events, state, AppStatus lifecycle, and repository calls.
- Create repository, repo_impl, remote source, and endpoint stubs.
- Add methods with HTTP types:
get,post,postMultipart. - Support method-specific query models and response models.
- Method-specific pagination fields to avoid conflicts across multiple methods.
Installation
- Ensure you have Dart SDK installed.
- Clone this repo and run:
dart run bin/nexon_cli.dart --help
Optionally add a shell alias for convenience:
alias nexon='dart run /path/to/nexon_cli/bin/nexon_cli.dart'
Quickstart
- Create a new feature scaffold:
nexon start auth
Generated structure under auth/:
auth/
├── domain/
│ ├── entity/
│ └── repo/
│ └── auth_repository.dart
├── data/
│ ├── endpoints/
│ │ └── auth_endpoints.dart
│ ├── model/
│ │ ├── request/
│ │ │ └── auth_request.dart
│ │ └── response/
│ │ └── auth_response.dart
│ ├── repo_impl/
│ │ └── auth_repo_impl.dart
│ └── sources/
│ ├── auth_remote_source.dart
│ └── auth_local_source.dart (placeholder)
└── presentation/
├── bloc/
│ ├── auth_bloc.dart
│ ├── auth_event.dart
│ └── auth_state.dart
├── screens/
├── utils/
└── widgets/
Commands
Start
nexon start <feature>- Example:
nexon start auth - Creates feature folders and boilerplates (repository, repo_impl, remote source, endpoints, bloc/event/state).
Add Method
- Syntax options:
nexon add <methodName> in <feature>(defaults toget)nexon add <httpMethod> <methodName> in <feature>where<httpMethod>∈get | post | postMultipart
- Prompts:
- Model class name (e.g.,
authHistory) — used to type the response and to generate a model file if missing. - Custom query class name (optional, e.g.,
authHistoryQuery). - Has pagination? (y/n) — injects method-specific pagination fields.
- Should store response? (y/n) — adds a store variable based on method name (pluralized reasonably).
- Model class name (e.g.,
What Gets Generated
- BLoC:
- Registers
on<MethodRequested>(_onMethod). - Handler emits
${method}Status: loading → failure/success → complete. - Stores
result.datawhen chosen (variable inferred:fetchHistory→histories). - Emits method-specific pagination fields:
${method}NextPage,${method}OffSet,${method}TotalPage.
- Registers
- Event:
class <Method>Requested extends <Feature>Event { <Query?> queryParam; [Map<String,dynamic>? payload] }.
- State:
- Adds
final AppStatus ${method}Status;. - Adds optional
final dynamic <storeVar>;. - Adds optional method-specific pagination fields.
- Adds
- Repository:
- Adds method signature using your model and query types.
- Repo Impl:
- Forwards to remote source.
- Remote Source:
- Adds method using your
ApiClient(get,post,postMultipart) withqueryParams: queryParam?.toJson()and optionalpayload. - Requires
workspaceIdfrom secure storage (returnsLeft(GeneralFailure(...))if missing). - Folds to
Right(<model>FromJson(result)).
- Adds method using your
- Endpoints:
- Adds
static String <method>({required String workspaceId}) => '/workspace/$workspaceId/<feature>s';
- Adds
Examples
- Create feature:
nexon start auth
- Add GET method:
nexon add get fetchHistory in auth- Model:
authHistory - Query class:
authHistoryQuery - Pagination:
y - Store response:
y
Custom Query Classes
- For method-specific filters (date/status/limit/offset etc.), specify a query class name.
- A stub is appended to
data/model/request/<feature>_request.dart:
class authHistoryQuery {
authHistoryQuery();
Map<String, dynamic> toJson() => {};
}
- You can expand this with fields and a proper
toJson().
Notes & Limitations
- Endpoint stub paths are generic; adjust them to your API (e.g., add supervisor/auth/day-sheet suffixes).
- Generated imports reference your architecture (
workplanxcore packages); ensure they exist in your app. - Model generation is intentionally minimal (message/data/pagination). Adapt as needed.
Roadmap
- Smarter endpoint path generation per method.
- Model generation from pasted JSON schema.
- Strongly-typed storage and data lists in state.
- Interactive choices for enum/request presets.
Contributing
- PRs welcome. Please keep templates and commands cohesive and minimal.
Documentation
- Docs are under
doc/and powered by Docsify. - To preview locally:
npx docsify-cli@latest serve docsorpython3 -m http.server 5500 --directory docs