# khoa-cntt/ncvxdwyt1285 architecture

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

- Interactive diagram: https://gitdiagram.com/khoa-cntt/ncvxdwyt1285
- Repository: https://github.com/khoa-cntt/ncvxdwyt1285

## Overview

##### Project type and purpose
- This is a full-stack healthcare appointment and information system comprised of:
- A React-Redux single page application (kltn-react-healthcare) for patient and admin UIs
- A Node.js/Express back-end (kltn-node-healthcare) using Sequelize ORM for data persistence
- A relational database (MySQL or PostgreSQL via Sequelize)
- Integrations: Momo payment gateway, e-mail service, and an AI chat endpoint

##### File structure
- Top-level folders:
- kltn-node-healthcare: server-side code, migrations, models, controllers, services, routes, views (EJS)
- kltn-react-healthcare: client app, components, containers, redux store, assets, services, server (for SSR or proxy)
- Notice MVC-style separation in the back-end: controllers → services → models → migrations/seeders
- The React app uses a typical container/component split, Redux actions/reducers, plus axios for API calls
- External config files: .env, .babelrc, .sequelizerc, package.json, etc.

##### Key README insights
- Little in the root README; each subproject has its own README describing installation and run scripts
- Back-end README defines database config and environment variables
- Front-end README covers React build, .env for API URLs

##### Main components & interactions (to include
a. Client layer
- Web Browser (React SPA)
- Static assets served via React public folder or CDN
b. Front-end application
- React components / containers
- Redux store (actions, reducers)
- Axios HTTP client for REST API calls
c. Back-end application
- Express server (`server.js`)
- Route layer (`src/routes`, `web.js`, `aiChatRoute.js`, `momoRoute.js`)
- Controller layer (e.g., authController, patientController…)
- Service layer (CRUDservice, authService, patientService…)
- Models (Sequelize definitions) & Migrations/Seeders
- View Engine (EJS templates for admin CRUD pages)
d. Data layer
- Relational Database (MySQL/PostgreSQL)
e. External services
- Momo Payment Gateway (payment initiation & callbacks)
- Email Service (SMTP / third-party provider)
- AI Chat Service (external AI API)

##### Relationships & data flows
- Browser → React UI
- React → Redux Dispatch → Axios → Express REST endpoints
- Express Routes → Controllers → Services → Models → Database
- Services may call external APIs:
- Momo service for payment requests/callbacks
- Email service for confirmations
- AI Chat endpoint for patient support
- Database migrations and seeders are run at deploy time to prepare schema

##### Architectural patterns & principles
- Layered architecture (presentation, application, domain, persistence)
- MVC on the server side
- Component/Container pattern on the client side
- Redux for state management
- RESTful API design
- Environment-based configuration

##### Technologies & frameworks
- Front-end: React, Redux, Axios, SASS/SCSS, Webpack (via Create React App), service workers
- Back-end: Node.js, Express, Sequelize ORM, EJS, dotenv, Nodemailer (or custom email), Momo SDK
- Database: MySQL or PostgreSQL (configured in `config/config.json`)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        Browser["User Browser"]:::external
        ReactSPA["React SPA"]:::frontend
        Components["Components"]:::frontend
        Containers["Containers"]:::frontend
        Store["Redux Store"]:::frontend
        Axios["Axios HTTP Client"]:::frontend
        SW["Service Worker"]:::frontend
    end

    Browser --> ReactSPA
    ReactSPA --> Components
    ReactSPA --> Containers
    ReactSPA --> Store
    ReactSPA --> SW
    Store --> Axios
    Components --> Axios
    Containers --> Axios
    Axios --> Express

    subgraph "Server Layer"
        Express["Express Server (server.js)"]:::backend
        subgraph "Routes"
            WebRoute["web.js"]:::backend
            MomoRoute["momoRoute.js"]:::backend
            AIChatRoute["aiChatRoute.js"]:::backend
        end
        subgraph "Controllers"
            ControllersNode["Controllers (*.js)"]:::backend
        end
        subgraph "Services"
            ServicesNode["Services (*.js)"]:::backend
            MomoSDK["Momo SDK (momo.js)"]:::backend
            EmailSvc["Email Service (emailService.js)"]:::backend
        end
        subgraph "Models & DB Setup"
            Models["Sequelize Models"]:::backend
            Migrations["Database Migrations"]:::backend
            Seeders["Database Seeders"]:::backend
        end
        subgraph "Config"
            Env[".env.example"]:::backend
            DBConfig["config.json"]:::backend
            DBConnect["connectDB.js"]:::backend
            ViewEngine["viewEngine.js"]:::backend
        end
        subgraph "Utilities & Views"
            Utils["Utilities (index.js)"]:::backend
            Views["Views (EJS templates)"]:::backend
        end
    end

    Express --> WebRoute
    Express --> MomoRoute
    Express --> AIChatRoute
    WebRoute --> ControllersNode
    MomoRoute --> ControllersNode
    AIChatRoute --> ControllersNode
    ControllersNode --> ServicesNode
    ServicesNode --> Models
    ServicesNode --> MomoSDK
    ServicesNode --> EmailSvc
    Models --> Migrations
    Models --> Seeders
    Express --> DBConnect
    DBConnect --> DBConfig
    Express --> ViewEngine
    Express --> Utils
    Express --> Views

    MomoRoute -->|webhook| MomoSDK
    ServicesNode -->|SMTP/API| EmailSvc

    Models --> Database
    DBConnect --> Database

    subgraph "External Services"
        MomoCloud["Momo Payment Gateway"]:::external
        EmailCloud["Email Service"]:::external
        AIChatCloud["AI Chat API"]:::external
    end

    MomoSDK --> MomoCloud
    EmailSvc --> EmailCloud
    ServicesNode --> AIChatCloud

    classDef frontend fill:#AED6F1,stroke:#1B4F72,color:#154360
    classDef backend fill:#A3E4D7,stroke:#117A65,color:#0E6655
    classDef data fill:#ABEBC6,stroke:#239B56,color:#145A32
    classDef external fill:#F9E79F,stroke:#B7950B,color:#7D6608

    Database["Database (MySQL/PostgreSQL)"]:::data

    click ReactSPA "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-react-healthcare/src"
    click Components "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-react-healthcare/src/components"
    click Containers "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-react-healthcare/src/containers"
    click Store "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-react-healthcare/src/store"
    click Axios "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-react-healthcare/src/axios.js"
    click SW "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-react-healthcare/src/serviceWorker.js"
    click Express "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/server.js"
    click Env "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/.env.example"
    click DBConfig "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/config/config.json"
    click DBConnect "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/config/connectDB.js"
    click ViewEngine "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/config/viewEngine.js"
    click WebRoute "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/route/web.js"
    click MomoRoute "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/routes/momoRoute.js"
    click AIChatRoute "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/routes/aiChatRoute.js"
    click ControllersNode "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/controllers/*.js"
    click ServicesNode "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/services/*.js"
    click MomoSDK "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/payments/momo.js"
    click EmailSvc "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/services/emailService.js"
    click Models "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-node-healthcare/src/models"
    click Migrations "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-node-healthcare/src/migrations"
    click Seeders "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-node-healthcare/src/seeders"
    click Utils "https://github.com/khoa-cntt/ncvxdwyt1285/blob/main/kltn-node-healthcare/src/utils/index.js"
    click Views "https://github.com/khoa-cntt/ncvxdwyt1285/tree/main/kltn-node-healthcare/src/views"
```
