How pratham15541/shellmind works
Project Type & Purpose
• Project Type: Full-stack CLI application (JavaScript/Node.js).
• Purpose: Provide a terminal-based AI chatbot experience with session management and file-attachment capabilities, powered by an external AI API.
File Structure
• bin/main.js – CLI entrypoint (triggered by npm link/shebang).
• src/cli – Core CLI modules:
– cli.js: parses commands & flags
– handleQuestionLoop.js: main REPL loop
– selectFile.js: file-picker integration
– sessionManager.js: create/resume sessions
• src/api – External API client:
– api.js: HTTP calls to AI service
– fileManager.js: reads/serializes file content
• src/utils – Shared helpers:
– chatHistory.js: store/retrieve conversation log
– stateManager.js: in-memory state
– systemInstruction.js: contains prompt templates
• src/configs/env.js – environment/config loader
• src/index.js – orchestrates initialization & module wiring
• rollup.config.js & build scripts – packaging into bin/main.js
README Insights
• Key features: session management, file selection, cross-platform CLI.
• Usage: global npm install, shellmind commands.
a. Main Components
1. User Terminal (CLI)
2. CLI Controller Layer
• Command Parser (cli.js)
• REPL Loop (handleQuestionLoop.js)
• Session Manager (sessionManager.js)
• File Selector (selectFile.js)
3. Core Services
• State Manager & Chat History (stateManager.js, chatHistory.js)
• System Instruction Provider (systemInstruction.js)
4. API Layer
• AI Client (api.js)
• File Manager (fileManager.js)
5. External AI Service (e.g., OpenAI)
6. Configuration
• Env Loader (env.js)
7. Build & Distribution
• Rollup Bundler & npm publish pipeline
b. Relationships & Data Flows
• User types command → CLI Controller
• Controller invokes Session Manager → loads previous history via Chat History
• User input (and attached file content via File Selector + File Manager) → System Instruction → API Client
• API Client sends HTTP request to External AI Service → receives response
• Response → passed back to REPL Loop → displayed in terminal → appended to Chat History & in-memory State Manager
• Config Loader provides API keys & settings at startup
• Bundler and npm pipelines are build-time components (separate deployment flank)
c. Architectural Patterns & Principles
• Layered Architecture:
• Presentation Layer (CLI)
• Application Layer (session, commands)
• Domain/Utility Layer (state, history, prompts)
• Infrastructure Layer (API, file I/O, config)
• Single Responsibility: each module handles one piece of functionality
• Dependency Injection-like wiring in src/index.js
• Stateless API client; state is managed locally
d. Key Technologies
• Node.js + Commander.js/yargs (assumed) for CLI parsing
• fetch/axios or native HTTPS for API calls
• Rollup for bundling into a single executable script
• .env for config, npm for package management
Final Checklist
• Clear component labels matching directory/module names
• Notes for critical design decisions (e.g., “Chat history persisted in JSON files or memory”)
• Build/deploy flow separately at the bottom or side