Skip to content

tvtdev94/winforms-coding-standards

Repository files navigation

πŸ“˜ C# WinForms Coding Standards & Best Practices

Comprehensive coding standards and best practices for building maintainable, scalable C# WinForms applications. Optimized for both human developers and AI assistants (Claude Code).

.NET Version C# Version License


🎯 What's This?

This repository contains coding standards, architectural guidelines, and best practices for C# WinForms development. It's designed to:

  • βœ… Ensure code consistency across team members
  • βœ… Provide clear guidelines for architectural decisions (MVP, MVVM, etc.)
  • βœ… Help AI assistants (like Claude Code) write better WinForms code
  • βœ… Serve as reference documentation for common patterns
  • βœ… Include code examples and templates for quick start

πŸš€ Quick Start

New to this repository? Check out the Usage Guide with practical, step-by-step examples:

  • πŸ“ Creating a Login Form from scratch
  • πŸ“ Creating a Customer Management Form
  • πŸ“ Adding validation to existing forms
  • πŸ“ Refactoring to MVP pattern
  • πŸ“ Setting up Dependency Injection
  • πŸ“ And more real-world scenarios!

⚑ Productivity Tools - Speed Up Development

Boost your productivity with our automation tools:

  • Code Snippets 🎨

    • 7 ready-to-use snippets for Visual Studio & VS Code
    • Generate complete MVP forms in 10 seconds
    • Shortcuts: mvpform, mvpservice, asyncevent, invokeui
    • Installation Guide
  • Pre-commit Hooks πŸ”’

    • Automatic quality checks before commits
    • Prevents broken builds, failing tests, debug code
    • 9 automated validations
    • Setup Instructions
  • Project Init Scripts πŸš€

    • Create new projects in 2 minutes (vs 30-60 min manual)
    • Pre-configured with DI, EF Core, Serilog, tests
    • Command: .\scripts\init-project.ps1 -ProjectName "MyApp"
    • Usage Guide

For Developers

  1. Start with practical examples: USAGE_GUIDE.md ⭐
  2. Install productivity tools: Snippets + Hooks + Scripts
  3. Read the overview: docs/00-overview.md
  4. Understand architecture: MVP Pattern
  5. Follow conventions: Naming Conventions
  6. Review examples: Code Examples and Example Project

For AI Assistants (Claude Code)

The CLAUDE.md file is automatically loaded by Claude Code and contains:

  • Quick reference for coding standards
  • Links to detailed documentation
  • Pre-commit checklist
  • AI-specific rules

πŸ“š Documentation Structure

/winforms-coding-standards
β”œβ”€β”€ CLAUDE.md                  # Auto-loaded by Claude Code
β”œβ”€β”€ README.md                  # This file
β”œβ”€β”€ LICENSE                    # MIT License
β”œβ”€β”€ USAGE_GUIDE.md             # ⭐ Practical step-by-step examples
β”œβ”€β”€ TROUBLESHOOTING.md         # πŸ”§ Common issues & solutions (30+ problems)
β”‚
β”œβ”€β”€ /snippets/                 # ⚑ Code snippets for rapid development
β”‚   β”œβ”€β”€ /visual-studio/        # VS .snippet files
β”‚   β”œβ”€β”€ /vscode/               # VS Code JSON snippets
β”‚   └── README.md              # Installation guide
β”‚
β”œβ”€β”€ /.githooks/                # πŸ”’ Pre-commit quality checks
β”‚   β”œβ”€β”€ pre-commit             # Main hook script
β”‚   β”œβ”€β”€ install.sh             # Installation script
β”‚   └── README.md              # Hook documentation
β”‚
β”œβ”€β”€ /scripts/                  # πŸš€ Project automation scripts
β”‚   β”œβ”€β”€ init-project.ps1       # PowerShell (Windows)
β”‚   β”œβ”€β”€ init-project.sh        # Bash (Linux/Mac)
β”‚   └── README.md              # Usage guide
β”‚
β”œβ”€β”€ /docs/
β”‚   β”œβ”€β”€ 00-overview.md         # Complete documentation index
β”‚   β”‚
β”‚   β”œβ”€β”€ /architecture/         # Architecture patterns & design
β”‚   β”‚   β”œβ”€β”€ project-structure.md
β”‚   β”‚   β”œβ”€β”€ mvp-pattern.md
β”‚   β”‚   β”œβ”€β”€ mvvm-pattern.md
β”‚   β”‚   └── dependency-injection.md
β”‚   β”‚
β”‚   β”œβ”€β”€ /conventions/          # Coding conventions
β”‚   β”‚   β”œβ”€β”€ naming-conventions.md
β”‚   β”‚   β”œβ”€β”€ code-style.md
β”‚   β”‚   └── comments-docstrings.md
β”‚   β”‚
β”‚   β”œβ”€β”€ /ui-ux/               # UI & UX best practices
β”‚   β”‚   β”œβ”€β”€ responsive-design.md
β”‚   β”‚   β”œβ”€β”€ form-communication.md
β”‚   β”‚   β”œβ”€β”€ data-binding.md
β”‚   β”‚   β”œβ”€β”€ input-validation.md
β”‚   β”‚   └── datagridview-practices.md
β”‚   β”‚
β”‚   β”œβ”€β”€ /best-practices/      # General best practices
β”‚   β”‚   β”œβ”€β”€ async-await.md
β”‚   β”‚   β”œβ”€β”€ resource-management.md
β”‚   β”‚   β”œβ”€β”€ error-handling.md
β”‚   β”‚   β”œβ”€β”€ thread-safety.md
β”‚   β”‚   β”œβ”€β”€ performance.md
β”‚   β”‚   β”œβ”€β”€ security.md
β”‚   β”‚   └── configuration.md
β”‚   β”‚
β”‚   β”œβ”€β”€ /testing/             # Testing guidelines
β”‚   β”‚   β”œβ”€β”€ testing-overview.md
β”‚   β”‚   β”œβ”€β”€ unit-testing.md
β”‚   β”‚   β”œβ”€β”€ integration-testing.md
β”‚   β”‚   └── ui-testing.md
β”‚   β”‚
β”‚   β”œβ”€β”€ /advanced/            # Advanced topics
β”‚   β”‚   β”œβ”€β”€ nullable-reference-types.md
β”‚   β”‚   β”œβ”€β”€ linq-practices.md
β”‚   β”‚   └── localization-i18n.md
β”‚   β”‚
β”‚   β”œβ”€β”€ /deployment/          # Deployment & packaging
β”‚   β”‚   └── packaging.md
β”‚   β”‚
β”‚   └── /examples/            # Working code examples
β”‚       β”œβ”€β”€ mvp-example.md
β”‚       β”œβ”€β”€ di-example.md
β”‚       └── async-ui-example.md
β”‚
β”œβ”€β”€ /.claude/
β”‚   └── /commands/            # Claude Code slash commands
β”‚       β”œβ”€β”€ create-form.md
β”‚       β”œβ”€β”€ review-code.md
β”‚       └── add-test.md
β”‚
└── /templates/               # Code templates
    β”œβ”€β”€ form-template.cs
    β”œβ”€β”€ service-template.cs
    β”œβ”€β”€ repository-template.cs
    └── test-template.cs

πŸ“– Key Topics

Architecture

Best Practices

UI & UX

Testing


πŸ’‘ Core Principles

1. Separation of Concerns

UI (Forms) β†’ Presenter/ViewModel β†’ Service β†’ Repository β†’ Database
  • βœ… Forms handle UI only (no business logic)
  • βœ… Services contain business logic
  • βœ… Repositories handle data access

2. Modern C# Features

  • Use async/await for all I/O operations
  • Enable nullable reference types (C# 8.0+)
  • Use pattern matching where appropriate
  • Leverage LINQ for data manipulation

3. Resource Management

  • Always dispose IDisposable resources
  • Use using statements or using declarations
  • Handle unmanaged resources properly

4. Testing

  • Unit tests for Services (business logic)
  • Integration tests for Repositories (data access)
  • UI tests for critical user flows (optional)
  • Aim for 80%+ code coverage

πŸŽ“ Learning Path

Beginner

  1. Project Structure - Understand folder organization
  2. Naming Conventions - Learn naming rules
  3. Code Style - Follow style guidelines

Intermediate

  1. MVP Pattern - Master architecture pattern
  2. Async/Await - Non-blocking operations
  3. Data Binding - BindingSource usage
  4. Unit Testing - Write effective tests

Advanced

  1. Thread Safety - Multi-threaded UI
  2. Performance Optimization - Profiling & tuning
  3. Localization - Multi-language support

πŸ› οΈ Tools & Technologies

  • .NET 8.0 / .NET Framework 4.8
  • C# 12.0 / C# 10.0
  • Entity Framework Core 8.0
  • xUnit / NUnit for testing
  • Serilog / NLog for logging
  • Microsoft.Extensions.DependencyInjection for DI
  • FlaUI for UI automation testing (optional)

🀝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-guideline)
  3. Add or update documentation
  4. Ensure examples are tested and working
  5. Submit a pull request

Guidelines for Contributors

  • Keep documentation concise (200-500 lines per file)
  • Include code examples with explanations
  • Use markdown best practices (headings, lists, code blocks)
  • Cross-reference related topics with links
  • Test all code examples before committing

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


πŸ“ž Support & Getting Help

Having Issues?

  1. Check TROUBLESHOOTING.md first - 30+ common problems solved

    • Setup & Configuration
    • Dependency Injection errors
    • Threading issues
    • Entity Framework problems
    • Performance optimization
    • Claude Code specific issues
  2. Search Documentation:

  3. Ask Claude Code:

    /review-code YourFile.cs     # Check for issues
    /check-standards YourFile.cs # Validate against standards
    
  4. Still Stuck?

    • Open a GitHub Issue with error details
    • Include what you've tried
    • Provide minimal code to reproduce

Other Resources

  • Documentation Issues: Open an issue on GitHub
  • AI Assistant Guide: See CLAUDE.md
  • Contributing: See guidelines above

Last Updated: 2025-11-07 Version: 2.0 (Modular structure)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors