Best practices for Angular Component Standards
.cursorrules in your project root# Angular Component Standards
## Core Principles
### 1. Single Responsibility Principle
* Each component should have a single, well-defined responsibility.
* Avoid mixing multiple, unrelated functionalities in a single component.
### 2. Separation of Concerns
* Keep presentation logic separate from business logic.
* Use services to handle complex business logic and API interactions.
### 3. Reusability
* Design components to be reusable across the application.
* Avoid tightly coupling components to specific use cases.
## Code Style Guidelines
### 1. Naming Conventions
* Component names should be in PascalCase (e.g., `UserListComponent`).
* Component file names should match the component name (e.g., `user-list.component.ts`).
* Use descriptive and concise names for variables, functions, and properties.
### 2. Typing
* Use type annotations for all variables, function parameters, and return types.
* Use interfaces to define complex data structures and API response types.
* Avoid using the `any` type whenever possible.
### 3. File Structure
* Keep component files organized in a logical directory structure (e.g., `components/user-list`).
* Use a consistent naming convention for component files (e.g., `user-list.component.ts`, `user-list.component.html`, `user-list.component.css`).
## Best Practices
### 1. Component Lifecycle Hooks
* Use lifecycle hooks (e.g., `ngOnInit`, `ngOnDestroy`) to handle component initialization and cleanup.
* Avoid using the constructor for complex initialization logic.
### 2. Data Binding
* Use two-way data binding (e.g., `[(ngModel)]`) for form inputs and other interactive elements.
* Use one-way data binding (e.g., `{{ }}`) for displaying read-only data.
### 3. Services and Dependency Injection
* Use services to handle API interactions, data storage, and other complex logic.
* Inject services into components using the `@Injectable` decorator.
### 4. Error Handling
* Use try-catch blocks to handle errors in component code.
* Display user-friendly error messages to the user.
## Common Pitfalls to Avoid
### 1. Overusing the `any` Type
* Avoid using the `any` type as a crutch for poor typing or lack of type definitions.
### 2. Tight Coupling
* Avoid tightly coupling components to specific services or APIs.
* Use interfaces and dependency injection to decouple components from specific implementations.
### 3. Complex Component Templates
* Avoid complex, deeply nested templates.
* Use child components or other templating strategies to simplify complex templates.
### 4. Unused Imports
* Remove unused imports from component files.
* Use tools like `npm run lint` to detect and remove unused imports.
### 5. Unhandled Async Operations
* Always handle async operations (e.g., promises, observables) in component code.
* Use try-catch blocks and error handling mechanisms to handle async errors.Comprehensive Cursor rules for Next.js 14+ with App Router, including routing, layouts, and API patterns.
Cursor rules for TypeScript with strict type checking, advanced patterns, and best practices.
Cursor rules for Tailwind CSS development with responsive design, custom components, and dark mode.
Cursor
coding
AI coding rules customize how Cursor generates and refactors code for your project. Follow these steps to install Angular Component Standards.
.cursor/rules, for Windsurf use .windsurfrulesComprehensive Cursor rules for Next.js 14+ with App Router, including routing, layouts, and API patterns.
Cursor rules for TypeScript with strict type checking, advanced patterns, and best practices.
Cursor rules for Tailwind CSS development with responsive design, custom components, and dark mode.