# danielp41/engine_api_workflow architecture

> Architecture diagram of the GitHub repository danielp41/engine_api_workflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danielp41/engine_api_workflow
- Repository: https://github.com/danielp41/engine_api_workflow

## Overview

##### Project Type and Purpose
- This is a Go‐based, monolithic API backend (“Engine API Workflow”) built on the Fiber framework.
- It exposes HTTP endpoints to configure and execute business workflows, persists data in MongoDB, uses Redis for asynchronous queue processing, authenticates via JWT, and integrates with Slack, webhooks, or other external APIs.

##### File Structure
- Top level:
- cmd/api/main.go → entry point (Fiber server).
- internal/ → core application code, organized by layers:
– api/handlers, middleware, routes → HTTP layer
– services/ → business logic (auth, queue, workflow, integrations)
– repository/ → data access interfaces & implementations (MongoDB, Redis)
– models/ → domain entities (User, Workflow, Log)
– config, utils → configuration loading, error handling, validation, response helpers
- pkg/ → shared utilities (database connectors, logger, JWT lib)
- docker-compose.yml, Dockerfile, Makefile → container orchestration & build scripts
- .github/workflows → CI/CD pipeline definitions

##### README for Additional Insights
- Confirms tech stack: Go + Fiber, MongoDB, Redis, Docker, GitHub Actions
- Core features: configurable workflows, async processing, integrations, JWT/RBAC, logging/metrics

##### Main Components
a. Client Layer
- Web UI / CLI / External caller (sends HTTP requests carrying JWTs)
b. API Layer (cmd/api)
- Fiber HTTP server
- Middleware: Authentication (JWT + RBAC), CORS, Request Logging
- Router: maps paths to Handlers
- Handlers: auth.go, workflow.go, trigger.go, log.go
c. Service Layer (internal/services)
- AuthService
- WorkflowService (builds, reads, updates workflows)
- QueueService (publishes/subscribes to Redis)
- IntegrationService(s): Slack, Webhook
d. Data Access Layer (internal/repository + pkg/database)
- MongoDB repositories: user, workflow, log
- Redis repository: queue operations
- Shared connectors in pkg/database
e. Data Stores & Infrastructure
- MongoDB instance (container)
- Redis instance (container as queue store)
- Docker network orchestrating API, DB, Redis
- GitHub Actions CI/CD (build, test, Docker publish)
f. External Services
- Slack API
- Third‐party webhooks / external REST APIs

##### Relationships & Data Flows
- Client → HTTP(S) → API Layer (middleware → handlers)
- Handler → Service Layer (business logic)
- Service → Repository → Data Stores (read/write from MongoDB, enqueue/dequeue in Redis)
- QueueService → asynchronously triggers goroutines → IntegrationService → calls external Slack/Webhook
- AuthService ↔ JWT lib (pkg/jwt) for token signing/validation
- Logs: Handler/Service → LogRepository → MongoDB
- CI/CD pipeline: pushes code → GitHub Actions → builds Docker image → publishes

##### Architectural Patterns & Principles
- Layered architecture (HTTP → Services → Repositories → Data Store)
- Dependency inversion: handlers depend on service interfaces; services depend on repository interfaces
- Asynchronous processing via Redis queue + goroutines
- Configuration-driven (internal/config + .env)
- Containerized micro‐environments (not microservices, but separate containers)

##### Final Checklist
- Components labeled (e.g., “Auth Middleware”, “WorkflowRepository”).
- Boundaries drawn around containers (API app, DB, Queue).
- Annotations for async vs. sync flows, and any retries or error‐handling paths if relevant.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Client["Client (Web UI/CLI)"]:::external
    end

    %% API Container
    subgraph "API Container"
        direction TB
        Main["Fiber HTTP Server"]:::appComp
        subgraph "Middleware"
            direction TB
            AuthMW["Auth Middleware"]:::appComp
            CORSMW["CORS Middleware"]:::appComp
            LogMW["Request Logging Middleware"]:::appComp
        end
        Router["Router"]:::appComp
        subgraph "Handlers"
            direction TB
            AuthH["Auth Handler"]:::appComp
            WorkflowH["Workflow Handler"]:::appComp
            TriggerH["Trigger Handler"]:::appComp
            LogH["Log Handler"]:::appComp
        end
        subgraph "Services"
            direction TB
            AuthS["AuthService"]:::appComp
            WorkflowS["WorkflowService"]:::appComp
            QueueS["QueueService"]:::appComp
            subgraph "Integration Services"
                direction TB
                SlackS["Slack Integration"]:::appComp
                WebhookS["Webhook Integration"]:::appComp
            end
        end
        subgraph "Repositories"
            direction TB
            RepoIntf["Repository Interfaces"]:::appComp
            subgraph "MongoDB Repositories"
                direction TB
                UserRepo["UserRepository"]:::appComp
                WorkflowRepo["WorkflowRepository"]:::appComp
                LogRepo["LogRepository"]:::appComp
            end
            RedisRepo["Redis Queue Repository"]:::appComp
        end
        subgraph "Utilities"
            direction TB
            JWTUtil["JWT Utility"]:::appComp
            LoggerUtil["Logger Utility"]:::appComp
            Config["Config Loader"]:::appComp
            subgraph "Helpers"
                direction TB
                Errors["Error Definitions"]:::appComp
                Response["Response Helpers"]:::appComp
                Validation["Validation Helpers"]:::appComp
            end
        end
    end

    %% Data Stores
    subgraph "Data Store Container"
        direction TB
        MongoDB["MongoDB"]:::datastore
        Redis["Redis"]:::datastore
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        SlackAPI["Slack API"]:::external
        WebhookAPI["Third-Party Webhooks"]:::external
    end

    %% Infrastructure & CI/CD
    subgraph "Infrastructure & CI/CD"
        direction TB
        DockerComp["Docker Compose"]:::infra
        DockerfileNode["Dockerfile"]:::infra
        MakefileNode["Makefile"]:::infra
        GitHubActions["GitHub Actions"]:::infra
    end

    %% Connections
    Client -->|"HTTP with JWT"| Main
    Main --> AuthMW --> CORSMW --> LogMW --> Router
    Router --> AuthH
    Router --> WorkflowH
    Router --> TriggerH
    Router --> LogH
    AuthH --> AuthS
    WorkflowH --> WorkflowS
    TriggerH --> QueueS
    LogH --> LogRepo
    AuthS --> UserRepo
    WorkflowS --> WorkflowRepo
    WorkflowS --> LogRepo
    QueueS --> RedisRepo
    QueueS --> SlackS
    QueueS --> WebhookS
    AuthS --> JWTUtil
    AuthS --> UserRepo
    UserRepo -->|Writes/Reads| MongoDB
    WorkflowRepo -->|Writes/Reads| MongoDB
    LogRepo -->|Writes/Reads| MongoDB
    RedisRepo -->|Enqueue/Dequeue| Redis
    SlackS -->|"calls Slack API"| SlackAPI
    WebhookS -->|"calls Webhook"| WebhookAPI
    DockerComp --> Main
    DockerComp --> MongoDB
    DockerComp --> Redis
    GitHubActions --> DockerfileNode
    GitHubActions --> DockerComp

    %% Click Events
    click Main "https://github.com/danielp41/engine_api_workflow/blob/master/cmd/api/main.go"
    click AuthH "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/handlers/auth.go"
    click WorkflowH "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/handlers/workflow.go"
    click TriggerH "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/handlers/trigger.go"
    click LogH "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/handlers/log.go"
    click AuthMW "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/middleware/auth.go"
    click CORSMW "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/middleware/cors.go"
    click LogMW "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/middleware/logger.go"
    click Router "https://github.com/danielp41/engine_api_workflow/blob/master/internal/api/routes/routes.go"
    click AuthS "https://github.com/danielp41/engine_api_workflow/blob/master/internal/services/auth_service.go"
    click WorkflowS "https://github.com/danielp41/engine_api_workflow/blob/master/internal/services/workflow_service.go"
    click QueueS "https://github.com/danielp41/engine_api_workflow/blob/master/internal/services/queue_service.go"
    click SlackS "https://github.com/danielp41/engine_api_workflow/blob/master/internal/services/integration/slack.go"
    click WebhookS "https://github.com/danielp41/engine_api_workflow/blob/master/internal/services/integration/webhook.go"
    click RepoIntf "https://github.com/danielp41/engine_api_workflow/blob/master/internal/repository/interfaces.go"
    click UserRepo "https://github.com/danielp41/engine_api_workflow/blob/master/internal/repository/mongodb/user_repository.go"
    click WorkflowRepo "https://github.com/danielp41/engine_api_workflow/blob/master/internal/repository/mongodb/workflow_repository.go"
    click LogRepo "https://github.com/danielp41/engine_api_workflow/blob/master/internal/repository/mongodb/log_repository.go"
    click RedisRepo "https://github.com/danielp41/engine_api_workflow/blob/master/internal/repository/redis/queue_repository.go"
    click JWTUtil "https://github.com/danielp41/engine_api_workflow/blob/master/pkg/jwt/jwt.go"
    click LoggerUtil "https://github.com/danielp41/engine_api_workflow/blob/master/pkg/logger/logger.go"
    click Config "https://github.com/danielp41/engine_api_workflow/blob/master/internal/config/config.go"
    click Errors "https://github.com/danielp41/engine_api_workflow/blob/master/internal/utils/errors.go"
    click Response "https://github.com/danielp41/engine_api_workflow/blob/master/internal/utils/response.go"
    click Validation "https://github.com/danielp41/engine_api_workflow/blob/master/internal/utils/validation.go"
    click DockerComp "https://github.com/danielp41/engine_api_workflow/blob/master/docker-compose.yml"
    click DockerfileNode "https://github.com/danielp41/engine_api_workflow/tree/master/Dockerfile"
    click MakefileNode "https://github.com/danielp41/engine_api_workflow/tree/master/Makefile"
    click GitHubActions "https://github.com/danielp41/engine_api_workflow/blob/master/.github/workflows/ci.yml"
    click GitHubActions "https://github.com/danielp41/engine_api_workflow/blob/master/.github/workflows/docker-publish.yml"

    %% Styles
    classDef appComp fill:#d5f5e3,stroke:#27ae60,stroke-width:2px
    classDef datastore fill:#d6eaf8,stroke:#2980b9,stroke-width:2px
    classDef external fill:#f9e79f,stroke:#d68910,stroke-width:2px
    classDef infra fill:#ebedef,stroke:#7f8c8d,stroke-width:2px
```
