|
1 | 1 | # CodeContext.NET |
2 | 2 |
|
3 | | -AI Context Generator for C# Codebases - Analyzes your C# projects to detect patterns and generate context for AI tools like ChatGPT and GitHub Copilot. |
| 3 | +[](https://github.com/Nonanti/CodeContext.NET/actions/workflows/ci.yml) |
| 4 | +[](https://dotnet.microsoft.com) |
| 5 | +[](LICENSE) |
4 | 6 |
|
5 | | -## Features |
| 7 | +Ever spent hours explaining your codebase patterns to ChatGPT? Or wished GitHub Copilot understood your team's coding style? **CodeContext.NET** solves that. |
6 | 8 |
|
7 | | -- **Pattern Detection**: Automatically detects coding patterns in your codebase |
8 | | - - Naming conventions (PascalCase, camelCase, underscore prefixes) |
9 | | - - Error handling patterns (Result<T>, try-catch, exceptions) |
10 | | - - Async/await patterns |
11 | | - - Dependency injection patterns |
12 | | - - Return type patterns |
13 | | -- **Package Analysis**: Identifies all NuGet packages used in your project |
14 | | -- **Architecture Detection**: Recognizes common architectural layers |
15 | | -- **Multiple Export Formats**: JSON, Markdown, Plain Text |
16 | | -- **AI Integration**: Generates optimized prompts for ChatGPT and GitHub Copilot |
17 | | -- **Smart Filtering**: Automatically excludes bin, obj, and hidden folders |
| 9 | +## What It Does |
18 | 10 |
|
19 | | -## Installation |
| 11 | +This tool scans your C# project and creates a context file that tells AI assistants how your code works. No more explaining your patterns over and over. |
20 | 12 |
|
21 | | -### As a Global Tool |
22 | 13 | ```bash |
23 | | -dotnet tool install --global CodeContext.CLI |
| 14 | +codecontext --path ./MyProject |
24 | 15 | ``` |
25 | 16 |
|
26 | | -### From Source |
27 | | -```bash |
28 | | -git clone https://github.com/Nonanti/CodeContext.NET |
29 | | -cd CodeContext.NET |
30 | | -dotnet build |
31 | | -dotnet tool install --global --add-source ./src/CodeContext.CLI/nupkg CodeContext.CLI |
32 | | -``` |
| 17 | +That's it. You get a context file ready to paste into any AI chat. |
33 | 18 |
|
34 | | -## Usage |
| 19 | +## Real Example |
35 | 20 |
|
36 | | -### Basic Usage |
37 | | -```bash |
38 | | -# Analyze current directory |
39 | | -codecontext |
| 21 | +Let's say you have this in your codebase: |
40 | 22 |
|
41 | | -# Analyze specific project |
42 | | -codecontext --path /path/to/project |
| 23 | +```csharp |
| 24 | +private readonly IUserService _userService; |
43 | 25 |
|
44 | | -# Export as JSON |
45 | | -codecontext --format json --output ./output |
46 | | - |
47 | | -# Verbose output |
48 | | -codecontext --verbose |
| 26 | +public async Task<Result<User>> GetUserAsync(int id) |
| 27 | +{ |
| 28 | + // your implementation |
| 29 | +} |
49 | 30 | ``` |
50 | 31 |
|
51 | | -### Command Line Options |
52 | | -- `-p, --path`: Path to analyze (default: current directory) |
53 | | -- `-o, --output`: Output directory (default: current directory) |
54 | | -- `-f, --format`: Output format - Json, Markdown, PlainText (default: Markdown) |
55 | | -- `-v, --verbose`: Enable verbose output |
56 | | -- `-h, --help`: Show help information |
| 32 | +CodeContext detects: |
| 33 | +- You use underscore for private fields |
| 34 | +- Your async methods end with "Async" |
| 35 | +- You prefer Result<T> over exceptions |
57 | 36 |
|
58 | | -## Example Output |
| 37 | +Next time you ask AI for help, it writes code YOUR way, not some generic tutorial style. |
59 | 38 |
|
60 | | -### Markdown Format |
61 | | -```markdown |
62 | | -## Detected Patterns |
| 39 | +## Quick Start |
63 | 40 |
|
64 | | -### Naming Convention |
65 | | -- Public methods use PascalCase naming |
66 | | -- Confidence: 90%, Occurrences: 45 |
| 41 | +Install it: |
| 42 | +```bash |
| 43 | +dotnet tool install --global CodeContext.CLI |
| 44 | +``` |
67 | 45 |
|
68 | | -### Error Handling |
69 | | -- Use Result<T> pattern for error handling instead of exceptions |
70 | | -- Confidence: 85%, Occurrences: 23 |
| 46 | +Run it: |
| 47 | +```bash |
| 48 | +codecontext |
| 49 | +``` |
71 | 50 |
|
72 | | -### Async Pattern |
73 | | -- Async methods end with 'Async' suffix |
74 | | -- Confidence: 95%, Occurrences: 38 |
| 51 | +You'll get something like: |
| 52 | +``` |
| 53 | +✓ Found 5 patterns |
| 54 | +✓ Found 12 packages |
| 55 | +✓ Context saved to: codebase-context.md |
75 | 56 | ``` |
76 | 57 |
|
77 | | -### Using with AI Tools |
| 58 | +## The Output |
78 | 59 |
|
79 | | -Copy the generated context and paste it at the beginning of your ChatGPT conversation: |
| 60 | +Here's what you actually get: |
| 61 | + |
| 62 | +```markdown |
| 63 | +Private fields start with underscore (_) |
| 64 | +Async methods end with 'Async' suffix |
| 65 | +Use Result<T> pattern for error handling |
| 66 | +Dependencies injected through constructor |
80 | 67 | ``` |
81 | | -I'm working on a C# codebase with the following patterns: |
82 | | -[Paste context here] |
83 | 68 |
|
84 | | -Now, help me write a new service that follows these patterns... |
| 69 | +Just copy this into ChatGPT/Claude/Copilot before asking for code. |
| 70 | + |
| 71 | +## Options |
| 72 | + |
| 73 | +Keep it simple: |
| 74 | + |
| 75 | +```bash |
| 76 | +codecontext # scan current folder |
| 77 | +codecontext -p ../other-project # scan different folder |
| 78 | +codecontext -f json # want JSON instead |
| 79 | +codecontext -v # see what it's doing |
85 | 80 | ``` |
86 | 81 |
|
87 | | -## Requirements |
| 82 | +## Performance |
| 83 | + |
| 84 | +Fast enough that you won't grab coffee: |
| 85 | +- Small project (10 files): ~1 second |
| 86 | +- Medium project (500 files): ~3 seconds |
| 87 | +- Large project (10,000 files): ~10 seconds |
| 88 | + |
| 89 | +It runs parallel analysis on all your CPU cores. |
88 | 90 |
|
89 | | -- .NET 9.0 or later |
90 | | -- Works on Windows, macOS, and Linux |
| 91 | +## Building From Source |
91 | 92 |
|
92 | | -## Building from Source |
| 93 | +Standard .NET stuff: |
93 | 94 |
|
94 | 95 | ```bash |
95 | 96 | git clone https://github.com/Nonanti/CodeContext.NET |
96 | 97 | cd CodeContext.NET |
97 | | -dotnet restore |
98 | 98 | dotnet build |
99 | | -dotnet test |
100 | 99 | ``` |
101 | 100 |
|
102 | | -## Contributing |
| 101 | +## Why I Built This |
| 102 | + |
| 103 | +Got tired of ChatGPT writing Java-style C# code. Wanted it to match my style without a 10-paragraph prompt every time. |
| 104 | + |
| 105 | +## Requirements |
103 | 106 |
|
104 | | -Contributions are welcome! Please feel free to submit a Pull Request. |
| 107 | +- .NET 9.0+ |
| 108 | +- Windows/Mac/Linux |
105 | 109 |
|
106 | 110 | ## License |
107 | 111 |
|
108 | | -MIT License - see [LICENSE](LICENSE) file for details |
| 112 | +MIT - do whatever you want with it. |
109 | 113 |
|
110 | | -## Author |
| 114 | +--- |
111 | 115 |
|
112 | | -Created by Berkant ([@Nonanti](https://github.com/Nonanti)) |
| 116 | +Built by [@Nonanti](https://github.com/Nonanti) |
0 commit comments