# baejihyun97/fire-response-system architecture

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

- Interactive diagram: https://gitdiagram.com/baejihyun97/fire-response-system
- Repository: https://github.com/baejihyun97/fire-response-system

## Overview

##### Project type and purpose
- This is a full-stack, event-driven microservices system for a “Fire Response System.”
- It consists of six backend services (reportmanagement, videoproccessing, eventmanagement, aianalysis, feedservice, notification), a Spring Cloud API Gateway, a Vue.js frontend, and a Kafka message bus.

##### File structure
- Top-level directories for each microservice, each with its own `pom.xml`, Dockerfile, Kubernetes manifests, `src/main/java/fireresponsesystem/domain` (domain entities & events), and `infra` (REST controllers, policy handlers, HATEOAS processors).
- A `gateway` module using Spring Cloud Gateway.
- A `frontend` Vue project (`src/components`, `router.js`, `App.vue`).
- An `infra` folder for Kafka compose and shared Docker Compose definitions.
- Kubernetes templates at the repo root and per-service.

##### README for additional insights
- Services communicate via Kafka topics—each service publishes and subscribes to domain events.
- The gateway aggregates all HTTP endpoints on port 8088.
- Frontend communicates only with the gateway.
- Deployable via Docker Compose or Kubernetes (EKS, AWS CLI tooling suggested).

##### Main components & their interactions
a. Frontend (Vue.js SPA)
- Runs on localhost:8088 (served by the gateway).
- Executes UI commands (e.g., ReceiveReportCommand, TriggerVideoAnalysisCommand).
b. API Gateway (Spring Cloud Gateway)
- Single HTTP entry point.
- Routes REST calls to individual microservices on internal ports.
c. Backend Microservices (Spring Boot each)
- reportmanagement: accepts new reports → emits ReportReceived event.
- videoproccessing: listens for ReportReceived → processes video → emits VideoAnalyzed or VideoAnalysisFailed.
- eventmanagement: listens for VideoAnalyzed → creates/updates events → emits IdentifiedAsFireEvent or IdentifiedAsNonFireEvent.
- aianalysis: listens for IdentifiedAsFireEvent → calls AI module → emits AiAnalyzed.
- feedservice: listens for AiAnalyzed & other domain events → publishes posts → emits PostPublished.
- notification: listens for all “important” events → sends notifications → persists Notification.
d. Kafka (message broker)
- Central event bus.
- Each service has producer & consumer clients configured via `application.yml`.
e. Each service’s Database (implicit in domain repositories)
- Stores its own entities.
- Boundaries maintained (no shared schema).
f. Container & Orchestration
- Docker for containerization (per-service Dockerfile).
- Kubernetes manifests for deployment.
- Shared Docker Compose in `infra/docker-compose.yml` for local Kafka and service composition.

##### Architectural patterns & design principles
- Microservices with bounded contexts (each module owns its domain model & repository).
- Event-driven architecture via Kafka topics.
- API Gateway pattern for unified HTTP façade.
- HATEOAS-driven REST with Spring Data REST processors.
- Domain-driven design: domain events, commands, repositories.
- Containerization and 12-factor app readiness.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "UI Layer"
        Frontend["Vue.js SPA"]:::frontend
    end

    subgraph "API Layer"
        Gateway["API Gateway\n(Spring Cloud Gateway)"]:::gateway
    end

    subgraph "Service Layer"
        subgraph ReportManagement
            RM["reportmanagement"]:::service
            RMDB["Report DB"]:::db
        end
        subgraph VideoProcessing
            VP["videoproccessing"]:::service
            VPDB["VideoProcessing DB"]:::db
        end
        subgraph EventManagement
            EM["eventmanagement"]:::service
            EMDB["EventManagement DB"]:::db
        end
        subgraph AIAnalysis
            AI["aianalysis"]:::service
            AIDB["AIAnalysis DB"]:::db
        end
        subgraph FeedService
            FS["feedservice"]:::service
            FSDB["FeedService DB"]:::db
        end
        subgraph Notification
            NS["notification"]:::service
            NSDB["Notification DB"]:::db
        end
    end

    subgraph "Event Bus"
        Kafka["Kafka Cluster"]:::kafka
    end

    subgraph "Infrastructure"
        Infra["Docker & Kubernetes"]:::infra
    end

    %% Connections
    Frontend -->|"HTTP 8088"| Gateway

    Gateway -->|"REST /reports/**"| RM
    Gateway -->|"REST /videoAnalyses/**"| VP
    Gateway -->|"REST /events/**"| EM
    Gateway -->|"REST /aiAnalyses/**"| AI
    Gateway -->|"REST /posts/**"| FS
    Gateway -->|"REST /notifications/**"| NS

    RM -->|"Read/Write"| RMDB
    VP -->|"Read/Write"| VPDB
    EM -->|"Read/Write"| EMDB
    AI -->|"Read/Write"| AIDB
    FS -->|"Read/Write"| FSDB
    NS -->|"Read/Write"| NSDB

    RM -.->|"Publish ReportReceived"| Kafka
    Kafka -.->|"Subscribe ReportReceived"| VP

    VP -.->|"Publish VideoAnalyzed"| Kafka
    Kafka -.->|"Subscribe VideoAnalyzed"| EM

    EM -.->|"Publish IdentifiedAsFireEvent"| Kafka
    Kafka -.->|"Subscribe IdentifiedAsFireEvent"| AI

    AI -.->|"Publish AiAnalyzed"| Kafka
    Kafka -.->|"Subscribe AiAnalyzed"| FS

    FS -.->|"Publish PostPublished"| Kafka
    Kafka -.->|"Subscribe PostPublished"| NS

    %% Deployment Infra
    Infra --- Frontend
    Infra --- Gateway
    Infra --- RM
    Infra --- VP
    Infra --- EM
    Infra --- AI
    Infra --- FS
    Infra --- NS
    Infra --- Kafka

    %% Click Events
    click Frontend "https://github.com/baejihyun97/fire-response-system/tree/main/frontend/"
    click Gateway "https://github.com/baejihyun97/fire-response-system/tree/main/gateway/"
    click RM "https://github.com/baejihyun97/fire-response-system/tree/main/reportmanagement/src/main/java/fireresponsesystem/domain/"
    click VP "https://github.com/baejihyun97/fire-response-system/tree/main/videoproccessing/src/main/java/fireresponsesystem/domain/"
    click EM "https://github.com/baejihyun97/fire-response-system/tree/main/eventmanagement/src/main/java/fireresponsesystem/domain/"
    click AI "https://github.com/baejihyun97/fire-response-system/tree/main/aianalysis/src/main/java/fireresponsesystem/domain/"
    click FS "https://github.com/baejihyun97/fire-response-system/tree/main/feedservice/src/main/java/fireresponsesystem/domain/"
    click NS "https://github.com/baejihyun97/fire-response-system/tree/main/notification/src/main/java/fireresponsesystem/domain/"
    click Kafka "https://github.com/baejihyun97/fire-response-system/blob/main/infra/docker-compose.yml"
    click Infra "https://github.com/baejihyun97/fire-response-system/blob/main/kubernetes/template.yml"

    %% Styles
    classDef frontend fill:#b2f5b3,stroke:#2f855a,color:#2f855a;
    classDef gateway fill:#bee3f8,stroke:#4299e1,color:#2b6cb0;
    classDef service fill:#ebf8ff,stroke:#3182ce,color:#2c5282;
    classDef kafka fill:#fefcbf,stroke:#d69e2e,color:#b7791f;
    classDef db fill:#e2e8f0,stroke:#718096,color:#4a5568;
    classDef infra fill:#f7fafc,stroke:#a0aec0,color:#2d3748;
```
