# sparrowapp-dev/sparrow-api architecture

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

- Interactive diagram: https://gitdiagram.com/sparrowapp-dev/sparrow-api
- Repository: https://github.com/sparrowapp-dev/sparrow-api

## Overview

##### Main Components Identification

The system should be divided into these major components:

a. Core Modules:
- Identity Module (Authentication/Authorization)
- Workspace Module (API Management)
- Proxy Module (API Communication)
- Common Module (Shared Services)

b. External Services:
- MongoDB Database
- Kafka Message Broker
- Blob Storage
- Email Service
- HubSpot Integration

**Client Layer**

**API Gateway Layer (NestJS)**

**Service Layer**
- Identity Services
- Workspace Services
- Proxy Services
- Common Services

**Data Access Layer**
- Repositories
- External Services

##### Component Details

a. Identity Module (Authentication):
- User management and team collaboration features
- Connection to email service for notifications

b. Workspace Module:
- Collection management
- Environment handling
- AI Assistant integration
- Test flow management
- Feature management

c. Proxy Module:
- HTTP controller
- WebSocket gateway
- SocketIO gateway
- Custom adapters

d. Common Services:
- Kafka message handling (producers/consumers)
- Blob storage service
- Email service
- Parser service
- API response service

##### Data Flow Visualization

- → Synchronous communication
- ⇢ Asynchronous communication (Kafka)
- ⇄ WebSocket connections

##### Additional Elements

- Security layer (Guards, JWT, OAuth)
- Error handling and logging
- Configuration management
- Environment separation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CL["Client Layer"]
        Client["Client Applications"]
    end

    subgraph GL["API Gateway Layer"]
        Gateway["NestJS Gateway"]
    end

    subgraph SL["Service Layer"]
        subgraph IM["Identity Module"]
            AuthService["Authentication Service"]:::service
            HubSpotService["HubSpot Integration"]:::service
            AuthStrategies["Auth Strategies"]:::service
        end

        subgraph WM["Workspace Module"]
            CollectionService["Collection Management"]:::service
            EnvService["Environment Handling"]:::service
            AIService["AI Assistant"]:::service
            TestFlowService["Test Flow Management"]:::service
        end

        subgraph PM["Proxy Module"]
            HTTPController["HTTP Controller"]:::service
            WSGateway["WebSocket Gateway"]:::service
            SocketIOGateway["SocketIO Gateway"]:::service
            CustomAdapters["Custom Adapters"]:::service
        end

        subgraph CM["Common Module"]
            KafkaProducer["Kafka Producer"]:::service
            KafkaConsumer["Kafka Consumer"]:::service
            BlobStorage["Blob Storage Service"]:::service
            EmailService["Email Service"]:::service
            ParserService["Parser Service"]:::service
            APIResponse["API Response Service"]:::service
        end
    end

    subgraph DAL["Data Access Layer"]
        subgraph SEC["Security"]
            Guards["Guards"]:::security
            JWTAuth["JWT Auth"]:::security
            OAuth["OAuth"]:::security
        end

        subgraph REP["Repositories"]
            IdentityRepo["Identity Repository"]:::repo
            WorkspaceRepo["Workspace Repository"]:::repo
        end

        subgraph MOD["Data Models"]
            UserModel["User Model"]:::model
            WorkspaceModel["Workspace Model"]:::model
            CollectionModel["Collection Model"]:::model
            EnvironmentModel["Environment Model"]:::model
        end
    end

    subgraph EXT["External Services"]
        MongoDB[(MongoDB)]:::database
        Kafka[("Kafka")]:::messagebroker
        BlobStore[(Blob Storage)]:::storage
        Email["Email Service"]:::external
        HubSpot["HubSpot"]:::external
    end

    %% Connections
    Client --> Gateway
    Gateway --> IM
    Gateway --> WM
    Gateway --> PM
    Gateway --> CM

    %% Identity Module Connections
    AuthService --> Guards
    AuthService --> JWTAuth
    AuthService --> OAuth
    AuthService --> IdentityRepo
    HubSpotService --> HubSpot

    %% Workspace Module Connections
    CollectionService --> WorkspaceRepo
    EnvService --> WorkspaceRepo
    TestFlowService --> WorkspaceRepo

    %% Common Module Connections
    KafkaProducer --> Kafka
    KafkaConsumer --> Kafka
    BlobStorage --> BlobStore
    EmailService --> Email

    %% Data Layer Connections
    IdentityRepo --> MongoDB
    WorkspaceRepo --> MongoDB

    %% Styles
    classDef service fill:#3498db,stroke:#2980b9,color:white
    classDef security fill:#f1c40f,stroke:#f39c12,color:black
    classDef repo fill:#2ecc71,stroke:#27ae60,color:white
    classDef model fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#34495e,stroke:#2c3e50,color:white
    classDef messagebroker fill:#e74c3c,stroke:#c0392b,color:white
    classDef storage fill:#1abc9c,stroke:#16a085,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Click Events
    click AuthService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/identity/services/auth.service.ts"
    click HubSpotService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/identity/services/hubspot.service.ts"
    click AuthStrategies "https://github.com/sparrowapp-dev/sparrow-api/tree/development/src/modules/identity/strategies"
    click CollectionService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/workspace/services/collection.service.ts"
    click EnvService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/workspace/services/environment.service.ts"
    click AIService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/workspace/services/ai-assistant.service.ts"
    click TestFlowService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/workspace/services/testflow.service.ts"
    click HTTPController "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/proxy/controllers/http.controller.ts"
    click WSGateway "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/proxy/gateway/websocket.gateway.ts"
    click SocketIOGateway "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/proxy/gateway/socketio.gateway.ts"
    click CustomAdapters "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/proxy/adapters/custom-websocket-adapter.ts"
    click KafkaProducer "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/services/kafka/producer.service.ts"
    click KafkaConsumer "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/services/kafka/consumer.service.ts"
    click BlobStorage "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/services/blobStorage.service.ts"
    click EmailService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/services/email.service.ts"
    click ParserService "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/services/parser.service.ts"
    click APIResponse "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/services/api-response.service.ts"
    click Guards "https://github.com/sparrowapp-dev/sparrow-api/tree/development/src/modules/common/guards"
    click JWTAuth "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/guards/jwt-auth.guard.ts"
    click OAuth "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/guards/google-oauth.guard.ts"
    click UserModel "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/models/user.model.ts"
    click WorkspaceModel "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/models/workspace.model.ts"
    click CollectionModel "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/models/collection.model.ts"
    click EnvironmentModel "https://github.com/sparrowapp-dev/sparrow-api/blob/development/src/modules/common/models/environment.model.ts"
    click IdentityRepo "https://github.com/sparrowapp-dev/sparrow-api/tree/development/src/modules/identity/repositories"
    click WorkspaceRepo "https://github.com/sparrowapp-dev/sparrow-api/tree/development/src/modules/workspace/repositories"
```
