How aandrew-me/tgpt works
Project type and purpose
• This is a Go-based, cross-platform, terminal CLI tool (“tgpt”) that lets users interact with AI text/chat providers and image-generation providers from their shell.
• The README describes installation, available AI/image providers, proxy support, and general usage—confirming it’s a full-featured CLI application with a plugin-style architecture for different back-end services.
File structure
• Top-level files
• main.go: CLI entrypoint and command dispatch
• go.mod/go.sum, build.sh, install scripts, LICENSE, README
• Directories under src/
• bubbletea: UI layer (TUI using bubbletea framework)
• client: core HTTP client and orchestration logic
• helper, utils: miscellaneous helper functions/utilities
• structs: shared data-type definitions (requests, responses)
• providers: registry and per-provider implementations for text/chat
• imagegen: image generation module and its providers (arta, pollinations)
• md/: documentation on providers and usage
• config files: tgpt.json, version.txt
README for additional insights
• Emphasizes provider-based design—users can choose from multiple AI or image providers
• Proxy support via environment or config file
• tUI element (bubbletea) for interactive sessions
Main components and interactions
a. Components
1. CLI Entrypoint (main.go & Cobra or flag parsing)
2. TUI Layer (bubbletea module)
3. Command/Orchestration Layer (client package)
4. Provider Registry (providers/providers.go)
5. Text/Chat Providers (each src/providers/*)
6. Image Generation Layer (imagegen package + its sub-providers)
7. Shared Data Models (structs package)
8. Utilities & Helpers (utils, helper packages)
9. Configuration Store (proxy.txt, tgpt.json, environment variables)
10. External HTTP Services (OpenAI, Gemini, Pollinations, etc.)
b. Relationships & Data Flows
• User types a command → CLI Entrypoint → passes arguments to TUI or client
• TUI calls orchestration layer when needed (e.g., interactive chat)
• Orchestration layer consults config (proxy, API keys) → selects appropriate Provider via Provider Registry
• Invokes specific Provider implementation → makes HTTP request to external AI/Image service → receives response
• Response marshaled into shared structs → passed back up to TUI or printed to stdout
• ImageGen module follows similar path for image requests
c. Architectural patterns & principles
• Plugin/Factory pattern for providers: centralized registry dynamically instantiates provider implementations
• Layered modular design: UI → Orchestration → Providers → External API
• Separation of concerns: Raw HTTP client code isolated in client package, business logic in providers, UI in bubbletea
• Configuration abstraction: supports environment variables and config files
d. Key technologies/libraries
• Go modules (go.mod)
• Bubbletea TUI framework (github.com/charmbracelet/bubbletea)
• HTTP client (net/http under client package)
• JSON/YAML parsing for config
• Build & install scripts (build.sh, install-win.ps1)