flowchart TD
%% Main Entry Point and Initialization
Start([Application Start]) --> ParseArgs[Parse Command Line Arguments]
ParseArgs --> CheckStdin{Check stdin}
CheckStdin -->|Input Piped| ProcessPiped[Process Piped Input]
CheckStdin -->|Interactive Mode| CheckAuth{Authentication Status}
%% Authentication Flow
CheckAuth -->|Not Authenticated| OAuthFlow[OAuth Authentication]
OAuthFlow --> StoreCredentials[Store User Credentials]
StoreCredentials --> SetupEnv[Initialize Environment]
CheckAuth -->|Authenticated| LoadCreds[Load Saved Credentials]
LoadCreds --> SetupEnv
SetupEnv --> InitializeSDK[Initialize Claude SDK]
%% Session Management
InitializeSDK --> CreateSession[Create User Session]
CreateSession --> InputLoop[Process User Input]
%% Command Processing
InputLoop --> ParseInput[Parse Input]
ParseInput --> CommandType{Determine Command Type}
%% System Commands
CommandType -->|System Command| HandleSystemCmd[Process System Command]
HandleSystemCmd --> |Help| ShowHelp[Display Help]
HandleSystemCmd --> |Version| ShowVersion[Display Version]
HandleSystemCmd --> |Bug Report| SubmitBug[Submit Bug Report]
HandleSystemCmd --> |Compact| CompactConvo[Compact Conversation History]
HandleSystemCmd --> |Quit/Exit| Terminate[Terminate CLI]
%% Natural Language Processing
CommandType -->|Natural Language| ProcessNL[Process Natural Language Input]
%% Task Classification Flow
ProcessNL --> TaskClassify{Classify Task Type}
%% Task Types
TaskClassify -->|Code Understanding| CodeAnalysis[Analyze Code]
TaskClassify -->|File Editing| FileEdit[Edit Files]
TaskClassify -->|Command Execution| ExecCmd[Execute Terminal Commands]
TaskClassify -->|Git Operations| GitOps[Perform Git Operations]
%% Code Analysis Flow
CodeAnalysis --> SearchFiles[Search for Relevant Files]
SearchFiles --> ParseCode[Parse Code Structure]
ParseCode --> GenerateUnderstanding[Generate Code Understanding]
%% File Editing Flow
FileEdit --> ReadFiles[Read Target Files]
ReadFiles --> ModifyCode[Modify Code]
ModifyCode --> WriteFiles[Write Changes to Files]
%% Command Execution Flow
ExecCmd --> ValidateCmd[Validate Command]
ValidateCmd --> RunCommand[Execute Command in Shell]
RunCommand --> CaptureOutput[Capture Command Output]
%% Git Operations Flow
GitOps --> GitCommand{Git Command Type}
GitCommand -->|Repo Operations| HandleRepo[Handle Repository Operations]
GitCommand -->|Commits| ManageCommit[Manage Commits]
GitCommand -->|Pull Requests| CreatePR[Create Pull Requests]
%% API Interaction with LLM
GenerateUnderstanding --> PreparePrompt[Prepare Prompt]
WriteFiles --> PreparePrompt
CaptureOutput --> PreparePrompt
HandleRepo --> PreparePrompt
ManageCommit --> PreparePrompt
CreatePR --> PreparePrompt
ShowHelp --> ReturnToSession
ShowVersion --> ReturnToSession
CompactConvo --> UpdateSessionHistory[Update Session History]
%% API Communication
PreparePrompt --> APIRequest[Send Request to Claude API]
APIRequest --> HandleResponse{Response Type}
HandleResponse -->|Streaming| StreamResponse[Process Streaming Response]
HandleResponse -->|Non-Streaming| ProcessResponse[Process Complete Response]
%% Response Handling
StreamResponse --> RenderStream[Render Incremental Response]
ProcessResponse --> RenderComplete[Render Complete Response]
RenderStream --> UpdateSessionContext[Update Conversation Context]
RenderComplete --> UpdateSessionContext
%% Debug and Telemetry
APIRequest --> |Debug Mode| LogAPIRequest[Log API Request Details]
HandleResponse --> |Debug Mode| LogAPIResponse[Log API Response]
LogAPIRequest --> APIRequest
LogAPIResponse --> UpdateSessionContext
%% Error Handling
ParseArgs --> |Invalid Args| ErrorHandling[Handle Error]
APIRequest --> |API Error| ErrorHandling
RunCommand --> |Execution Error| ErrorHandling
ErrorHandling --> DisplayError[Display Error Message]
DisplayError --> ReturnToSession
%% Session Continuation
UpdateSessionContext --> ReturnToSession[Return to Session]
UpdateSessionHistory --> ReturnToSession
SubmitBug --> ReturnToSession
ReturnToSession --> SessionContinue{Continue Session?}
SessionContinue -->|Yes| InputLoop
SessionContinue -->|No| Cleanup[Cleanup Resources]
Terminate --> Cleanup
Cleanup --> Exit([Exit Application])
%% Caching & Performance
subgraph "Caching System"
FileCache[File Content Cache]
PromptCache[Prompt Template Cache]
ResponseCache[API Response Cache]
end
SearchFiles <--> FileCache
PreparePrompt <--> PromptCache
APIRequest <--> ResponseCache
%% Background Processes
subgraph "Background Processes"
SessionMonitor[Session Monitor]
CredentialRefresh[Refresh Credentials]
PeriodicFlush[Periodic Cache Flush]
end
CreateSession --> SessionMonitor
SessionMonitor --> CredentialRefresh
SessionMonitor --> PeriodicFlush
%% Subgraphs for Logical Components
subgraph "Authentication & Session"
CheckAuth
OAuthFlow
StoreCredentials
LoadCreds
CreateSession
UpdateSessionContext
UpdateSessionHistory
end
subgraph "Command Processing"
ParseInput
CommandType
HandleSystemCmd
ProcessNL
TaskClassify
end
subgraph "Task Execution"
CodeAnalysis
FileEdit
ExecCmd
GitOps
SearchFiles
ParseCode
ReadFiles
ModifyCode
WriteFiles
ValidateCmd
RunCommand
CaptureOutput
GitCommand
HandleRepo
ManageCommit
CreatePR
end
subgraph "API Interaction"
PreparePrompt
APIRequest
HandleResponse
StreamResponse
ProcessResponse
RenderStream
RenderComplete
end
subgraph "Error Management"
ErrorHandling
DisplayError
end
Created
March 9, 2025 05:09
-
-
Save leehanchung/04c0c53fe839e6b1ad7570f026c2f988 to your computer and use it in GitHub Desktop.
claude code mermaid diagram in https://leehanchung.github.io/blogs/2025/03/07/claude-code/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment