Aniworld/.github/copilot-instructions.md
2025-10-12 18:05:31 +02:00

7.7 KiB
Raw Blame History

GitHub Copilot Instructions

These instructions define how GitHub Copilot should assist with this project. The goal is to ensure consistent, high-quality code generation aligned with our conventions, stack, and best practices.

🧠 Context

  • Project Type: Web API / Data Pipeline / CLI Tool / ML App
  • Language: Python
  • Framework / Libraries: FastAPI / Flask / Django / Pandas / Pydantic / Poetry
  • Architecture: MVC / Clean Architecture / Event-Driven / Microservices

🔧 General Guidelines

  • Use Pythonic patterns (PEP8, PEP257).
  • Prefer named functions and class-based structures over inline lambdas.
  • Use type hints where applicable (typing module).
  • Follow black or isort for formatting and import order.
  • Use meaningful naming; avoid cryptic variables.
  • Emphasize simplicity, readability, and DRY principles.

📁 File Structure

Use this structure as a guide when creating or updating files:

src/
  controllers/
  services/
  repositories/
  schemas/
  utils/
  config/
tests/
  unit/
  integration/

🧶 Patterns

Patterns to Follow

  • Use the Repository Pattern and Dependency Injection (e.g., via Depends in FastAPI).
  • Validate data using Pydantic models.
  • Use custom exceptions and centralized error handling.
  • Use environment variables via dotenv or os.environ.
  • Use logging via the logging module or structlog.
  • Write modular, reusable code organized by concerns (e.g., controller, service, data layer).
  • Favor async endpoints for I/O-bound services (FastAPI, aiohttp).
  • Document functions and classes with docstrings.

🚫 Patterns to Avoid

  • Dont use wildcard imports (from module import *).
  • Avoid global state unless encapsulated in a singleton or config manager.
  • Dont hardcode secrets or config values—use .env.
  • Dont expose internal stack traces in production environments.
  • Avoid business logic inside views/routes.

🧪 Testing Guidelines

  • Use pytest or unittest for unit and integration tests.
  • Mock external services with unittest.mock or pytest-mock.
  • Use fixtures to set up and tear down test data.
  • Aim for high coverage on core logic and low-level utilities.
  • Test both happy paths and edge cases.

🧩 Example Prompts

  • Copilot, create a FastAPI endpoint that returns all users from the database.
  • Copilot, write a Pydantic model for a product with id, name, and optional price.
  • Copilot, implement a CLI command that uploads a CSV file and logs a summary.
  • Copilot, write a pytest test for the transform_data function using a mock input.

🔁 Iteration & Review

  • Review Copilot output before committing.
  • Add comments to clarify intent if Copilot generates incorrect or unclear suggestions.
  • Use linters (flake8, pylint) and formatters (black, isort) as part of the review pipeline.
  • Refactor output to follow project conventions.

📚 References

1. General Philosophy

  • Clarity is King: Code should be easy to understand at a glance.

  • Consistency Matters: Adhere to these standards across all projects.

  • Automation Encouraged: Utilize tools like StyleCop, Roslyn Analyzers, and .editorconfig to enforce these standards automatically.

  • Evolve and Adapt: These standards should be reviewed and updated as the C# language and best practices evolve.

  • Practicality Reigns: While striving for perfection, prioritize pragmatic solutions that balance maintainability and development speed.

  • CleanCode, Keep it simple, MVVM

2. Security Considerations

  • Input Validation: Always validate user input to prevent injection attacks (e.g., SQL injection, XSS).
  • Secure Configuration: Store sensitive information (e.g., passwords, API keys) in secure configuration files, and encrypt them if possible. Avoid hardcoding sensitive data.
  • Authentication and Authorization: Implement proper authentication and authorization mechanisms to protect resources. Favor using built-in identity frameworks.
  • Data Encryption: Encrypt sensitive data at rest and in transit. Use strong encryption algorithms.
  • Regular Security Audits: Perform regular security audits and penetration testing to identify and address vulnerabilities.
  • Dependency Vulnerabilities: Keep dependencies up-to-date to patch known security vulnerabilities. Use tools to automatically check for vulnerabilities.

3. Performance Optimization

  • Minimize Object Allocation: Reduce unnecessary object allocations, especially in performance-critical code. Use techniques like object pooling and struct types for small value types.
  • Use Efficient Data Structures: Choose the appropriate data structures for the task (e.g., "Dictionary" for fast lookups, "List" for ordered collections).
  • Avoid Boxing/Unboxing: Avoid boxing and unboxing operations, as they can be expensive. Use generics to prevent boxing.
  • String Concatenation: Use "StringBuilder" for building strings in loops instead of repeated string concatenation.
  • Asynchronous I/O: Use asynchronous I/O operations to avoid blocking threads.
  • Profiling: Use profiling tools to identify performance bottlenecks.

4. GUI

  • Effortless: faster and more intuitive. It's easy to do what I want, with focus and precision.
  • Calm: faster and more intuitive. It's easy to do what I want, with focus and precision.
  • Iconography: Iconography is a set of visual images and symbols that help users understand and navigate your app. Windows 11 iconography has evolved in concert with our design language. Every glyph in our system icon font has been redesigned to embrace a softer geometry and more modern metaphors.
  • Shapes and geometry: Geometry describes the shape, size, and position of UI elements on screen. These fundamental design elements help experiences feel coherent across the entire design system. Windows 11 features updated geometry that creates a more approachable, engaging, and modern experience.
  • Typography: As the visual representation of language, the main task of typography is to communicate information. The Windows 11 type system helps you create structure and hierarchy in your content in order to maximize legibility and readability in your UI.
  • Familiar: faster and more intuitive. It's easy to do what I want, with focus and precision.
  • Familiar: faster and more intuitive. It's easy to do what I want, with focus and precision.
  • Fluent UI design: Use Fluent UI design
  • Themes: Use the already defined Theme color. Make sure ther is always a dark and light mode.
  • Text: Write in resource files so that a translation is easily possible. Use the already defined text in the resource files.

This document serves as a starting point and is meant to be adapted to the specific needs of each project and team. Regularly review and update these standards to keep them relevant and effective.

Run till you are realy finished. Do not gues, open and read files if you dont know something.