1- namespace CodeContext ;
1+ using System . Text ;
2+
3+ namespace CodeContext ;
24public class MyAppsContext
35{
46 public static string GitRepoRoot { get ; private set ; }
@@ -19,20 +21,133 @@ public static string GetProjectStructure(string path, int indent = 0)
1921 . Where ( e => ! FileChecker . ShouldSkip ( new FileInfo ( e ) , GitRepoRoot ) )
2022 . ToList ( ) ;
2123
22- return string . Join ( "\n " , entries . Select ( ( e , i ) =>
24+ var sb = new StringBuilder ( ) ;
25+
26+ // Group files by their type/purpose
27+ var files = entries . Where ( e => ! Directory . Exists ( e ) )
28+ . Select ( f => new FileInfo ( f ) )
29+ . ToList ( ) ;
30+
31+ var projectFiles = files . Where ( f => f . Extension == ".csproj" || f . Extension == ".sln" ) ;
32+ var configFiles = files . Where ( f =>
33+ f . Name . StartsWith ( "appsettings" ) ||
34+ f . Name . EndsWith ( ".json" ) ||
35+ f . Name . EndsWith ( ".yml" ) ||
36+ f . Name . EndsWith ( ".config" ) ) ;
37+ var sourceFiles = files . Where ( f =>
38+ f . Extension == ".cs" ||
39+ f . Extension == ".ts" ||
40+ f . Extension == ".js" ||
41+ f . Extension == ".py" ) ;
42+ var otherFiles = files . Except ( projectFiles )
43+ . Except ( configFiles )
44+ . Except ( sourceFiles ) ;
45+
46+ // Add project overview if it's the root
47+ if ( indent == 0 )
2348 {
24- if ( indent == 0 ) WriteProgress ( i + 1 , entries . Count ) ;
49+ var projFiles = projectFiles . ToList ( ) ;
50+ if ( projFiles . Any ( ) )
51+ {
52+ sb . AppendLine ( "📦 Project Files:" ) ;
53+ foreach ( var proj in projFiles )
54+ {
55+ WriteProgress ( files . IndexOf ( proj ) + 1 , files . Count ) ;
56+ sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ proj . Extension } ] { proj . Name } ") ;
57+ }
58+ }
2559
26- var info = new FileInfo ( e ) ;
27- var indentation = new string ( ' ' , indent * 2 ) ;
28- var result = $ "{ indentation } { info . Name } { ( info . Attributes . HasFlag ( FileAttributes . Directory ) ? "/" : "" ) } ";
60+ var configs = configFiles . ToList ( ) ;
61+ if ( configs . Any ( ) )
62+ {
63+ sb . AppendLine ( "\n ⚙️ Configuration Files:" ) ;
64+ foreach ( var config in configs )
65+ {
66+ WriteProgress ( files . IndexOf ( config ) + 1 , files . Count ) ;
67+ // Extract environment for appsettings files
68+ var env = config . Name . Contains ( "appsettings." )
69+ ? $ "({ config . Name . Split ( '.' ) [ 1 ] } ) "
70+ : "" ;
71+ sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ config . Extension } ] { config . Name } { env } ") ;
72+ }
73+ }
74+ }
2975
30- return info . Attributes . HasFlag ( FileAttributes . Directory )
31- ? result + "\n " + GetProjectStructure ( e , indent + 1 )
32- : result ;
33- } ) ) ;
76+ // Add source files
77+ var srcFiles = sourceFiles . ToList ( ) ;
78+ if ( srcFiles . Any ( ) )
79+ {
80+ if ( indent == 0 ) sb . AppendLine ( "\n 💻 Source Files:" ) ;
81+ foreach ( var src in srcFiles )
82+ {
83+ WriteProgress ( files . IndexOf ( src ) + 1 , files . Count ) ;
84+ var filePurpose = GetFilePurpose ( src . Name ) ;
85+ sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ src . Extension } ] { src . Name } { filePurpose } ") ;
86+ }
87+ }
88+
89+ // Add remaining files
90+ var remaining = otherFiles . ToList ( ) ;
91+ if ( remaining . Any ( ) )
92+ {
93+ if ( indent == 0 ) sb . AppendLine ( "\n 📄 Other Files:" ) ;
94+ foreach ( var file in remaining )
95+ {
96+ WriteProgress ( files . IndexOf ( file ) + 1 , files . Count ) ;
97+ sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } { file . Name } ") ;
98+ }
99+ }
100+
101+ // Process subdirectories
102+ var directories = entries . Where ( e => Directory . Exists ( e ) )
103+ . Select ( d => new DirectoryInfo ( d ) )
104+ . ToList ( ) ;
105+
106+ if ( directories . Any ( ) )
107+ {
108+ if ( indent == 0 ) sb . AppendLine ( "\n 📂 Directories:" ) ;
109+ foreach ( var dir in directories )
110+ {
111+ var dirPurpose = GetDirectoryPurpose ( dir . Name ) ;
112+ sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ dir . Name } /] { dirPurpose } ")
113+ . Append ( GetProjectStructure ( dir . FullName , indent + 1 ) ) ;
114+ }
115+ }
116+
117+ return sb . ToString ( ) ;
34118 }
35119
120+ private static string GetFilePurpose ( string fileName ) => fileName . ToLower ( ) switch
121+ {
122+ var n when n . EndsWith ( "controller.cs" ) => "(API Endpoint)" ,
123+ var n when n . EndsWith ( "service.cs" ) => "(Business Logic)" ,
124+ var n when n . EndsWith ( "repository.cs" ) => "(Data Access)" ,
125+ var n when n . EndsWith ( "model.cs" ) => "(Data Model)" ,
126+ var n when n . EndsWith ( "request.cs" ) => "(API Request)" ,
127+ var n when n . EndsWith ( "response.cs" ) => "(API Response)" ,
128+ var n when n . EndsWith ( "dto.cs" ) => "(Data Transfer)" ,
129+ var n when n . EndsWith ( "mapper.cs" ) => "(Object Mapping)" ,
130+ var n when n == "program.cs" => "(Application Entry)" ,
131+ var n when n == "startup.cs" => "(App Configuration)" ,
132+ _ => ""
133+ } ;
134+
135+ private static string GetDirectoryPurpose ( string dirName ) => dirName . ToLower ( ) switch
136+ {
137+ "controllers" => "(API Endpoints)" ,
138+ "services" => "(Business Logic)" ,
139+ "models" => "(Data Models)" ,
140+ "views" => "(UI Templates)" ,
141+ "repositories" => "(Data Access)" ,
142+ "tests" => "(Test Cases)" ,
143+ "migrations" => "(DB Migrations)" ,
144+ "scripts" => "(Utility Scripts)" ,
145+ "docs" => "(Documentation)" ,
146+ "config" => "(Configuration)" ,
147+ "wwwroot" => "(Static Files)" ,
148+ _ => ""
149+ } ;
150+
36151 public static string GetFileContents ( string path )
37152 {
38153 if ( GitRepoRoot == null ) GitRepoRoot = FindGitRepoRoot ( path ) ;
0 commit comments