Add comprehensive MDC files for various technologies and frameworks

Generate a large set of Markdown Configuration (MDC) files covering best practices across multiple domains, including:
- AI/ML libraries (PyTorch, TensorFlow, scikit-learn)
- Backend frameworks (Django, FastAPI, Express, Spring Boot)
- Frontend frameworks (React, Vue, Angular)
- Cloud platforms (AWS, Azure, GCP)
- Development tools (Docker, Kubernetes, Terraform)
- State management libraries
- UI component libraries
- Web technologies and APIs

Enhance project documentation with detailed, standardized best practice guidelines for different technologies and frameworks
This commit is contained in:
sanjeed5
2025-02-27 16:58:58 +05:30
parent 676f3376bf
commit 5068ef1d22
88 changed files with 20037 additions and 0 deletions
@@ -0,0 +1,65 @@
---
description: This rule provides best practices for CSS development, covering code organization, performance, security, testing, and common pitfalls. It aims to ensure maintainable, scalable, and efficient CSS code.
globs: **/*.css
---
- **Use a CSS Preprocessor**: Leverage preprocessors like Sass, Less, or Stylus for features like variables, nesting, mixins, and functions to enhance code organization and maintainability.
- **Code Organization and Structure**:
- **Directory Structure**: Organize CSS files into logical directories based on functionality (e.g., `components`, `modules`, `pages`, `themes`).
- **File Naming Conventions**: Use meaningful and consistent file names (e.g., `button.css`, `header.module.css`). Consider using a naming convention like BEM (Block, Element, Modifier) or SUIT CSS.
- **Module Organization**: Break down large stylesheets into smaller, reusable modules.
- **Component Architecture**: Structure CSS based on UI components, ensuring each component has its dedicated stylesheet.
- **Code Splitting**: Split CSS into critical (above-the-fold) and non-critical CSS for improved initial page load time. Utilize tools like `Critical CSS` or `PurgeCSS`.
- **Formatting and Style**:
- **Indentation**: Use soft-tabs with two spaces for indentation.
- **Trailing Whitespace**: Avoid trailing whitespace.
- **Declaration Order**: Maintain a consistent declaration order (e.g., alphabetical, grouping related properties).
- **Property Units**: Use appropriate units (e.g., `rem` or `em` for font sizes, `vw` or `%` for responsive layouts).
- **Quotation**: Use double quotes for attribute values in selectors.
- **Line Length**: Keep lines reasonably short (e.g., under 80-100 characters) for readability.
- **Common Patterns and Anti-patterns**:
- **BEM (Block, Element, Modifier)**: Use BEM or similar methodologies for clear and maintainable class naming.
- **Object-Oriented CSS (OOCSS)**: Apply OOCSS principles to create reusable and scalable styles.
- **Avoid !important**: Minimize the use of `!important` to prevent specificity conflicts.
- **Avoid Inline Styles**: Prefer external stylesheets or embedded styles over inline styles for better maintainability and separation of concerns.
- **Don't use IDs for styling**: Avoid using IDs for styling since they are too specific and make styles harder to override.
- **Understanding CSS Specificity**: Master CSS specificity rules to avoid unexpected style conflicts. Use specific selectors sparingly.
- **Use Flexible/Relative Units**: Employ relative units like `em`, `rem`, and `vw` for creating responsive designs that adapt to different screen sizes.
- **Performance Considerations**:
- **Optimize Selectors**: Use efficient CSS selectors to minimize rendering time. Avoid overly complex selectors.
- **Minify CSS**: Minify CSS files to reduce file size and improve loading times.
- **Compress CSS**: Use Gzip or Brotli compression on the server to further reduce CSS file sizes.
- **Browser Caching**: Leverage browser caching to store CSS files locally, reducing server load and improving performance.
- **Avoid Expensive Properties**: Avoid CSS properties that are computationally expensive (e.g., `filter`, `box-shadow` with large blur radii) when possible.
- **Security Best Practices**:
- **Sanitize User Input**: When using CSS variables based on user input, sanitize the input to prevent CSS injection attacks.
- **Content Security Policy (CSP)**: Implement a CSP to control the sources from which CSS can be loaded.
- **Testing Approaches**:
- **Unit Testing**: Use tools like `CSS Modules` or `styled-components` to write unit tests for individual CSS components.
- **Visual Regression Testing**: Implement visual regression testing to detect unexpected changes in CSS styles.
- **Linting**: Use a CSS linter (e.g., `stylelint`) to enforce coding standards and catch potential errors.
- **Common Pitfalls and Gotchas**:
- **Specificity Conflicts**: Be aware of specificity issues and use tools to visualize and manage CSS specificity.
- **Browser Compatibility**: Test CSS across different browsers and versions to ensure compatibility.
- **Vendor Prefixes**: Use vendor prefixes when necessary but consider using tools like `autoprefixer` to automate the process.
- **Tooling and Environment**:
- **CSS Linters**: Use `stylelint` to enforce coding standards and identify potential errors.
- **CSS Formatters**: Employ tools like `Prettier` to automatically format CSS code consistently.
- **Build Tools**: Integrate CSS compilation, minification, and optimization into your build process using tools like `Webpack`, `Parcel`, or `Gulp`.
- **CSS Modules**: Use CSS Modules to scope CSS classes locally and avoid naming conflicts.
- **Additional Tips**:
- **Document CSS**: Add comments to explain complex or non-obvious CSS rules.
- **Keep CSS DRY (Don't Repeat Yourself)**: Reuse CSS code as much as possible using variables, mixins, and inheritance.
- **Regularly Review and Refactor**: Regularly review and refactor CSS code to maintain its quality and prevent code bloat.
- **Consider Accessibility**: Ensure CSS styles contribute to website accessibility (e.g., sufficient color contrast, proper use of semantic HTML).
- **Use CSS Variables (Custom Properties)**: Use CSS variables for theming and to manage values across your CSS.
@@ -0,0 +1,101 @@
---
description: Comprehensive guide for Tailwind CSS best practices, covering code organization, performance optimization, security considerations, and common pitfalls. This rule provides actionable guidance for developers to build scalable and maintainable Tailwind CSS projects.
globs: **/*.{html,js,jsx,ts,tsx,vue}
---
- Leverage Tailwind's PurgeCSS to remove unused styles in production. Configure `purge` in `tailwind.config.js` to specify files to scan for Tailwind classes. Example:
javascript
module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
- Use Tailwind's Configuration File (`tailwind.config.js`) to customize the theme, colors, spacing, breakpoints, and other design tokens. This promotes consistency and maintainability across the project. Avoid hardcoding values directly in the HTML or components.
- Adopt a Mobile-First Approach: Design for smaller screens first and then use Tailwind's responsive modifiers (e.g., `md:`, `lg:`) to adapt the layout and styles for larger screens. This improves the user experience on mobile devices and reduces the amount of CSS needed.
- Utilize Tailwind UI or other component libraries built with Tailwind CSS to accelerate development and maintain a consistent design language. Customize the components as needed to fit the specific requirements of the project. Alternatively, create your own reusable components.
- Optimize for Performance: Be mindful of the number of Tailwind classes used on each element. Consider using `@apply` in CSS or extracting common styles into custom CSS classes to reduce duplication and improve performance. Use `content` variants when needed instead of the `DEFAULT` to control when generated classes are added. For instance, use `content-[url(..)]` instead of `content-[url(..)]`. Configure the JIT mode for faster build times during development.
- Stay Organized with Components: Break down the UI into smaller, reusable components. Use a consistent naming convention for components and Tailwind classes. Consider using a component library like Storybook to document and showcase the components.
- Integrate with a Design System: Define a clear design system with consistent colors, typography, and spacing. Map the design system tokens to Tailwind's configuration file. This ensures that the UI is consistent and aligned with the brand guidelines.
- Use semantic class names: While Tailwind promotes utility-first CSS, consider using semantic class names in conjunction with Tailwind classes to improve readability and maintainability. For example, instead of `<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">`, you could use `<button class="primary-button">` and define the corresponding styles in your CSS file using `@apply`. This allows you to update the button styles in one place without having to modify the HTML.
- Create Custom Utilities: Extend Tailwind's functionality by creating custom utilities for frequently used CSS patterns. Add these utilities to `tailwind.config.js` under the `extend.utilities` section. This will allow you to apply these patterns with a single class name.
- Use the Theme Function: Leverage the `theme()` function in your CSS or JavaScript files to access values defined in `tailwind.config.js`. This ensures that you are using consistent values throughout your project and that changes to the theme are reflected everywhere.
- Avoid Inline Styles: Refrain from using inline styles as much as possible. Tailwind provides a comprehensive set of utility classes, so most styling needs can be met without resorting to inline styles. Inline styles can make it harder to maintain and update the styles in your project.
- Use Layer Directives: Use `@layer` directives in your CSS to organize your styles and ensure that Tailwind's base styles are applied correctly. This can help prevent conflicts between your custom styles and Tailwind's default styles.
- Be Careful with Arbitrary Values: While Tailwind allows you to use arbitrary values with square bracket notation (e.g., `w-[23px]`), use this feature sparingly. Overuse of arbitrary values can make your code less readable and harder to maintain. Prefer using values defined in your `tailwind.config.js` file whenever possible.
- Utilize Variants Effectively: Understand and use Tailwind's variants (e.g., `hover:`, `focus:`, `active:`) to create interactive and dynamic styles. Customize the variants in `tailwind.config.js` to match the specific needs of your project.
- Code Organization and Structure:
- Directory structure: Organize your Tailwind CSS files into a logical directory structure. Common approaches include:
- `src/css/`: Contains `tailwind.css` (input file) and other custom CSS files.
- `src/components/`: Contains reusable UI components.
- `src/layout/`: Contains layout components (e.g., header, footer, navigation).
- File naming conventions: Use descriptive and consistent file names. For example:
- `button.css`: Styles for a button component.
- `header.js`: JavaScript file for a header component.
- Module organization: Break down your CSS into smaller, manageable modules. Use `@import` in your `tailwind.css` file to import these modules. This improves code organization and maintainability.
- Component architecture: Design your UI with a component-based architecture. Each component should have its own CSS file that defines the styles for that component.
- Code splitting strategies: Consider using code splitting to reduce the initial load time of your application. This can be achieved by splitting your CSS into smaller chunks and loading them on demand.
- Common Patterns and Anti-patterns:
- Design patterns:
- Atomic CSS: Tailwind promotes the atomic CSS approach, where styles are applied using small, single-purpose utility classes.
- Utility-first CSS: Prioritize using utility classes over custom CSS classes.
- Component-based styling: Encapsulate styles within components.
- Recommended approaches:
- Use a consistent naming convention for your components and CSS classes.
- Document your components and styles.
- Test your components and styles.
- Anti-patterns:
- Overusing custom CSS classes: Try to use Tailwind's utility classes as much as possible.
- Hardcoding values: Use the theme configuration instead of hardcoding values.
- Not using PurgeCSS: This can lead to a large CSS file in production.
- State management: Use a state management library like Redux or Zustand to manage the state of your application. Apply tailwind classes based on state changes.
- Error handling: Implement proper error handling to catch and handle errors gracefully.
- Performance Considerations:
- Optimization techniques:
- Use PurgeCSS to remove unused styles.
- Enable JIT mode.
- Optimize images.
- Memory management: Be mindful of memory usage, especially when dealing with large datasets or complex UIs.
- Rendering optimization: Use techniques like virtualization and memoization to optimize rendering performance.
- Bundle size optimization: Reduce the size of your CSS and JavaScript bundles.
- Lazy loading: Load resources on demand to improve initial load time.
- Security Best Practices:
- Common vulnerabilities:
- Cross-site scripting (XSS)
- Cross-site request forgery (CSRF)
- Injection attacks
- Input validation: Validate all user input to prevent malicious data from being injected into your application.
- Authentication and authorization: Implement proper authentication and authorization mechanisms to protect your application from unauthorized access.
- Data protection: Protect sensitive data by encrypting it and storing it securely.
- Secure API communication: Use HTTPS to encrypt communication between your application and the server.
- Testing Approaches:
- Unit testing: Test individual components and functions in isolation.
- Integration testing: Test the interaction between different components and modules.
- End-to-end testing: Test the entire application from start to finish.
- Test organization: Organize your tests into a logical directory structure.
- Mocking and stubbing: Use mocking and stubbing to isolate your tests and avoid dependencies on external resources.
- Common Pitfalls and Gotchas:
- Frequent mistakes:
- Not configuring PurgeCSS properly.
- Overriding Tailwind's styles without understanding the consequences.
- Using arbitrary values excessively.
- Edge cases:
- Handling different screen sizes and devices.
- Dealing with complex layouts and interactions.
- Supporting older browsers.
- Version-specific issues: Be aware of any version-specific issues and compatibility concerns.
- Debugging strategies: Use browser developer tools to inspect the CSS and debug any issues.
- Tooling and Environment:
- Recommended tools:
- Visual Studio Code with the Tailwind CSS IntelliSense extension.
- PostCSS with the autoprefixer plugin.
- ESLint with the eslint-plugin-tailwindcss plugin.
- Build configuration: Configure your build process to use PurgeCSS and optimize your CSS.
- Linting and formatting: Use a linter and formatter to enforce code style and catch errors.
- Deployment: Deploy your application to a production environment that is optimized for performance and security.
- CI/CD: Integrate your application with a CI/CD pipeline to automate the build, test, and deployment process.