# decker-dev/shipa-app architecture

> Architecture diagram of the GitHub repository decker-dev/shipa-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/decker-dev/shipa-app
- Repository: https://github.com/decker-dev/shipa-app

## Overview

##### Project type and purpose
- This is a **GitHub App** built on **Probot** (Node.js/TypeScript).
- It listens for pull‑request and push events, analyzes documentation changes, invokes an AI service, and posts review comments.

##### File structure
- **Root / config files**: `.env`, `Dockerfile`, `app.yml` (App manifest), `package.json`, TS config, lint/build/test settings.
- **src/index.ts**: Probot entry point – registers event handlers.
- **src/services/github.ts**: Wrapper over GitHub REST API calls (e.g., fetch diffs, post comments).
- **src/ai/suggestions.ts**: Encapsulates OpenAI API calls to generate documentation improvement suggestions.
- **src/types/**: Shared TypeScript interfaces.
- **Tests & build**: `vitest.config.ts`, build scripts in `package.json`.

##### README for additional insights
- Confirms the event flow (PR synchronize/push → doc change detection → AI suggestions → post review comments).
- Lists required environment variables and installation/deployment instructions.

##### Main components and their interactions
a. **GitHub Webhook Listener (Probot)**
- Receives events from GitHub (pull_request.synchronize, push).
b. **Event Router / Handler (src/index.ts)**
- Dispatches incoming events to the appropriate logic.
c. **Change Analyzer**
- Examines modified files for documentation (comments, JSDoc).
d. **AI Suggestion Module (src/ai/suggestions.ts)**
- Constructs prompts and calls the OpenAI API using `OPENAI_API_KEY`.
- Receives suggestion payloads (text/markdown).
e. **GitHub Service Module (src/services/github.ts)**
- Uses `APP_ID`, `WEBHOOK_SECRET`, `PRIVATE_KEY` to authenticate.
- Posts review comments back to the pull request via GitHub’s REST API.
f. **External Services**
- **GitHub API** (event delivery, diff retrieval, comment posting).
- **OpenAI API** (suggestion generation).

##### Architectural patterns and design principles
- **Modular separation**:
- Event handling (index.ts)
- Service layer (GitHub API wrapper)
- AI integration layer
- **Depend‑inversion**: Use of interfaces in `src/types` for loose coupling.
- **Single responsibility**: Each module focuses on a specific concern.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    GitHub["GitHub API"]:::external
    OpenAI["OpenAI API"]:::external

    %% Internal Modules Container
    subgraph "Node.js/TypeScript" 
        direction TB
        Webhook["Webhook Listener / Event Handler"]:::internal
        Analyzer["Change Analyzer"]:::internal
        AI["AI Suggestion Module"]:::internal
        Service["GitHub Service Module"]:::internal
        Types["Shared TS Interfaces"]:::internal
    end

    %% Config Files
    subgraph "Configuration & Build" 
        direction TB
        AppManifest["app.yml"]:::config
        Env[".env.example"]:::config
        TSConfig["tsconfig.json"]:::config
        Docker["Dockerfile"]:::config
    end

    %% Data Flows
    GitHub -->|pull_request.synchronize<br/>push events| Webhook
    Webhook -->|dispatch events| Analyzer
    Analyzer -->|docs found| AI
    AI -->|POST /completions| OpenAI
    OpenAI -->|suggestions payload| AI
    AI -->|suggestions| Service
    Service -->|post review comments| GitHub

    %% Click Events
    click Webhook "https://github.com/decker-dev/shipa-app/blob/main/src/index.ts"
    click AI "https://github.com/decker-dev/shipa-app/blob/main/src/ai/suggestions.ts"
    click Service "https://github.com/decker-dev/shipa-app/blob/main/src/services/github.ts"
    click Types "https://github.com/decker-dev/shipa-app/blob/main/src/types/index.ts"
    click AppManifest "https://github.com/decker-dev/shipa-app/blob/main/app.yml"
    click Env "https://github.com/decker-dev/shipa-app/blob/main/.env.example"
    click TSConfig "https://github.com/decker-dev/shipa-app/blob/main/tsconfig.json"
    click Docker "https://github.com/decker-dev/shipa-app/tree/main/Dockerfile"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000;
    classDef external fill:#FFA500,stroke:#000;
    classDef config fill:#D3D3D3,stroke:#000;
    classDef data fill:#90EE90,stroke:#000;
```
