Skip to content

Commit 79ffaa9

Browse files
authored
Merge pull request #150 from shelltime/docs/improve-claude-md
docs(claude): improve CLAUDE.md with architecture details
2 parents d5fbcfa + abbca7c commit 79ffaa9

1 file changed

Lines changed: 35 additions & 60 deletions

File tree

CLAUDE.md

Lines changed: 35 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
ShellTime CLI is a Go-based command-line tool for tracking DevOps work. It consists of two main binaries:
88
- `shelltime`: The main CLI tool for command tracking and management
9-
- `shelltime-daemon`: A background service for asynchronous command tracking and synchronization
9+
- `shelltime-daemon`: A background service for asynchronous command tracking, synchronization, and OTEL data collection
1010

1111
## Development Commands
1212

@@ -18,8 +18,8 @@ go build -o shelltime ./cmd/cli/main.go
1818
# Build the daemon binary
1919
go build -o shelltime-daemon ./cmd/daemon/main.go
2020

21-
# Build with version information
22-
go build -ldflags "-X main.version=v0.1.0 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%d)" -o shelltime ./cmd/cli/main.go
21+
# Build with all ldflags (version, commit, AI service config)
22+
go build -ldflags "-X main.version=v0.1.0 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%d) -X main.ppEndpoint=<endpoint> -X main.ppToken=<token>" -o shelltime ./cmd/cli/main.go
2323
```
2424

2525
### Testing
@@ -38,83 +38,58 @@ go test -run TestHandlerName ./daemon/
3838

3939
### Code Generation
4040
```bash
41-
# Install mockery if not already installed
42-
go install github.com/vektra/mockery/v2@v2.42.0
43-
4441
# Generate mocks (uses .mockery.yml configuration)
4542
mockery
4643
```
4744

4845
### Linting
4946
```bash
50-
# Run go vet
5147
go vet ./...
52-
53-
# Format code
5448
go fmt ./...
5549
```
5650

5751
## Architecture
5852

5953
### Package Structure
60-
- **cmd/**: Entry points for the binaries
61-
- `cli/`: Main CLI application entry point
62-
- `daemon/`: Daemon service entry point
63-
64-
- **commands/**: CLI command implementations (auth, track, sync, gc, daemon management, hooks)
65-
- Each command is self-contained in its own file
66-
- `base.go` provides shared functionality across commands
67-
- Hook management for shell integrations (bash, zsh, fish)
68-
69-
- **daemon/**: Daemon service implementation
70-
- Unix domain socket-based IPC communication with CLI
71-
- Watermill pub/sub messaging for async command processing
72-
- Channel-based architecture for concurrent operations
73-
74-
- **model/**: Core business logic and data models
75-
- API client implementations with encryption support
76-
- Database operations (local SQLite storage)
77-
- Shell-specific hook implementations
78-
- System service installers (systemd/launchctl)
79-
80-
### Key Architectural Patterns
81-
82-
1. **Command Pattern**: Each CLI command implements the `urfave/cli/v2` command interface
83-
2. **Service Pattern**: Interfaces (ConfigService, AIService, CommandService) with dependency injection via `commands.InjectVar()` and `commands.InjectAIService()`
84-
3. **IPC Communication**: Unix domain sockets for CLI-daemon communication
85-
4. **Pub/Sub Messaging**: Watermill GoChannel for internal daemon message routing
86-
5. **Batch Processing**: Commands are buffered locally and synced in batches
87-
6. **Encryption**: Hybrid RSA/AES-GCM encryption for secure command transmission
54+
- **cmd/cli/**: CLI entry point - registers all commands, initializes services via dependency injection
55+
- **cmd/daemon/**: Daemon entry point - sets up pub/sub, socket handler, and optional CCOtel gRPC server
56+
- **commands/**: CLI command implementations - each command in its own file, `base.go` holds injected services
57+
- **daemon/**: Daemon internals - socket handler, Watermill pub/sub channel, CCOtel gRPC server/processor
58+
- **model/**: Business logic - API clients, config, crypto, shell hooks, service installers, dotfile handlers
59+
60+
### Service Interfaces (model package)
61+
Three key interfaces with dependency injection:
62+
- `ConfigService`: Reads and merges config from `config.toml` and `config.local.toml`
63+
- `AIService`: PromptPal integration for AI-powered command suggestions (`shelltime q`)
64+
- `CommandService`: Executable lookup with fallback paths (handles daemon's limited PATH)
65+
66+
Injection happens in `cmd/*/main.go` via `commands.InjectVar()` and `commands.InjectAIService()`.
67+
68+
### Daemon Architecture
69+
1. **SocketHandler**: Unix domain socket server accepting JSON messages from CLI
70+
2. **GoChannel**: Watermill pub/sub for decoupled message processing
71+
3. **SocketTopicProcessor**: Consumes messages and routes to appropriate handlers
72+
4. **CCOtelServer** (optional): gRPC server implementing OTEL collector for Claude Code metrics/logs passthrough
8873

8974
### Data Flow
90-
1. Shell hooks capture commands →
91-
2. CLI stores commands locally (file based) →
92-
3. Daemon (if installed) processes commands asynchronously →
93-
4. Batch sync to shelltime.xyz API
75+
1. Shell hooks capture commands → CLI stores locally (file-based buffer)
76+
2. CLI sends sync message to daemon via Unix socket
77+
3. Daemon's pub/sub routes to sync handler
78+
4. Batch sync to shelltime.xyz API with optional encryption
9479

9580
### Configuration
96-
- Config file location: `$HOME/.shelltime/config.toml`
97-
- Local overrides: `$HOME/.shelltime/config.local.toml` (merged with main config, not committed to version control)
98-
- Database location: `$HOME/.shelltime/shelltime.db`
99-
- Daemon socket: `/tmp/shelltime-daemon.sock` (Unix) or named pipe (Windows)
81+
- Main config: `$HOME/.shelltime/config.toml`
82+
- Local overrides: `$HOME/.shelltime/config.local.toml` (merged, gitignored)
83+
- Daemon socket: `/tmp/shelltime.sock` (configurable via `socketPath`)
84+
- CCOtel gRPC port: configurable via `ccotel.grpcPort` (default: 4317)
10085

10186
## Commit Rules
10287

103-
You must follow the Conventional Commits rules, ensuring that the scope and module are included.
104-
105-
For example:
106-
107-
```md
108-
fix(home): add price link on home page
109-
feat(ai): add AI module
110-
refactor(cell): update cell module for better maintenance
111-
perf(parser): improve parser performance by over 30%
112-
```
88+
Follow Conventional Commits with scope: `fix(daemon): ...`, `feat(cli): ...`, `refactor(model): ...`
11389

11490
## Important Notes
11591

116-
- The daemon is optional but recommended for better performance
117-
- Encryption requires daemon mode and a special token
118-
- All local storage uses SQLite for reliability
119-
- The project uses OpenTelemetry for observability (when enabled)
120-
- Shell hooks are platform-specific and require careful testing
92+
- Daemon is optional but recommended (<8ms latency vs ~100ms+ direct)
93+
- Encryption requires daemon mode and a token with encryption capability
94+
- Shell hooks are platform-specific (bash, zsh, fish) - test on target shells
95+
- CCOtel feature enables Claude Code metrics/logs passthrough via gRPC (port 4317)

0 commit comments

Comments
 (0)