> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oasm.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 개발자 가이드

> OASM 개발 환경을 설정하고, 소스에서 서비스를 실행하며, 데이터베이스, 코드 생성, 환경 변수를 관리합니다

이 가이드는 소스에서 OASM을 개발하는 방법을 다룹니다. 모노레포 클론, 환경 초기화, 콘솔, Core API, 워커의 로컬 실행, 데이터베이스 마이그레이션 관리, 그리고 각 서비스가 요구하는 환경 변수를 설명합니다. 프로덕션 배포는 [배포](https://docs.oasm.io/ko/deployment.md)를 참고하세요.

## 사전 요구 사항

시작하기 전에 다음이 설치되어 있는지 확인하세요.

* **Task (taskfile)** — [설치 가이드](https://taskfile.dev/#/installation)
* **Node.js v22+** — [설치 가이드](https://nodejs.org/en/download/package-manager)
* **Go 1.26+** — [설치 가이드](https://go.dev/doc/install)
* **PostgreSQL v17+** (pgvector 확장 포함)
* **Docker & Docker Compose** (데이터베이스와 전체 스택에 권장)

## 저장소 클론

```bash theme={null}
git clone https://github.com/oasm-platform/open-asm.git
cd open-asm
```

이 저장소는 Node 기반 서비스인 `console`과 `core-api`를 Go `worker`와 함께 묶는 **pnpm workspaces** 모노레포입니다.

## 프로젝트 구조

```
open-asm/
├── core-api/           # NestJS API server
│   ├── src/            # Source code
│   ├── example.env     # Environment template
│   └── package.json
├── console/            # React web interface
│   ├── src/            # React components
│   ├── public/         # Static assets
│   └── package.json
├── worker/             # Go-based scanning workers
│   ├── cmd/            # CLI and App entry points
│   ├── internal/       # Business logic
│   ├── scripts/        # Install scripts (install.ps1, install.sh)
│   ├── go.mod          # Go module definition
│   └── .example.env    # Environment template
├── grpc-client/        # Generated gRPC stubs (Go + TypeScript)
├── .open-api/          # Auto-generated API docs
├── docker-compose.yml  # Container orchestration
├── taskfile.yml        # Task automation
└── README.md           # Documentation
```

* **`console/`** — React 19 + TanStack Router + Vite.
* **`core-api/`** — NestJS 11 (REST는 포트 `6276`, gRPC는 포트 `16276`).
* **`worker/`** — Go 스캔 워커(CLI 및 앱 진입점).

## 개발 환경 초기화

로컬 개발 환경을 설정하려면 다음 명령을 실행합니다.

```bash theme={null}
task init
```

이 명령은 다음을 수행합니다.

* `core-api`, `console`, `worker`의 예제 환경 파일(`.env`) 복사
* `npm`으로 프로젝트 의존성 설치(각 워크스페이스별로 task가 관리)
* 워커용 Go 의존성 설치
* 워커 보안 도구(nuclei, subfinder, httpx, naabu, dnsx)를 `worker/oasm-tools/`에 설치

`task init`을 실행한 뒤에는 `task dev`로 모든 서비스를 시작하거나, 아래 설명처럼 개별적으로 실행할 수 있습니다.

## 서비스 실행

### Task로 모든 서비스 실행

API와 콘솔 개발 서버를 동시에 시작하려면:

```bash theme={null}
task dev
```

다음이 시작됩니다.

* Core API: `http://localhost:6276`
* 콘솔: `http://localhost:5173` (Vite 개발 서버)

### Core API

```bash theme={null}
task api:dev
```

또는 직접:

```bash theme={null}
cd core-api && npm run start:dev
```

API는 포트 `6276`(기본 경로 `http://localhost:6276/api`)에서 실행되며, gRPC 서버는 포트 `16276`에서 실행됩니다.

### 콘솔(웹 인터페이스)

```bash theme={null}
task console:dev
```

또는 직접:

```bash theme={null}
cd console && npm run dev
```

### 워커

CLI 모드로 워커를 로컬에서 실행하려면:

```bash theme={null}
task worker:dev
```

사용자 지정 매개변수와 함께:

```bash theme={null}
task worker:dev replicas=3 maxJobs=10 apiKey=<your-api-key> network=<target-network>
```

앱 모드(환경 변수 기반)로 워커를 실행하려면:

```bash theme={null}
task worker:dev-app
```

워커가 사용하는 환경 변수는 [워커](https://docs.oasm.io/ko/worker.md)를 참고하세요.

## 데이터베이스 설정

`task init`은 PostgreSQL을 자동으로 시작하지 **않습니다**. 다음 중 하나를 선택하세요.

1. Docker Compose로 PostgreSQL과 Redis를 시작합니다(로컬 개발에 둘 다 필요).
   ```bash theme={null}
   docker compose up postgres redis -d
   ```
2. 자체 PostgreSQL 인스턴스를 사용하고 `core-api/.env`를 그에 맞게 수정합니다.

데이터베이스는 벡터 연산을 위한 pgvector 확장이 포함된 PostgreSQL 17을 사용합니다. 전체 스택(워커, geo-ip, rustfs 포함)을 실행하려면 대신 `task docker-compose`를 실행하세요. [Docker Compose 사용](#using-docker-compose)을 참고하세요.

## 데이터베이스 마이그레이션

데이터베이스 마이그레이션은 TypeORM으로 관리합니다. 마이그레이션 스크립트는 `core-api/taskfile.yml`에 정의되어 있으며 task 명령으로 실행할 수 있습니다.

### 대기 중인 모든 마이그레이션 실행

이 명령은 대기 중인 모든 데이터베이스 마이그레이션을 실행합니다.

```bash theme={null}
task migration:run
```

이 명령은:

* PostgreSQL 데이터베이스에 연결하고
* `migrations` 테이블에서 대기 중인 마이그레이션을 확인한 뒤
* 아직 적용되지 않은 새 마이그레이션을 모두 실행합니다

### 새 마이그레이션 생성

사용자 지정 이름으로 새 마이그레이션을 생성하려면:

```bash theme={null}
task migration:generate MIGRATION_NAME=YourMigrationName
```

예:

```bash theme={null}
task migration:generate MIGRATION_NAME=AddUserTable
```

`core-api/src/database/migrations/`에 새 마이그레이션 파일이 생성됩니다.

### 마지막 마이그레이션 되돌리기

가장 최근에 실행된 마이그레이션을 롤백하려면:

```bash theme={null}
task migration:revert
```

**참고:** 한 번에 하나의 마이그레이션만 되돌립니다. 필요하면 반복하세요.

### Docker Compose로 마이그레이션

Docker로 마이그레이션을 실행하려면(로컬에서 PostgreSQL을 실행하지 않을 때 유용):

```bash theme={null}
docker compose up migration
```

PostgreSQL 컨테이너를 시작하고(실행 중이 아니라면), 마이그레이션 서비스를 실행해 대기 중인 모든 마이그레이션을 적용한 다음, 마이그레이션 컨테이너를 제거하고 마이그레이션이 끝나면 `core-api`를 시작합니다. 디버깅을 위해 컨테이너를 유지하려면:

```bash theme={null}
docker compose run --rm migration
```

`--rm` 플래그는 컨테이너가 멈춘 뒤 제거되도록 합니다.

## 개발 규칙

### 코드 스타일

* **Core API (NestJS):** ESLint와 Prettier를 사용합니다.
  ```bash theme={null}
  task api:lint
  ```
* **콘솔 (React):** ESLint와 Prettier를 사용합니다.
  ```bash theme={null}
  task console:lint
  ```
* **워커 (Go):** `go fmt`와 `go vet`을 사용합니다.
  ```bash theme={null}
  task worker:format
  task worker:lint
  ```

### 테스트

* **Core API:** 테스트에 Jest를 사용합니다.
  ```bash theme={null}
  task api:test           # Unit tests
  task api:test:one SPEC=path/to/spec.ts   # Run a single test file
  cd core-api && npm run test:watch    # Watch mode
  cd core-api && npm run test:e2e      # End-to-end tests
  ```

* **콘솔:** 단위 테스트에 Vitest, e2e 테스트에 Playwright를 사용합니다.
  ```bash theme={null}
  task console:test       # Unit tests
  cd console && npm run e2e           # E2E tests
  ```

* **워커:** Go 테스트를 사용합니다.
  ```bash theme={null}
  task worker:test
  ```

### 빌드

```bash theme={null}
task api:build      # Build the Core API
task build          # Build all services (API + Console + Worker)
```

### API 클라이언트 생성

API 계약을 변경한 뒤에는 콘솔 API 클라이언트를 다시 생성하세요.

```bash theme={null}
task gen-api
```

orval을 사용해 OpenAPI 명세에서 TanStack Query 훅을 생성합니다. 원본 명세는 `core-api`의 `.open-api`에 있습니다(문서 사이트는 이를 `api-reference/openapi.json`에 미러링합니다).

### gRPC 스텁 생성

proto 파일을 수정한 뒤에는 gRPC 스텁을 다시 생성하세요.

```bash theme={null}
task proto
```

`grpc-client/`에 Go와 TypeScript 스텁이 생성됩니다.

## 환경 변수

각 서비스는 `task init`이 예제 템플릿에서 복사한 자체 `.env` 파일에서 구성을 읽습니다. 아래 표는 로컬 개발에서 사용하는 변수와 기본값입니다.

| 서비스 | 변수 | 용도 | 기본값 |
| - | - | - | - |
| `core-api` | `POSTGRES_HOST` | PostgreSQL 서비스의 호스트 | — |
| `core-api` | `REDIS_URL` | Redis 연결 문자열(DB 비밀번호 포함) | `redis://:password@redis:6379/0` |
| `core-api` | `GEO_IP_URL` | 자산 위치를 위한 Geo IP 서비스 엔드포인트 | `geo-ip:4360` |
| `core-api` | `OASM_CLOUD_APIKEY` | OASM Cloud API 키 | — |
| `core-api` | `RUSTFS_ENDPOINT` | 스크린샷과 아티팩트용 오브젝트 스토리지 엔드포인트 | — |
| `core-api` | `ENCRYPTION_KEYS` | 저장된 자격 증명을 암호화하는 키. 마지막 키로 암호화합니다. 로컬에서는 선택 사항(내장 키로 대체), 배포 시에는 필수 | 예제 값 |
| `core-api` | `BETTER_AUTH_SECRET` | 세션과 이메일 인증 링크에 서명합니다. 로컬에서는 선택 사항, 배포 시에는 필수 | — |
| `core-api` | `BASE_URL` | 인증 링크와 Telegram webhook에 쓰이는 콘솔의 공개 URL. 로컬에서는 비워 두세요 | — |
| `worker` | `WORKER_API_KEY` | 워커가 합류할 때 쓰는 키: **워커 연결** 대화 상자의 일회용 API 키, 또는 글로벌 워커라면 코어 API의 `OASM_CLOUD_APIKEY` | `change_me` |
| `worker` | `WORKER_GRPC_HOST` | Core API의 gRPC 호스트 | `core-api` |
| `worker` | `WORKER_GRPC_PORT` | Core API의 gRPC 포트 | `16276` |
| `worker` | `WORKER_MAX_CONCURRENCY` | 워커당 최대 동시 작업 수 | `10` |
| `worker` | `WORKER_TOOL_PATH` | 스캔 도구가 설치된 디렉터리 | `/app/oasm-tools` |
| `console` | `VITE_API_URL` | 콘솔이 Core API에 접근할 때 쓰는 기본 URL(빌드/개발 기본값) | `http://localhost:6276` |

> [!CAUTION]
>
> `.env` 파일은 절대 커밋하지 마세요. gitignore에 포함되어 있습니다. 워커의 `WORKER_API_KEY`는 유효한 일회용 API 키이거나 코어 API의 `OASM_CLOUD_APIKEY`와 같아야 하며, 그렇지 않으면 워커가 합류하지 못합니다. [워커](https://docs.oasm.io/ko/worker.md)를 참고하세요.

## Docker Compose 사용

Docker Compose로 전체 스택을 실행하려면:

```bash theme={null}
task docker-compose
```

다음이 시작됩니다.

* 콘솔(포트 3000)
* Core API(포트 6276, gRPC 포트 16276)
* 워커 인스턴스 3개
* pgvector가 포함된 PostgreSQL(포트 5432)
* Redis(포트 6379)
* Geo-IP 프록시(포트 4360)
* Rustfs S3 스토리지(포트 9000)

## 로컬 CI 테스트

변경 사항을 푸시하기 전에 [act](https://github.com/nektos/act)를 사용해 GitHub Actions 워크플로를 로컬에서 실행하여 문제를 조기에 발견할 수 있습니다.

### 사전 요구 사항

* Docker Desktop이 설치되어 실행 중이어야 합니다
* act 설치:
  ```bash theme={null}
  # Linux/macOS
  curl -fsSL https://raw.githubusercontent.com/nektos/act/master/install.sh | bash

  # Windows (Git Bash)
  curl -fsSL https://raw.githubusercontent.com/nektos/act/master/install.sh | bash
  ```

### 사용법

```bash theme={null}
# List available workflows
bash .github/scripts/test-local.sh

# Run a specific workflow
bash .github/scripts/test-local.sh check-lint
bash .github/scripts/test-local.sh worker-ci

# Validate all workflows (dry-run)
bash .github/scripts/test-local.sh --all

# Custom act binary path
ACT_BIN=act bash .github/scripts/test-local.sh check-lint
```

### 로컬 테스트 대응표

| CI 워크플로 | 로컬 명령 |
| - | - |
| `check-lint.yml` | `task lint` |
| `check-test.yml` | `task api:test` |
| `check-build.yml` | `task build` (Docker 필요) |
| `frontend-tests.yml` | `cd console && npm run test:run` |
| `worker-ci.yml` | `task worker:lint && task worker:check` |

### 참고 사항

* 멀티 플랫폼 빌드로 `docker/build-push-action`을 사용하는 워크플로(`build-release.yml`, `build-nightly.yml`)는 QEMU와 네이티브 CI 러너가 필요하므로 로컬에서 실행할 수 없습니다.
* `dorny/paths-filter`는 얕은 클론에서 파일 변경을 제대로 감지하지 못할 수 있습니다. `--full-history`를 사용하거나 특정 작업만 테스트하세요.
* Docker 레이어 캐싱(`type=gha`)은 로컬에서 사용할 수 없지만 빌드는 정상적으로 동작합니다.

## 기여하기

기여를 환영합니다! 다음 단계를 따라 주세요.

1. 저장소를 포크합니다.
2. 기능 브랜치를 만듭니다: `git checkout -b feature/amazing-feature`.
3. 변경 사항을 만들고 [Conventional Commits](https://www.conventionalcommits.org/)에 따라 커밋합니다.
   ```bash theme={null}
   git commit -m 'feat(scope): add amazing feature'
   ```
4. CI 워크플로를 로컬에서 테스트합니다: `bash .github/scripts/test-local.sh <workflow>`
5. 브랜치에 푸시합니다: `git push origin feature/amazing-feature`.
6. Pull Request를 엽니다.

PR을 제출하기 전에 코드가 프로젝트의 코딩 표준을 따르고 모든 테스트를 통과하는지 확인하세요.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.