# hunghero32/datn architecture

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

- Interactive diagram: https://gitdiagram.com/hunghero32/datn
- Repository: https://github.com/hunghero32/datn

## Overview

##### Project type and purpose
- This is a full-stack, multi-tier online booking system for medical appointments.
- Backend is a Laravel-based REST API plus a Blade-based admin portal.
- Frontend is a React single-page application serving both guest (patient) and doctor portals.
- A separate Python “chatbot” microservice provides automated symptom guidance.
- The system supports scheduling, user management, medical records, invoicing, real-time chat, push notifications, and payment integration.

##### Main components
a. Frontends
- Blade‐based Admin UI (Laravel views under backend/resources/views/admin)
- React SPA (guest & doctor portals in frontend/src/components)
b. Backend API (Laravel)
- HTTP layer: Controllers (app/Http/Controllers/*) separated into Admin, Client API, Doctor API, Auth
- Business logic: Services (app/Services), Repositories (app/Repositories), Events (app/Events)
- Data layer: Eloquent Models (app/Models) and Repositories, Migrations/Seeders (database/)
- Scheduling/Jobs: Artisan scheduler (Console/Commands), jobs table, queue workers
- Real-time: Broadcasting with Pusher (app/Events/MessageSent) and FirebaseService
c. Chatbot service
- Python REST microservice (chatbot/main.py) using training_data.json, exposed on its own port
d. Data stores
- Primary relational database (MySQL/PostgreSQL) for booking data, users, records, etc.
- Queue backend (Redis or database queue) for jobs, notifications
e. External services
- Push notifications (Firebase Cloud Messaging)
- Real-time channels (Pusher)
- Payment gateway API
- Email delivery (Mail services via Laravel Mail/Mailgun, SES, etc.)

##### Component interactions and data flow
- Users (guest, doctor) access the React SPA (http://localhost:3000) → sends API calls (REST/JSON) to Laravel API (http://localhost:8000/api/…)
- Administrators access the Laravel Blade admin portal (served under backend/public/admin) → interacts with Laravel controllers → database updates
- React SPA subscribes to Pusher channels → receives real-time chat and notification events broadcast by Laravel
- Laravel Scheduler / Artisan commands run periodic tasks (auto-update bookings, send reminders) → dispatch events or queue jobs
- Chat messages from users → Laravel ChatController broadcasts via Pusher → React chat UI
- Chatbot UI component in React calls Python microservice REST endpoint → returns automated responses
- Laravel’s NotificationService and FirebaseService push push‐notifications to mobile/web clients
- All data persistence occurs through Eloquent ORM → migrating via migrations and seeding initial data

##### Architectural patterns and design principles
- MVC on Laravel backend, layered service‐repository pattern for business logic & data access
- Modular controllers for each user role (Admin/Client/Doctor) and transport mechanism (web vs api)
- Event-driven real-time notifications (Laravel Events → Pusher/Firebase)
- Microservice separation for chatbot logic (Python service)
- SPA on the frontend using React, Redux for state, Axios for API calls
- Cron jobs via Laravel Scheduler for background tasks
- RESTful API design with versioning (client_api.php, doctor_api.php, api.php)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        Blade["Blade Admin UI"]:::frontend
        React["React SPA (Guest & Doctor)"]:::frontend
    end

    subgraph "Backend Service Cluster"
        subgraph "Controllers (HTTP Layer)"
            AdminCtrl["Admin Controllers"]:::backend
            ClientCtrl["Client API Controllers"]:::backend
            DoctorCtrl["Doctor API Controllers"]:::backend
            AuthCtrl["Auth Controllers"]:::backend
            ChatCtrl["Chat Controller"]:::backend
        end
        subgraph "Business Logic"
            Services["Services"]:::backend
            Repositories["Repositories"]:::backend
            Events["Events"]:::backend
        end
        subgraph "Scheduling & Jobs"
            Commands["Artisan Commands"]:::backend
            Kernel["Console Kernel"]:::backend
            QueueMigrate["Jobs Table Migration"]:::backend
        end
        subgraph "Real-time Broadcasting"
            EventRT["MessageSent Event"]:::backend
            FirebaseSvc["FirebaseService"]:::backend
            NotificationSvc["NotificationService"]:::backend
        end
    end

    Chatbot["Chatbot Microservice"]:::microservice

    subgraph "Data Stores"
        DB["Relational Database"]:::data
        Queue["Queue Backend (Redis)"]:::data
    end

    subgraph "External Services"
        Pusher["Pusher Channels"]:::external
        FCM["Firebase Cloud Messaging"]:::external
        Payment["Payment Gateway"]:::external
        Email["Email Delivery Service"]:::external
    end

    React -->|"REST API/JSON"| ClientCtrl
    React -->|"REST API/JSON"| DoctorCtrl
    Blade -->|"Web Requests"| AdminCtrl

    AdminCtrl -->|"calls"| Services
    ClientCtrl -->|"calls"| Services
    DoctorCtrl -->|"calls"| Services
    AuthCtrl -->|"auth via"| Services
    Services -->|"use"| Repositories
    Repositories -->|"ORM"| DB
    Services -->|"dispatch"| Events
    Events -->|"broadcast"| EventRT

    EventRT -->|"via WebSocket"| React
    EventRT -->|"via WebSocket"| Blade

    FirebaseSvc -->|"push via"| FCM
    NotificationSvc -->|"push via"| FCM

    Services -->|"queue jobs"| Queue
    Commands -->|"scheduled tasks"| Services
    Kernel -->|"schedules"| Commands
    QueueMigrate -->|"migrates"| DB

    ChatCtrl -->|"broadcast"| EventRT

    React -->|"Chat REST"| Chatbot
    Chatbot -->|"response"| React

    Services -->|"payment"| Payment
    Services -->|"email"| Email

    %% Click Events
    click Blade "https://github.com/hunghero32/datn/tree/dev/backend/resources/views/admin"
    click React "https://github.com/hunghero32/datn/tree/dev/frontend/src/components"
    click AdminCtrl "https://github.com/hunghero32/datn/tree/dev/backend/app/Http/Controllers/Admin"
    click ClientCtrl "https://github.com/hunghero32/datn/tree/dev/backend/app/Http/Controllers/Api/Client"
    click DoctorCtrl "https://github.com/hunghero32/datn/tree/dev/backend/app/Http/Controllers/Api/Doctor"
    click AuthCtrl "https://github.com/hunghero32/datn/tree/dev/backend/app/Http/Controllers/Auth"
    click ChatCtrl "https://github.com/hunghero32/datn/blob/dev/backend/app/Http/Controllers/ChatController.php"
    click Services "https://github.com/hunghero32/datn/tree/dev/backend/app/Services"
    click Repositories "https://github.com/hunghero32/datn/tree/dev/backend/app/Repositories"
    click Events "https://github.com/hunghero32/datn/blob/dev/backend/app/Events/MessageSent.php"
    click Commands "https://github.com/hunghero32/datn/tree/dev/backend/app/Console/Commands"
    click Kernel "https://github.com/hunghero32/datn/blob/dev/backend/app/Console/Kernel.php"
    click QueueMigrate "https://github.com/hunghero32/datn/blob/dev/backend/database/migrations/create_jobs_table.php"
    click FirebaseSvc "https://github.com/hunghero32/datn/blob/dev/backend/app/Services/FirebaseService.php"
    click NotificationSvc "https://github.com/hunghero32/datn/blob/dev/backend/app/Services/NotificationService.php"
    click Chatbot "https://github.com/hunghero32/datn/blob/dev/chatbot/main.py"

    %% Styles
    classDef frontend fill:#e0f7e9,stroke:#2e7d32,color:#2e7d32
    classDef backend fill:#e3f2fd,stroke:#1565c0,color:#1565c0
    classDef microservice fill:#fff3e0,stroke:#ef6c00,color:#ef6c00
    classDef data fill:#f5f5f5,stroke:#9e9e9e,color:#616161
    classDef external fill:#f3e5f5,stroke:#6a1b9a,color:#6a1b9a
```
