A CLI tool that creates a Next.js project, authenticates users with an API service, generates API keys, and stores them using dotenv.
-
CLI Interface (
bin/create-c1-app)- Entry point for the tool
- Interactive prompts using
inquirer - Progress indicators and user feedback
-
Project Generator (
src/generators/project.ts)- Creates Next.js project using
create-next-app - Configures project structure
- Installs additional dependencies
- Creates Next.js project using
-
Authentication Module (
src/auth/authenticator.ts)- Handles user authentication flow
- Manages session tokens
- Validates credentials
-
API Key Manager (
src/api/keyManager.ts)- Generates API keys via authenticated API calls
- Validates key permissions
- Handles key refresh/rotation
-
Environment Manager (
src/env/envManager.ts)- Integrates with dotenv
- Securely stores API keys
- Manages environment configuration
1. Prompt for project name and configuration
2. Create Next.js project using create-next-app
3. Navigate to project directory
4. Install additional dependencies (dotenv, API client)
1. Prompt for API service credentials (email/password or token)
2. Authenticate with API service
3. Store session token securely
4. Validate authentication status
Note: Skipped when --api-key flag is provided
1. Use authenticated session to request API key
2. Specify key permissions/scopes if needed
3. Receive and validate API key
4. Handle any rate limiting or quota restrictions
Note: Skipped when --api-key flag is provided
1. Set up dotenv in project
2. Create .env file with API key
3. Add .env to .gitignore
4. Configure Next.js for environment variables
inquirer- Interactive CLI promptschalk- Terminal colors and stylingora- Loading spinnersexeca- Process executionfs-extra- Enhanced file system operations
typescript- TypeScript compiler@types/node- Node.js type definitions@types/inquirer- Inquirer type definitionsts-node- TypeScript execution environment
dotenv- Environment variables- Custom API client library (if applicable)
create-c1-app/
├── package.json
├── tsconfig.json # TypeScript configuration
├── bin/
│ └── create-c1-app # CLI entry point
├── src/
│ ├── index.ts # Main orchestrator
│ ├── types/
│ │ └── index.ts # TypeScript type definitions
│ ├── generators/
│ │ └── project.ts # Next.js project creation
│ ├── auth/
│ │ └── authenticator.ts # Authentication handling
│ ├── api/
│ │ └── keyManager.ts # API key management
│ ├── env/
│ │ └── envManager.ts # Environment setup
│ └── utils/
│ ├── logger.ts # Logging utilities
│ ├── validation.ts # Input validation
│ └── spinner.ts # Progress indicators
├── dist/ # Compiled JavaScript output
├── templates/
│ └── nextjs/ # Next.js templates/configs
└── README.md
--project-name(-n) - Specify project name--template(-t) - Next.js template (app/pages router)--api-key(-k) - API key to use (skips authentication and key generation)--debug(-d) - Enable debug logging
CREATE_C1_APP_ENDPOINT- Default API endpointCREATE_C1_APP_TOKEN- Pre-existing auth tokenCREATE_C1_APP_DEBUG- Enable debug logging
-
Credential Storage
- Never store plaintext credentials
- Use system keychain when possible
- Temporary session tokens only
-
API Key Protection
- Set up with dotenv
- Generate unique keys per project
- Implement key rotation capabilities
-
Network Security
- Use HTTPS for all API calls
- Validate SSL certificates
- Implement request timeout/retry logic
- Invalid credentials → Re-prompt with helpful message
- Network errors → Retry with exponential backoff
- Rate limiting → Wait and inform user
- Directory exists → Prompt for overwrite/rename
- Permission errors → Suggest alternative location
- Dependency installation fails → Provide manual steps
- Generation fails → Retry with user confirmation
- Invalid permissions → Show available options
- Quota exceeded → Display usage information
-
Unit Tests
- Each module independently tested
- Mock external API calls
- Validate input/output contracts
-
Integration Tests
- End-to-end tool flow
- Real API interactions (test environment)
- File system operations
-
CLI Tests
- Command parsing and validation
- Interactive prompt flows
- Error scenario handling
- Developer Experience
- Auto-completion for bash/zsh
- VS Code extension
- Documentation generation
- Usage analytics (opt-in)
- ✅ Creates functional Next.js project
- ✅ Successfully authenticates users
- ✅ Generates valid API keys
- ✅ Stores credentials with dotenv
- ✅ Provides clear error messages
- ✅ Works across platforms (macOS, Linux, Windows)
- ✅ Complete in under 2 minutes for typical usage
- Basic CLI structure
- Next.js project creation
- Simple authentication flow
- dotenv integration
- Secure credential storage
- Environment validation
- Error handling improvements
- Comprehensive testing
- Documentation and examples