# Cmd Module

## Overview

The Cmd module contains the command-line tools and service entry points for the dataflow-service project. This module defines the project's executable files, including the main service and agent service.

## Directory Structure

```
cmd/
├── agent/           # Agent service entry point
│   └── main.go      # Agent service main function
└── dataflow/        # Main service entry point
    └── main.go      # Main service main function
```

## Core Components

### 1. agent/

Entry point for the Agent service, responsible for starting and running the Agent service. The Agent service is deployed in various environments to perform local operations such as backup, restore, etc.

### 2. dataflow/

Entry point for the main service, responsible for starting and running the dataflow-service main service. The main service provides HTTP and gRPC interfaces, as well as background workers.

## Main Service Command-Line Parameters

The main service (`dataflow`) supports the following commands:

| Command | Description |
|------|------|
| `grpc` | Start gRPC server, providing gRPC service interfaces |
| `http` | Start HTTP server, providing HTTP service interfaces |
| `migrate` | Execute database migration, upgrade database schema |
| `run_job` | Run custom tasks |
| `worker` | Start background worker, handling asynchronous tasks |
| `help` | Display help information |

### Common Parameters

| Parameter | Description | Default Value |
|------|------|--------|
| `--config` | Configuration file path | `config.yaml` |
| `--help` | Display help information | - |
| `--version` | Display version information | - |

## Usage Examples

### Start HTTP Server

```bash
./dataflow http --config config.yaml
```

### Start gRPC Server

```bash
./dataflow grpc --config config.yaml
```

### Start Background Worker

```bash
./dataflow worker --config config.yaml
```

### Execute Database Migration

```bash
./dataflow migrate --config config.yaml
```

## Build Method

Use the `make` command to build the executable files:

```bash
make build
```

Build results will be output to the `dist/` directory.

## Deployment Instructions

### Main Service

The main service is typically deployed in a Kubernetes cluster, managed using Deployment or StatefulSet.

### Agent Service

The Agent service is typically deployed in environments where local operations need to be performed, such as backup target environments.

## Notes

- Ensure that the `config.yaml` file is properly configured with necessary configuration information before starting the service.
- For production environments, it is recommended to use container orchestration tools like Kubernetes for deployment and management.
- Be cautious when executing the database migration command, as it will modify the database schema.
