# vizia-project/vizia-backend-service architecture

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

- Interactive diagram: https://gitdiagram.com/vizia-project/vizia-backend-service
- Repository: https://github.com/vizia-project/vizia-backend-service

## Overview

##### Main Components
- Microservices:
- Article Service: Handles scraping and serving eye health articles. Include an interaction node indicating that this service fetches and scrapes data.
- History Service: Manages storage and retrieval of user prediction/histories. Note its use of image uploads (via utilities) and validation.
- User Auth Service: Manages login/registration, user authentication, and authorization. Emphasize its route controllers and validations.
- Default Service: Provides OpenAPI documentation and may serve as the centralized documentation endpoint.
- Database Migrator: A separate module that runs KnexJS based database migrations for setting up the MySQL Cloud SQL database schema.
- Data Storage Components:
- Cloud SQL (MySQL): All microservices likely interact with a centralized MySQL database as indicated in the README.
- Cloud Storage: For storing any files (e.g., images uploaded in history or user auth services) as referenced in the environment variables.
- CI/CD Pipeline: Represent the .github workflows showing that GitHub Actions automates the deployment of individual services (article, history, user auth, and default).
- External Services / GCP Components: Include Google Cloud App Engine (for service hosting) and any managed services that support Cloud Storage and Cloud SQL.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Emphasize that the project has separated concerns by having dedicated services for articles, history, and user authentication.
- Separation of Concerns: Each service is self-contained, managing its own routes, controllers, configurations, and utilities.
- Continuous Deployment: The presence of GitHub Actions workflows for each service demonstrates automated CI/CD practices.
- Configuration Management: Each service has its own environment configuration file (.env.example) ensuring that sensitive settings (like DB credentials and JWT secrets) are properly abstracted.

##### Relevant Technologies and Frameworks
- Language & Framework: JavaScript with HapiJS in each microservice.
- Database: MySQL via Cloud SQL, with migrations maintained in a dedicated package.
- Cloud: Google Cloud Platform components (App Engine, Cloud Storage, Cloud SQL).
- API Documentation: Swagger/OpenAPI via the default-service and vizia-openapi.yaml.
- Build and Deployment: GitHub Actions (under .github/workflows).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["External Client"]:::external

    AG["API Gateway / Default Service"]:::gateway

    subgraph "Microservices"
        AS["Article Service: Scraping & Serving Articles"]:::micro
        HS["History Service: User Prediction History"]:::micro
        UA["User Auth Service: Authentication & Authorization"]:::micro
    end

    DM["Database Migrator"]:::migrator

    subgraph "Data Storage"
        SQL["Cloud SQL (MySQL)"]:::db
        ST["Cloud Storage"]:::db
    end

    subgraph "Deployment"
        CI["CI/CD Pipeline (GitHub Actions)"]:::deploy
        GCP["GCP App Engine"]:::deploy
    end

    %% External request flows
    Client -->|"sends request"| AG

    %% API Gateway routes to microservices
    AG -->|"routes to"| AS
    AG -->|"routes to"| HS
    AG -->|"routes to"| UA
    AG -->|"auth_check"| UA

    %% Microservices data interactions
    AS -->|"reads/writes"| SQL
    HS -->|"reads/writes"| SQL
    UA -->|"reads/writes"| SQL
    HS -->|"stores images"| ST
    UA -->|"stores images"| ST

    %% Database migrator manages DB schema
    DM -->|"migrates schema"| SQL

    %% Deployment flow
    CI -->|"triggers"| GCP
    GCP -->|"deploys"| AG
    GCP -->|"deploys"| AS
    GCP -->|"deploys"| HS
    GCP -->|"deploys"| UA
    GCP -->|"deploys"| DM

    %% Click Events
    click AG "https://github.com/vizia-project/vizia-backend-service/tree/main/default-service/"
    click AS "https://github.com/vizia-project/vizia-backend-service/blob/main/article-service/app.js"
    click HS "https://github.com/vizia-project/vizia-backend-service/blob/main/history-service/app.js"
    click UA "https://github.com/vizia-project/vizia-backend-service/blob/main/user-auth-service/app.js"
    click DM "https://github.com/vizia-project/vizia-backend-service/blob/main/database-migrator/knexfile.js"
    click CI "https://github.com/vizia-project/vizia-backend-service/blob/main/.github/workflows/article-service-deploy.yaml"

    %% Styles
    classDef gateway fill:#8ecae6,stroke:#023047,stroke-width:2px;
    classDef micro fill:#219ebc,stroke:#023047,stroke-width:2px;
    classDef migrator fill:#f4a261,stroke:#e76f51,stroke-width:2px;
    classDef db fill:#ffb703,stroke:#d62828,stroke-width:2px;
    classDef deploy fill:#90be6d,stroke:#43aa8b,stroke-width:2px;
    classDef external fill:#adb5bd,stroke:#6c757d,stroke-width:2px;
```
