# phobiavr/phober architecture

> Architecture diagram of the GitHub repository phobiavr/phober, 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/phobiavr/phober
- Repository: https://github.com/phobiavr/phober

## Overview

##### Main Components
- API Gateway:
- API Gateway container (located under docker/api-gateway) as the single entry point for all client requests.
- How routing is handled, with URL path prefixes (/auth, /hardware, /crm, /staff) mapping to appropriate microservices.
- Microservices:
- Service residing in the “services” folder, including adminpanel, auth-server, config-server, crm-service, device-service, notification-server, and staff-service.
- That each of these microservices is an independent module, with internal communication managed via the API Gateway.
- Shared Components:
- A component or library layer for “shared/laravel-common” that is used across multiple services.
- Media/Buckets:
- Interactions: the adminpanel for read/write access and device-service for read-only access.
- Database Containers:
- Various database instances (MySQL, Postgres, Oracle, SQLite, SQL Server) which are available as Docker containers. These might be drawn either as separate blocks or as a “Database Layer” that the services interact with.
- Docker Infrastructure:
- Supporting Tools:
- Logging/monitoring via the ELK stack (from docker/elk) if deemed critical to the overall system’s observability.

##### Relationships and Data Flow
- Optionally, show how shared components are imported/used by multiple microservices.

##### Architectural Patterns & Design Principles
- Microservices architecture pattern by clearly segregating the API Gateway, multiple backend services, and storage layers.
- Separation of concerns: the API Gateway isolates client interaction and routing, while each microservice handles domain-specific logic.
- Mention that the inter-service communication is abstracted, potentially through REST APIs, as suggested by the provided Postman collection.
- Usage of Docker Compose and containerization as a key operational pattern that supports the deployment and scalability aspects.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client Requests"):::client

    APIGateway("API Gateway (Routing)"):::gateway

    subgraph "Microservices Layer"
        AdminPanel("Admin Panel Microservice"):::service
        AuthServer("Auth Server Microservice"):::service
        ConfigServer("Config Server Microservice"):::service
        CRMService("CRM Service Microservice"):::service
        DeviceService("Device Service Microservice"):::service
        NotificationServer("Notification Server Microservice"):::service
        StaffService("Staff Service Microservice"):::service
    end

    Shared("Shared Laravel Common Library"):::shared

    Buckets("Media/Buckets Storage"):::storage

    subgraph "Database Layer"
        MySQL("MySQL Database"):::database
        Postgres("Postgres Database"):::database
        Oracle("Oracle Database"):::database
        SQLite("SQLite Database"):::database
        SQLServer("SQL Server Database"):::database
    end

    subgraph "Infrastructure Layer"
        DockerInfra("Docker Compose & Orchestration"):::infra
        PhoberPHP("PHP/Laravel Runtime (Phober PHP)"):::infra
    end

    ELK("Logging/Monitoring (ELK Stack)"):::monitoring

    %% Data Flow Connections
    Client -->|"requests"| APIGateway

    APIGateway -->|"routes:/auth"| AuthServer
    APIGateway -->|"routes:/crm"| CRMService
    APIGateway -->|"routes:/hardware"| DeviceService
    APIGateway -->|"routes:/staff"| StaffService
    APIGateway -->|"routes:/admin"| AdminPanel
    APIGateway -->|"routes:/config"| ConfigServer
    APIGateway -->|"routes:/notify"| NotificationServer

    %% Microservices using shared library
    AdminPanel --- Shared
    AuthServer --- Shared
    ConfigServer --- Shared
    CRMService --- Shared
    DeviceService --- Shared
    NotificationServer --- Shared
    StaffService --- Shared

    %% Media/Buckets Relationships
    AdminPanel -- "read/write" --> Buckets
    DeviceService -- "read-only" --> Buckets

    %% Microservices Database Connections (dotted lines indicate flexible DB support)
    AdminPanel -.-> MySQL
    AdminPanel -.-> Postgres
    AuthServer -.-> MySQL
    AuthServer -.-> SQLite
    ConfigServer -.-> SQLServer
    CRMService -.-> Postgres
    DeviceService -.-> Oracle
    NotificationServer -.-> MySQL
    StaffService -.-> SQLServer

    %% All components run within Docker Infrastructure
    APIGateway --- DockerInfra
    AdminPanel --- DockerInfra
    AuthServer --- DockerInfra
    ConfigServer --- DockerInfra
    CRMService --- DockerInfra
    DeviceService --- DockerInfra
    NotificationServer --- DockerInfra
    StaffService --- DockerInfra
    MySQL --- DockerInfra
    Postgres --- DockerInfra
    Oracle --- DockerInfra
    SQLite --- DockerInfra
    SQLServer --- DockerInfra
    PhoberPHP --- DockerInfra
    ELK --- DockerInfra

    %% Logging/Monitoring links to services and API Gateway
    APIGateway --- ELK
    AdminPanel --- ELK
    AuthServer --- ELK
    ConfigServer --- ELK
    CRMService --- ELK
    DeviceService --- ELK
    NotificationServer --- ELK
    StaffService --- ELK

    %% Click Events
    click APIGateway "https://github.com/phobiavr/phober/tree/master/docker/api-gateway"
    click AdminPanel "https://github.com/phobiavr/phober/tree/master/services/adminpanel"
    click AuthServer "https://github.com/phobiavr/phober/tree/master/services/auth-server"
    click ConfigServer "https://github.com/phobiavr/phober/tree/master/services/config-server"
    click CRMService "https://github.com/phobiavr/phober/tree/master/services/crm-service"
    click DeviceService "https://github.com/phobiavr/phober/tree/master/services/device-service"
    click NotificationServer "https://github.com/phobiavr/phober/tree/master/services/notification-server"
    click StaffService "https://github.com/phobiavr/phober/tree/master/services/staff-service"
    click Shared "https://github.com/phobiavr/phober/tree/master/shared/laravel-common"
    click Buckets "https://github.com/phobiavr/phober/tree/master/buckets"
    click MySQL "https://github.com/phobiavr/phober/tree/master/docker/mysql"
    click Postgres "https://github.com/phobiavr/phober/tree/master/docker/postgres"
    click Oracle "https://github.com/phobiavr/phober/tree/master/docker/oracle"
    click SQLite "https://github.com/phobiavr/phober/tree/master/docker/sqlite"
    click SQLServer "https://github.com/phobiavr/phober/tree/master/docker/sqlsrv"
    click DockerInfra "https://github.com/phobiavr/phober/tree/master/docker/"
    click PhoberPHP "https://github.com/phobiavr/phober/tree/master/docker/phober-php"
    click ELK "https://github.com/phobiavr/phober/tree/master/docker/elk"

    %% Style Definitions
    classDef client fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef gateway fill:#FFB347,stroke:#333,stroke-width:2px;
    classDef service fill:#B0E57C,stroke:#333,stroke-width:2px;
    classDef shared fill:#FFD1DC,stroke:#333,stroke-width:2px;
    classDef storage fill:#FDFD96,stroke:#333,stroke-width:2px;
    classDef database fill:#FF6961,stroke:#333,stroke-width:2px;
    classDef infra fill:#AEC6CF,stroke:#333,stroke-width:2px;
    classDef monitoring fill:#CFCFC4,stroke:#333,stroke-width:2px;
```
