# quanganh247-qa/golang-pet-care architecture

> Architecture diagram of the GitHub repository quanganh247-qa/golang-pet-care, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/quanganh247-qa/golang-pet-care
- Repository: https://github.com/quanganh247-qa/golang-pet-care

## Overview

##### Project Type and Purpose
- This is a backend service written in Go that supports a React Native mobile application for pet clinics and pet owners. It offers functionalities like user management, pet management, medical record tracking, appointment scheduling, e-commerce (shopping cart, products, payment), location services, and AI-powered chatbot assistance.
- Its design leverages standard RESTful APIs, layered architecture (controllers, services, models), middleware for authentication/logging, and uses Docker for deployment.

##### Main Components to Highlight
a. API Server (Backend):
- Components in the “app/api” directory, such as endpoints for appointments, cart, chatbot, device_token, disease, doctor, invoice, location, medical records, medications, payment, pet, pet_schedule, products, rooms, search, service, test, user, vaccination.
- You note that the API layer uses Gin Web Framework, handling HTTP routing and controller logic.
b. Business Logic / Service Layer:
- Under “app/service”, include modules such as Elasticsearch integration, LLM (likely for chatbot and intelligent responses), mail sending, MinIO for object storage, Redis for caching and queue management, token (JWT management), websocket for real-time notification, and worker tasks.
c. Middleware:
d. Database & Data Access:
- The “app/db” directory contains migration scripts, SQL query files, and SQLC-generated Go code that abstracts database interactions. The primary database is PostgreSQL.
e. External Services Integration:
- External integrations provided by 3rd-party services such as:
- JWT for authentication.
- Goong Maps (location services).
- Gmail for email notifications.
- VietQR for payment integration.
- Google Gemini for chatbot enhancements.
- OpenFDA for drug and medical information.
f. Utility and Configuration:
- Components in “app/util” that handle configuration, custom responses, logging, error handling, validations, and connection initialization.
g. Docker & Deployment:
- Dockerfiles, docker-compose files, and Makefile targets indicate a containerized environment. These should be shown as part of the overall deployment environment.

##### Relationships and Interactions
- How the mobile client (React Native application) interacts with the API Gateway (the Gin server).
- That the API server routes HTTP requests through middleware before reaching the controller logic.
- The controllers in turn invoke services which handle the business logic and interact with the database (PostgreSQL) via SQLC code.
- Some services (like caching, queue/worker, file storage) interact with Redis, MinIO, and external services.

##### Architectural Patterns and Design Principles
- Layered architecture separating the API, business logic (services), and data access layers.
- Use of middleware for cross-cutting concerns (authentication, authorization, logging).
- Containerization using Docker, promoting microservice-like deployment even if it is a monolithic Go application.
- Integration of external microservices/APIs for maps, payment, and AI functionalities.
- Worker pattern for background tasks.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Mobile Client (React Native)"]:::mobile

    subgraph "API Layer"
        B["API Server (Gin)"]:::apiserver
        C["Middleware"]:::middleware
        subgraph "API Modules (Controllers)"
            D["Appointment Module"]:::controllers
            E["Cart Module"]:::controllers
            F["Chatbot Module"]:::controllers
            G["Device Token Module"]:::controllers
            H["Disease Module"]:::controllers
            I["Doctor Module"]:::controllers
            J["Invoice Module"]:::controllers
            K["Location Service (Goong Maps)"]:::controllers
            L["Medical Records Module"]:::controllers
            M["Medications Module"]:::controllers
            N["Payment Module"]:::controllers
            O["Pet Module"]:::controllers
            P["Pet Schedule Module"]:::controllers
            Q["Products Module"]:::controllers
            R["Rooms Module"]:::controllers
            S["Search Module"]:::controllers
            T["Service Module"]:::controllers
            U["Test Module"]:::controllers
            V["User Module"]:::controllers
            W["Vaccination Module"]:::controllers
        end
    end

    subgraph "Business Logic / Service Layer"
        X["Elasticsearch Integration"]:::service
        Y["LLM Integration"]:::service
        Z["Mail Sending"]:::service
        AA["MinIO Integration"]:::service
        AB["Redis Integration"]:::service
        AC["Token (JWT) Management"]:::service
        AD["WebSocket Notifications"]:::service
        AE["Worker Background Tasks"]:::service
    end

    AF["PostgreSQL DB"]:::db
    AG["Utility & Configuration"]:::util

    subgraph "External Services"
        AH["JWT Service"]:::external
        AI["Goong Maps Service"]:::external
        AJ["Gmail Service"]:::external
        AK["VietQR Payment Gateway"]:::external
        AL["Google Gemini"]:::external
        AM["OpenFDA Service"]:::external
    end

    AN["Containerization & Deployment"]:::deployment

    %% Connections
    A -->|"HTTP_Request"| B
    B -->|"Routes"| C
    C -->|"Passes_Request"| D

    %% Representative API Modules calling business logic
    D -->|"calls"| X
    E -->|"uses_cache"| AB
    V -->|"calls"| AC
    K -->|"calls"| AI
    N -->|"processes"| AK
    F -->|"calls"| Y
    M -->|"fetches_info"| AM

    %% Business Logic interactions
    AC -->|"validate"| AH
    Y -->|"enhance"| AL
    X -->|"stores_data"| AF
    AE -->|"processes_data"| AF
    Z -->|"sendEmail"| AJ
    AE -->|"triggers"| Z

    %% Infrastructure and deployment links
    B -->|"uses"| AG
    B -->|"deployed_with"| AN
    AD -->|"notify"| A

    %% Class Definitions for styling
    classDef mobile fill:#f9c,stroke:#333,stroke-width:2px;
    classDef apiserver fill:#bbf,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ccf,stroke:#333,stroke-width:2px;
    classDef controllers fill:#ddf,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef db fill:#fdd,stroke:#333,stroke-width:2px;
    classDef external fill:#fcf,stroke:#333,stroke-width:2px;
    classDef util fill:#cff,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ffc,stroke:#333,stroke-width:2px;

click B "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api"
click D "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/appointment"
click E "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/cart"
click F "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/chatbot"
click G "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/device_token"
click H "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/disease"
click I "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/doctor"
click J "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/invoice"
click K "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/location"
click L "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/medical_records"
click M "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/medications"
click N "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/payment"
click O "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/pet"
click P "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/pet_schedule"
click Q "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/products"
click R "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/rooms"
click S "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/search"
click T "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/service"
click U "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/test"
click V "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/user"
click W "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/api/vaccination"
click X "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/elasticsearch"
click Y "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/llm"
click Z "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/mail"
click AA "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/minio"
click AB "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/redis"
click AC "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/token"
click AD "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/websocket"
click AE "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/service/worker"
click C "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/middleware"
click AF "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/db"
click AG "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/app/util"
click AN "https://github.com/quanganh247-qa/golang-pet-care/tree/feature/golang/Dockerfile"
```
