A powerful CLI scaffolding tool for React + TypeScript applications
Generate opinionated folder structures and component templates with Angular-style architecture for Vite + React + TypeScript projects.
- 🚀 Quick Scaffolding: Initialize a complete project structure in seconds
- 📦 Angular-Style Architecture: Organized modules, services, and components
- 🎨 Component Generation: Auto-generate components with TypeScript, SCSS modules, and type definitions
- 🔧 Service Layer: Class-based singleton services for business logic
- 🪝 Custom Hooks: Generate custom React hooks with boilerplate
- 📁 Module System: Organize features into self-contained modules
- ⚡ TypeScript First: Full TypeScript support out of the box
- 🎯 Opinionated Structure: Best practices baked in
npm install -g react-architectnpx react-architect initreact-architect initThis creates the following folder structure:
src/
├── core/
│ ├── services/
│ ├── hooks/
│ └── context/
├── components/
├── shared/
│ ├── ui/
│ └── utils/
└── modules/
# Generate a component in src/components
react-architect generate component Button
# Or use the shorthand
react-architect g component ButtonThis creates:
src/components/Button/
├── Button.tsx
├── Button.module.scss
├── Button.types.ts
└── index.ts
# Generate a component inside a specific module
react-architect g component LoginForm --module authThis creates:
src/modules/auth/components/LoginForm/
├── LoginForm.tsx
├── LoginForm.module.scss
├── LoginForm.types.ts
└── index.ts
Initialize the recommended folder structure.
react-architect initGenerate components, modules, services, or hooks.
react-architect generate <type> <name> [options]Types:
component- React component with styles and typesmodule- Feature module with folder structureservice- Singleton service classhook- Custom React hook
Options:
-m, --module <name>- Generate inside a specific module
Examples:
# Generate a component
react-architect g component Button
# Generate a component in a module
react-architect g component LoginForm --module auth
react-architect g component LoginForm -m auth # shorthandCleaner syntax for generating items inside a specific module.
react-architect module <moduleName> <type> <name>Types:
component- React componentservice- Service classhook- Custom hook
Examples:
# Generate components in auth module
react-architect module auth component LoginForm
react-architect m auth component RegisterForm # shorthand
# Generate service in auth module
react-architect m auth service Auth
# Generate hook in auth module
react-architect m auth hook useAuthList all available modules in your project.
react-architect list-modules
react-architect ls # shorthandOutput:
📦 Available modules:
• auth
• products
• dashboard
Total: 3 module(s)
react-architect g component HeaderOutput:
// Header.tsx
import React from 'react';
import styles from './Header.module.scss';
import { HeaderProps } from './Header.types';
export const Header: React.FC<HeaderProps> = ({ children, className = '' }) => {
return (
<div className={`${styles.header} ${className}`}>
<h2>Header Component</h2>
{children}
</div>
);
};react-architect g service AuthOutput:
// AuthService.ts
class AuthService {
private static instance: AuthService;
private constructor() {
this.initialize();
}
public static getInstance(): AuthService {
if (!AuthService.instance) {
AuthService.instance = new AuthService();
}
return AuthService.instance;
}
// ... methods
}
export const authService = AuthService.getInstance();react-architect g hook useAuthOutput:
// useAuth.ts
import { useState, useEffect } from 'react';
export const useAuth = () => {
const [data, setData] = useState<any>(null);
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<Error | null>(null);
// ... hook logic
return { data, loading, error };
};react-architect g module authOutput:
src/modules/auth/
├── components/
├── services/
├── hooks/
└── index.ts
# Traditional way with --module flag
react-architect g component LoginForm --module auth
# Or use the cleaner module command (NEW!)
react-architect module auth component LoginForm
react-architect m auth component LoginForm # shorthandReact Architect enforces a clean, scalable architecture:
Global services, hooks, and context that are used across the entire application.
Reusable components that aren't tied to a specific feature.
- ui/: Common UI components (buttons, inputs, modals)
- utils/: Helper functions and utilities
Feature-based modules containing:
- components/: Feature-specific components
- services/: Business logic and API calls
- hooks/: Feature-specific custom hooks
Each component gets:
ComponentName.tsx- React componentComponentName.module.scss- Scoped stylesComponentName.types.ts- TypeScript interfacesindex.ts- Clean exports
src/modules/feature-name/
├── components/ # Feature components
├── services/ # Feature services
├── hooks/ # Feature hooks
└── index.ts # Module exports
- Clone the repository:
git clone https://github.com/yourusername/react-architect.git
cd react-architect- Install dependencies:
npm install- Link the package locally:
npm link- Test the CLI:
react-architect --help- Unlink when done:
npm unlink -g react-architect-
Create an NPM account at npmjs.com
-
Login to NPM:
npm login- Update version in
package.json:
npm version patch # or minor, or major- Publish to NPM:
npm publish- Patch (
1.0.0→1.0.1): Bug fixes
npm version patch- Minor (
1.0.0→1.1.0): New features
npm version minor- Major (
1.0.0→2.0.0): Breaking changes
npm version majornpm version patch
npm publish- Interactive Mode: CLI prompts for configuration
- Config File:
.reactarchitectrcfor project-specific settings - Storybook Integration: Auto-generate Storybook stories
- JavaScript Support: Generate JS files instead of TS
- Testing Templates: Auto-generate test files
- Custom Templates: User-defined template support
- Context Generation: Generate React context providers
- API Client Generator: Generate API service boilerplate
- Route Generation: Auto-generate route configurations
- Form Generation: Generate form components with validation
- Support for other styling solutions (Styled Components, Tailwind)
- Redux/Zustand slice generators
- GraphQL query generators
- Docker configuration
- CI/CD pipeline templates
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Angular CLI
- Built for the React community
- Powered by Node.js, Commander, and Handlebars
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ❤️ for the React community
⭐ Star this repo if you find it helpful!