Skip to content

Commit 0123df7

Browse files
appleboyclaude
andcommitted
docs(claude): improve CLAUDE.md with request flow and dev commands
- Add request flow section explaining notification pipeline across packages - Add app/ package documentation which was missing - Add single test and per-package test commands with sqlite tag note - Add make lint and make fmt commands - Note golangci-lint v2 usage - Remove verbose README-like content (Docker, CLI examples, feature lists) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c44106c commit 0123df7

File tree

1 file changed

+48
-123
lines changed

1 file changed

+48
-123
lines changed

CLAUDE.md

Lines changed: 48 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -4,162 +4,87 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
Gorush is a push notification microserver written in Go that supports sending notifications to iOS (APNS), Android (FCM), and Huawei (HMS) devices. It provides both HTTP REST API and gRPC interfaces for sending push notifications.
7+
Gorush is a push notification microserver written in Go that supports sending notifications to iOS (APNS), Android (FCM), and Huawei (HMS) devices. It provides both HTTP REST API and gRPC interfaces.
88

99
## Architecture
1010

11-
### Core Components
11+
### Request Flow
1212

13-
- **main.go**: Entry point that handles CLI flags, configuration loading, and server initialization
14-
- **config/**: Configuration management with YAML support and environment variable overrides
15-
- **core/**: Core abstractions for queue, storage, and health check interfaces
16-
- **notify/**: Push notification implementations for different platforms (APNS, FCM, HMS)
17-
- **router/**: HTTP server setup using Gin framework with REST endpoints
18-
- **rpc/**: gRPC server implementation with protocol buffer definitions
19-
- **status/**: Application statistics and metrics collection
20-
- **storage/**: Multiple storage backends (memory, Redis, BoltDB, BuntDB, LevelDB, BadgerDB)
21-
- **logx/**: Logging utilities and interfaces
13+
1. **main.go** parses CLI flags, loads config, initializes platform clients (APNS/FCM/HMS), then starts HTTP (Gin) and gRPC servers via `graceful.Manager`
14+
2. **router/** receives push requests at `POST /api/push`, validates them, and enqueues `PushNotification` messages into the queue
15+
3. **app/worker.go** creates the queue worker (local/NSQ/NATS/Redis) with `notify.Run(cfg)` as the processing function
16+
4. **notify/** dispatches notifications to platform-specific push functions (`PushToIOS`, `PushToAndroid`, `PushToHuawei`)
17+
5. **status/** + **storage/** track success/failure counts across configurable backends
2218

23-
### Key Features
19+
### Key Packages
2420

25-
- Multi-platform support (iOS APNS, Android FCM, Huawei HMS)
26-
- Multiple queue engines (local channels, NSQ, NATS, Redis streams)
27-
- Configurable storage backends for statistics
28-
- Prometheus metrics support
29-
- gRPC and REST API interfaces
30-
- Docker and Kubernetes deployment support
31-
- AWS Lambda support
21+
- **app/**: Application orchestration — CLI send helpers (`sender.go`), config validation/merge (`config.go`), CLI options (`options.go`), queue worker creation (`worker.go`)
22+
- **config/**: YAML config with Viper, env var overrides. Reference config: `config/testdata/config.yml`
23+
- **core/**: Shared types and interfaces — `Platform` enum, queue engine constants (`core/queue.go`), storage interface (`core/storage.go`), health check interface (`core/health.go`)
24+
- **notify/**: Platform-specific push implementations. Each platform has its own file (`notification_apns.go`, `notification_fcm.go`, `notification_hms.go`). `global.go` holds shared client state
25+
- **router/**: Gin HTTP server with REST endpoints and Prometheus metrics
26+
- **rpc/**: gRPC server. Proto definitions in `rpc/proto/`
27+
- **storage/**: Storage backends (memory, Redis, BoltDB, BuntDB, LevelDB, BadgerDB) all implement `core.Storage`
28+
- **logx/**: Logging utilities wrapping zerolog/logrus
3229

3330
## Development Commands
3431

35-
### Building
32+
### Build and Run
3633

3734
```bash
38-
# Build for current platform
39-
make build
40-
41-
# Build for specific platforms
42-
make build_linux_amd64
43-
make build_darwin_arm64
44-
make build_linux_lambda
45-
46-
# Install locally
47-
make install
35+
make build # Build binary to release/gorush
36+
make install # Install to $GOPATH/bin
37+
make dev # Hot reload with air
4838
```
4939

5040
### Testing
5141

5242
```bash
53-
# Run tests (requires FCM_CREDENTIAL and FCM_TEST_TOKEN environment variables)
43+
# Full test suite (requires FCM credentials)
44+
export FCM_CREDENTIAL="/path/to/firebase-credentials.json"
45+
export FCM_TEST_TOKEN="your_test_device_token"
5446
make test
5547

56-
# Check required environment variables first
57-
make init
58-
```
59-
60-
### Development Tools
48+
# Run a single test
49+
go test -v -tags sqlite -run TestFunctionName ./package/...
6150

62-
```bash
63-
# Run with hot reload
64-
make dev
65-
66-
# Clean build artifacts
67-
make clean
68-
69-
# Check available commands
70-
make help
51+
# Run tests for a specific package
52+
go test -v -tags sqlite ./notify/...
53+
go test -v -tags sqlite ./config/...
7154
```
7255

73-
### Linting and Code Quality
56+
The `-tags sqlite` flag is required for all test commands (it's the default build tag).
7457

75-
```bash
76-
# The project uses golangci-lint with configuration in .golangci.yml
77-
# Run linting (if golangci-lint is installed):
78-
golangci-lint run
79-
80-
# Supported linters include: bodyclose, errcheck, gosec, govet, staticcheck, etc.
81-
# Formatters: gofmt, gofumpt, goimports
82-
```
83-
84-
### Protocol Buffers
58+
### Linting and Formatting
8559

8660
```bash
87-
# Install protoc dependencies
88-
make proto_install
89-
90-
# Generate Go protobuf files
91-
make generate_proto_go
92-
93-
# Generate JavaScript protobuf files
94-
make generate_proto_js
95-
96-
# Generate all protobuf files
97-
make generate_proto
61+
make lint # Run golangci-lint (auto-installs if missing)
62+
make fmt # Format code with golangci-lint fmt
9863
```
9964

100-
## Configuration
101-
102-
The application uses YAML configuration files. See `config/testdata/config.yml` for the complete configuration example.
103-
104-
Key configuration sections:
105-
106-
- **core**: Server settings, workers, queue configuration
107-
- **grpc**: gRPC server settings
108-
- **android**: Firebase Cloud Messaging settings
109-
- **ios**: Apple Push Notification settings
110-
- **huawei**: Huawei Mobile Services settings
111-
- **queue**: Queue engine configuration (local/nsq/nats/redis)
112-
- **stat**: Statistics storage backend configuration
113-
- **log**: Logging configuration
65+
Linter config is in `.golangci.yml` (v2 format). Uses golangci-lint v2.
11466

115-
## Running the Server
116-
117-
### Basic Usage
118-
119-
```bash
120-
# Use default config
121-
./gorush
122-
123-
# Use custom config file
124-
./gorush -c config.yml
125-
126-
# CLI notification examples
127-
./gorush -android -m "Hello World" --fcm-key /path/to/key.json -t "device_token"
128-
./gorush -ios -m "Hello World" -i /path/to/cert.pem -t "device_token"
129-
```
130-
131-
### Docker
67+
### Protocol Buffers
13268

13369
```bash
134-
docker run --name gorush -p 80:8088 appleboy/gorush
70+
make generate_proto # Generate both Go and JS proto files
13571
```
13672

137-
## API Endpoints
138-
139-
### REST API
140-
141-
- `GET /api/stat/go` - Go runtime statistics
142-
- `GET /api/stat/app` - Application push statistics
143-
- `GET /api/config` - Current configuration
144-
- `POST /api/push` - Send push notifications
145-
- `GET /metrics` - Prometheus metrics
146-
- `GET /healthz` - Health check
147-
148-
### gRPC
149-
150-
Enable gRPC server in config and use port 9000 by default. Protocol definitions are in `rpc/proto/`.
73+
## Build Tags
15174

152-
## Testing Requirements
75+
- `sqlite` — default tag, required for standard builds and tests
76+
- `lambda` — for AWS Lambda builds (replaces sqlite)
77+
- Set custom tags via `TAGS` environment variable
15378

154-
Tests require FCM credentials and test tokens:
79+
## Configuration
15580

156-
```bash
157-
export FCM_CREDENTIAL="/path/to/firebase-credentials.json"
158-
export FCM_TEST_TOKEN="your_test_device_token"
159-
```
81+
Config uses Viper with YAML files. Key sections: `core`, `grpc`, `android`, `ios`, `huawei`, `queue`, `stat`, `log`, `api`. See `config/testdata/config.yml` for all options. Environment variables can override any config value.
16082

161-
## Build Tags
83+
## API Endpoints
16284

163-
- Default: `sqlite` tag enabled
164-
- `lambda` tag: For AWS Lambda builds
165-
- Custom tags can be set with `TAGS` environment variable
85+
- `POST /api/push` — send push notifications
86+
- `GET /api/stat/go` — Go runtime stats
87+
- `GET /api/stat/app` — push statistics
88+
- `GET /api/config` — current config
89+
- `GET /metrics` — Prometheus metrics
90+
- `GET /healthz` — health check

0 commit comments

Comments
 (0)