# drmyth/hostrix architecture

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

- Interactive diagram: https://gitdiagram.com/drmyth/hostrix
- Repository: https://github.com/drmyth/hostrix

## Overview

##### Main Components
- API Server: Represent the core backend (found in the “api-server” directory) which includes controllers (authController, cacheController, deploymentController, logsController, projectController), routes, and service modules (for CloudFront, ECS, ELB, Kafka, Prisma client, etc.). This server orchestrates deployments and interacts with the database and external AWS services.
- Database: Indicate the PostgreSQL database managed through Prisma (see the “prisma” directory under api-server).
- Build Microservices: There are three distinct build services – dynamic-builds, serverless-builds, and static-builds. Each has its own Dockerfile, build scripts, and associated configurations. Represent these as distinct modules responsible for preparing, containerizing, and executing different deployment strategies.
- Reverse Proxy: The “reverse-proxy” component is responsible for handling and routing incoming requests to backend services, particularly integrating CDN caching mechanisms.
- External Cloud Infrastructure: Include AWS S3 (for static site storage), AWS CloudFront (for CDN and caching), AWS ECS (for running containers), AWS Cognito (for authentication), and other AWS services as needed.
- Logging/Message Queue: Represent Kafka as the mechanism used for capturing deployment logs and analytics.

##### Establish Relationships and Interactions
- The API Server acts as the central hub:
- It receives API requests, handles user authentication (via AWS Cognito settings in the config), and interacts with the database (through Prisma).
- It triggers deployment processes by interfacing with one or more build microservices (dynamic, serverless, or static) based on the type of application being deployed.
- The API Server’s controllers call on dedicated service modules that interact with AWS services (for ECS container management, setting up CloudFront distributions, etc.).
- The Reverse Proxy sits at the front, directing client requests to the appropriate backend endpoints and ensuring that caching policies are enforced.
- Logging is integrated via Kafka which collects and routes logs from the deployment processes for analysis.
- Containerization via Docker is used in the build modules, and these interact with the AWS infrastructure to perform actual deployment.

##### Relevant Architectural Patterns and Design Principles
- Modular/MVC Architecture: The api-server has a clear separation between its controllers, routes, and services – following MVC or modular patterns.
- Microservices/Containerization: The distinct “build” directories represent microservices that are containerized using Docker.
- Cloud-Abstraction: Infrastructure-as-a-service via AWS is abstracted within the services layer allowing for dynamic scaling and external integrations.
- Log-based Monitoring: Using Kafka for asynchronous logging and analytics ensures the system can monitor and analyze deployments efficiently.

##### Technologies, Frameworks, and External Services
- Node.js and Express are the backbone of the API server.
- Prisma is used for ORM interactions with PostgreSQL.
- AWS components (S3, CloudFront, ECS, and Cognito) are fundamental to deployment and security.
- Kafka handles logging and message queuing.
- Docker is critical for containerized builds in dynamic, serverless, and static build modules.

##### Detailing for the Specific Project Type
- For static websites: show the flow from build microservices to AWS S3 and through CloudFront.
- For serverless functions: include pathways showing how serverless-builds interact with CloudFront and API routing.
- Clearly present the separation of concerns so that one can see, at a glance, how the different deployment strategies are modularized and controlled.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Reverse Proxy
    subgraph "Reverse Proxy"
        RP("Reverse Proxy"):::proxy
    end

    %% Backend Components
    subgraph "Backend Components"
        API("API Server"):::backend
        DB("Database (Prisma/PostgreSQL)"):::database
    end

    %% Build Microservices
    subgraph "Build Microservices"
        Dyn("Dynamic Build Microservice"):::build
        Serv("Serverless Build Microservice"):::build
        Stat("Static Build Microservice"):::build
    end

    %% AWS Integration Configurations
    subgraph "AWS Integration"
        AWSConfig("AWS Config"):::aws
        CognConfig("Cognito Config"):::aws
    end

    %% External AWS Services
    subgraph "External AWS Services"
        S3("AWS S3"):::cloud
        CF("AWS CloudFront"):::cloud
        ECS("AWS ECS"):::cloud
        CognAWS("AWS Cognito"):::cloud
    end

    %% Logging/Message Queue
    subgraph "Logging/Message Queue"
        Kafka("Kafka Service"):::logging
    end

    %% Relationships
    RP -->|"routes"| API
    API -->|"queries"| DB
    API -->|"triggersDeployment"| Dyn
    API -->|"triggersDeployment"| Serv
    API -->|"triggersDeployment"| Stat
    API -->|"uses"| AWSConfig
    API -->|"uses"| CognConfig
    API -->|"orchestrates"| ECS
    API -->|"authVia"| CognAWS
    API -->|"sendsLogs"| Kafka

    Dyn -->|"deploysTo"| S3
    Dyn -->|"updates"| CF
    Serv -->|"deploysTo"| S3
    Serv -->|"updates"| CF
    Stat -->|"deploysTo"| S3
    Stat -->|"updates"| CF

    AWSConfig -->|"configures"| CF
    CognConfig -->|"configures"| CognAWS

    %% Styles
    classDef backend fill:#bbd,stroke:#333,stroke-width:2px;
    classDef database fill:#dfd,stroke:#333,stroke-width:2px;
    classDef build fill:#ffd,stroke:#333,stroke-width:2px;
    classDef proxy fill:#cfc,stroke:#333,stroke-width:2px;
    classDef aws fill:#fdd,stroke:#333,stroke-width:2px;
    classDef cloud fill:#9cf,stroke:#333,stroke-width:2px;
    classDef logging fill:#f9c,stroke:#333,stroke-width:2px;

    %% Click Events
    click API "https://github.com/drmyth/hostrix/tree/main/api-server/"
    click DB "https://github.com/drmyth/hostrix/tree/main/api-server/prisma/"
    click Dyn "https://github.com/drmyth/hostrix/tree/main/dynamic-builds/"
    click Serv "https://github.com/drmyth/hostrix/tree/main/serverless-builds/"
    click Stat "https://github.com/drmyth/hostrix/tree/main/static-builds/"
    click RP "https://github.com/drmyth/hostrix/tree/main/reverse-proxy/"
    click AWSConfig "https://github.com/drmyth/hostrix/blob/main/api-server/config/aws.js"
    click CognConfig "https://github.com/drmyth/hostrix/blob/main/api-server/config/cognito.js"
    click Kafka "https://github.com/drmyth/hostrix/blob/main/api-server/services/kafkaService.js"
```
