# hcmus-project/servicebooking architecture

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

- Interactive diagram: https://gitdiagram.com/hcmus-project/servicebooking
- Repository: https://github.com/hcmus-project/servicebooking

## Overview

##### Main System Components

a) API Layer:
- gRPC Service Endpoints (shown in /src/proto folder)
- Controllers (booking, employee, services, voucher, review)

b) Core Services:
- Database Services (Prisma + MongoDB)
- Cache Service
- Logger Service
- Queue Service
- External Services Integration

c) Feature Modules:
- Booking System
- Employee Management
- Services Management
- Review System
- Voucher System

##### Architecture Representation

**┌─────────────────────────────────────────────────────────────┐**
- gRPC API Gateway                        │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- NestJS Core Layer                       │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
- Guards    │  │Interceptors │  │  Exception Filters  │ │
- ┘  └─────────────┘  └─────────────────────┘ │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Feature Modules                         │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
- Booking   │  │  Employee   │  │      Services       │ │
- ┘  └─────────────┘  └─────────────────────┘ │
- ┌─────────────┐  ┌─────────────┐                          │
- Review    │  │   Voucher   │                          │
- ┘  └─────────────┘                          │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Core Services                           │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
- Cache    │  │   Logger    │  │       Queue         │ │
- ┘  └─────────────┘  └─────────────────────┘ │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Data Layer                              │
- ┌─────────────┐  ┌─────────────┐                          │
- Prisma    │  │   MongoDB   │                          │
- ┘  └─────────────┘                          │
- ┘

##### Connection Types

→ Synchronous calls
⇢ Asynchronous calls
⇄ Two-way communication

##### Additional Details

Annotations for:
- Environment configurations
- Authentication flow
- Error handling
- Logging mechanisms
- Cache strategies
- Queue processing

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "gRPC API Gateway"
        GRPC["gRPC Service Endpoints"]:::api
        PROTO["Proto Definitions"]:::api
    end

    subgraph "NestJS Core Layer"
        GUARDS["Guards"]:::core
        INTER["Interceptors"]:::core
        EXCEPT["Exception Filters"]:::core
    end

    subgraph "Feature Modules"
        BOOK["Booking Module"]:::feature
        EMP["Employee Module"]:::feature
        SERV["Services Module"]:::feature
        REV["Review Module"]:::feature
        VOUCH["Voucher Module"]:::feature
        EXT["External Services"]:::feature
    end

    subgraph "Core Services"
        CACHE["Cache Service"]:::core
        LOG["Logger Service"]:::core
        QUEUE["Queue Service"]:::core
        CONF["Configuration"]:::core
        RESP["Response Handler"]:::core
    end

    subgraph "Utility Services"
        EMAIL["Email Service"]:::util
        STORAGE["Storage Service"]:::util
        TIME["Time Utilities"]:::util
    end

    subgraph "Data Layer"
        PRISMA["Prisma Service"]:::data
        MONGO["MongoDB Service"]:::data
        SCHEMA["Database Schema"]:::data
    end

    GRPC --> PROTO
    PROTO --> |gRPC Calls| GUARDS
    GUARDS --> INTER
    INTER --> EXCEPT
    EXCEPT --> |Route to| BOOK & EMP & SERV & REV & VOUCH
    BOOK & EMP & SERV & REV & VOUCH --> |Use| CACHE
    BOOK & EMP & SERV & REV & VOUCH --> |Use| LOG
    BOOK & EMP & SERV & REV & VOUCH --> |Use| QUEUE
    BOOK & EMP & SERV & REV & VOUCH --> |External Calls| EXT
    EXT --> |Profile Services| BOOK
    CACHE & LOG & QUEUE --> |Data Operations| PRISMA
    PRISMA --> SCHEMA
    SCHEMA --> MONGO
    BOOK & EMP & SERV & REV & VOUCH --> |Utilize| EMAIL & STORAGE & TIME

    %% Click Events
    click PROTO "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/proto"
    click BOOK "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/features/booking"
    click EMP "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/features/employee"
    click SERV "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/features/services"
    click REV "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/features/review"
    click VOUCH "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/features/voucher"
    click CACHE "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/core/cache"
    click LOG "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/core/logger"
    click QUEUE "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/core/queue"
    click PRISMA "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/core/prisma"
    click MONGO "https://github.com/HCMUS-Project/ServiceBooking/blob/main//src/core/database/services/mongo.service.ts"
    click SCHEMA "https://github.com/HCMUS-Project/ServiceBooking/blob/main//prisma/schema.prisma"
    click CONF "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/configs"
    click RESP "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/core/response"
    click EXT "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/features/external_services"
    click EMAIL "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/util/brevo_mailer"
    click STORAGE "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/util/supabase"
    click TIME "https://github.com/HCMUS-Project/ServiceBooking/tree/main//src/util/time"

    classDef api fill:#2196F3,stroke:#1976D2,color:white
    classDef core fill:#4CAF50,stroke:#388E3C,color:white
    classDef feature fill:#FFC107,stroke:#FFA000,color:black
    classDef data fill:#F44336,stroke:#D32F2F,color:white
    classDef util fill:#9C27B0,stroke:#7B1FA2,color:white

    %% Legend
    subgraph Legend
        API[API Components]:::api
        CORE[Core Components]:::core
        FEAT[Feature Modules]:::feature
        DATA[Data Components]:::data
        UTILS[Utility Services]:::util
    end
```
