# project-refri/refri_be architecture

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

- Interactive diagram: https://gitdiagram.com/project-refri/refri_be
- Repository: https://github.com/project-refri/refri_be

## Overview

##### Main Components

a. API Services Layer:
- Spring API Service (api-spring)
- NestJS API Service (api)
- Image Processing Service (image-process)
- Data Processing Service (data-process)

b. Core Domain Services:
- Authentication Service (auth)
- User Management
- Ingredient Management
- Recipe Management
- Notification Service
- Image Processing

c. Infrastructure Components:
- MongoDB (indicated by mongo repositories)
- Redis Cache
- Prisma Database
- GCP (indicated by GCP workflows)

##### Architecture Patterns to Highlight

a. Microservices Architecture:
- Clear separation between Spring and NestJS services
- GRPC communication for image processing

b. Data Layer:
- Dual database architecture (MongoDB and Prisma)
- Redis caching layer
- Data flow patterns

##### Client Layer
- External API Consumers
- Mobile/Web Clients

##### API Gateway Layer
- Spring API Gateway
- NestJS API Gateway

- User Service  |  |    Recipe     |  |   Ingredient  |
- Service    |  |    Service    |

- Auth       |  |  Notification |  |     Image     |
- Service     |  |    Service    |  |   Processing  |

##### Data Layer

- MongoDB     |  |    Redis      |  |    Prisma     |
- (Primary)    |  |    Cache      |  |  Database     |

##### Important Elements

- Blue: API Gateways
- Green: Core Services
- Yellow: Data Stores
- Red: Critical Infrastructure

- REST API calls between services
- gRPC communication with image processing
- Database read/write operations
- Cache interactions

- Symbols for:
- Load balancers
- Security layers (auth)
- Message queues (if present)
- Monitoring points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        Client[Client Applications]
    end

    subgraph "API Gateway Layer"
        SpringAPI["Spring API Gateway"]:::apigateway
        NestAPI["NestJS API Gateway"]:::apigateway
    end

    subgraph "Service Layer"
        AuthService["Authentication Service"]:::service
        UserService["User Management Service"]:::service
        RecipeService["Recipe Management Service"]:::service
        IngredientService["Ingredient Management Service"]:::service
        NotificationService["Notification Service"]:::service
        ImageService["Image Service"]:::service
        ImageProcessing["Image Processing Service"]:::service
        DataProcessing["Data Processing Service"]:::service
    end

    subgraph "Data Layer"
        MongoDB[(MongoDB)]:::database
        Redis[(Redis Cache)]:::cache
        PrismaDB[(Prisma Database)]:::database
    end

    subgraph "Infrastructure"
        GCP["GCP Infrastructure"]:::infra
        Common["Common Infrastructure"]:::infra
    end

    %% Connections
    Client --> SpringAPI
    Client --> NestAPI
    
    SpringAPI --> AuthService
    SpringAPI --> UserService
    SpringAPI --> RecipeService
    SpringAPI --> IngredientService
    
    NestAPI --> AuthService
    NestAPI --> UserService
    NestAPI --> RecipeService
    NestAPI --> IngredientService
    NestAPI --> NotificationService
    NestAPI --> ImageService
    
    ImageService --> ImageProcessing
    ImageProcessing --> DataProcessing
    
    AuthService --> MongoDB
    UserService --> MongoDB
    RecipeService --> MongoDB
    IngredientService --> MongoDB
    NotificationService --> MongoDB
    
    AuthService --> Redis
    UserService --> Redis
    RecipeService --> Redis
    
    UserService --> PrismaDB
    RecipeService --> PrismaDB
    IngredientService --> PrismaDB
    
    %% Infrastructure Connections
    AuthService --> Common
    UserService --> Common
    RecipeService --> Common
    IngredientService --> Common
    NotificationService --> Common
    ImageService --> Common
    
    Common --> GCP

    %% Click Events
    click SpringAPI "https://github.com/project-refri/refri_be/tree/master/api-spring/"
    click NestAPI "https://github.com/project-refri/refri_be/tree/master/api/apps/api/"
    click ImageProcessing "https://github.com/project-refri/refri_be/tree/master/image-process/"
    click DataProcessing "https://github.com/project-refri/refri_be/tree/master/data-process/"
    click AuthService "https://github.com/project-refri/refri_be/tree/master/api/libs/auth/"
    click UserService "https://github.com/project-refri/refri_be/tree/master/api/libs/user/"
    click IngredientService "https://github.com/project-refri/refri_be/tree/master/api/libs/ingredient/"
    click RecipeService "https://github.com/project-refri/refri_be/tree/master/api/libs/recipe/"
    click NotificationService "https://github.com/project-refri/refri_be/tree/master/api/libs/noti/"
    click ImageService "https://github.com/project-refri/refri_be/tree/master/api/libs/image/"
    click MongoDB "https://github.com/project-refri/refri_be/tree/master/api/libs/common/src/mongo/"
    click Redis "https://github.com/project-refri/refri_be/tree/master/api/libs/common/src/cache/"
    click PrismaDB "https://github.com/project-refri/refri_be/tree/master/api/libs/common/src/prisma/"
    click Common "https://github.com/project-refri/refri_be/tree/master/api/libs/common/"
    click GCP "https://github.com/project-refri/refri_be/tree/master/.github/workflows/app-gcp-*"

    %% Styling
    classDef apigateway fill:#2374f7,stroke:#fff,stroke-width:2px,color:#fff
    classDef service fill:#47b347,stroke:#fff,stroke-width:2px,color:#fff
    classDef database fill:#ff9900,stroke:#fff,stroke-width:2px,color:#fff
    classDef cache fill:#ff6b6b,stroke:#fff,stroke-width:2px,color:#fff
    classDef infra fill:#6b6bff,stroke:#fff,stroke-width:2px,color:#fff

    %% Legend
    subgraph Legend
        L1["API Gateway"]:::apigateway
        L2["Service"]:::service
        L3["Database"]:::database
        L4["Cache"]:::cache
        L5["Infrastructure"]:::infra
    end
```
