Comprehensive coding standards and best practices for building maintainable, scalable C# WinForms applications. Optimized for both human developers and AI assistants (Claude Code).
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
π USAGE GUIDE - Start Here! β
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!
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
- Start with practical examples: USAGE_GUIDE.md β
- Install productivity tools: Snippets + Hooks + Scripts
- Read the overview: docs/00-overview.md
- Understand architecture: MVP Pattern
- Follow conventions: Naming Conventions
- Review examples: Code Examples and Example Project
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
/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
- Project Structure - Standard folder organization
- MVP Pattern - Recommended for WinForms β
- MVVM Pattern - For .NET 8+ with data binding
- Dependency Injection - Loose coupling
- Async/Await - Non-blocking UI operations
- Resource Management - Prevent memory leaks
- Error Handling - Logging and exception handling
- Thread Safety - Cross-thread UI updates
- Performance - Optimization techniques
- Security - Secure coding practices
- Responsive Design - Adaptive layouts
- Data Binding - BindingSource pattern
- Input Validation - ErrorProvider usage
- DataGridView - Advanced grid techniques
- Testing Overview - Testing strategy
- Unit Testing - xUnit with Services
- Integration Testing - Database testing
- UI Testing - FlaUI automation
UI (Forms) β Presenter/ViewModel β Service β Repository β Database
- β Forms handle UI only (no business logic)
- β Services contain business logic
- β Repositories handle data access
- 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
- Always dispose
IDisposableresources - Use using statements or using declarations
- Handle unmanaged resources properly
- Unit tests for Services (business logic)
- Integration tests for Repositories (data access)
- UI tests for critical user flows (optional)
- Aim for 80%+ code coverage
- Project Structure - Understand folder organization
- Naming Conventions - Learn naming rules
- Code Style - Follow style guidelines
- MVP Pattern - Master architecture pattern
- Async/Await - Non-blocking operations
- Data Binding - BindingSource usage
- Unit Testing - Write effective tests
- Thread Safety - Multi-threaded UI
- Performance Optimization - Profiling & tuning
- Localization - Multi-language support
- .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)
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-guideline) - Add or update documentation
- Ensure examples are tested and working
- Submit a pull request
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
- Microsoft's C# Coding Conventions
- .NET Framework Design Guidelines
- Community best practices from WinForms developers
-
Check TROUBLESHOOTING.md first - 30+ common problems solved
- Setup & Configuration
- Dependency Injection errors
- Threading issues
- Entity Framework problems
- Performance optimization
- Claude Code specific issues
-
Search Documentation:
-
Ask Claude Code:
/review-code YourFile.cs # Check for issues /check-standards YourFile.cs # Validate against standards -
Still Stuck?
- Open a GitHub Issue with error details
- Include what you've tried
- Provide minimal code to reproduce
- 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)