# wei-hsiang86/care-together architecture

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

- Interactive diagram: https://gitdiagram.com/wei-hsiang86/care-together
- Repository: https://github.com/wei-hsiang86/care-together

## Overview

##### Project type and purpose
- Care-Together is a full-stack web application built with Node.js, Express, Sequelize (MySQL) and Handlebars.
- It serves two user roles—patients and medical staff—allowing patients to log vitals and social interactions, and staff to review, annotate, and record medical cases.

##### File structure
- Top-level artifacts:
- app.js – entry point, Express app setup
- config/ – database and authentication configuration (Sequelize, Passport)
- controllers/ – request handlers organized by domain (user, patient, comment, note, record, friend, contest, admin)
- models/ – Sequelize models and associations for user, patient, records, notes, comments, friendships, acquaintance
- routes/ – Express routers that map URL paths to controllers
- middleware/ – Express middleware for auth, file upload (multer), error handling
- views/ – Handlebars templates (layouts, partials, domain views)
- public/ – static assets and client-side scripts
- migrations/ & seeders/ – Sequelize schema and data initialization
- Architectural pattern: Classic MVC layered: routes → controllers → models → database; views rendered on server.

##### README
- Describes key features: user registration, login, vitals submission, social/friend features, annotations, record keeping.
- Tech stack: Node, Express, MySQL, Sequelize, Handlebars, Passport.

##### Detailed capture of essential elements
- For each feature (e.g., “Add Patient Data”), annotate which controller, model, and view are involved.
- Authentication flow: login route → Passport middleware → session store.
- File-upload path: Browser → Multer middleware → Disk (public/demo or uploads).
- Friend/Acquaintance management: controllers invoking `friendship` and `acquaintance` models.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Client Browser (UI)"]:::client
        PublicAssets["Static Assets (public/)"]:::static
    end

    %% Application Layer
    subgraph "Application Layer"
        App["Express App (app.js)"]:::server
        subgraph "Configuration"
            ConfigDB["config/config.js"]:::server
            PassportConfig["config/passport.js"]:::server
        end
        subgraph "Routes"
            IndexRoute["routes/index.js"]:::server
            AdminRoute["routes/modules/admin.js"]:::server
        end
        subgraph "Middleware"
            AuthMW["middleware/auth.js"]:::server
            MulterMW["middleware/multer.js"]:::server
            ErrorMW["middleware/error-handler.js"]:::server
        end
        subgraph "Controllers"
            UserCtrl["controllers/user-controller.js"]:::server
            PatientCtrl["controllers/patient-controller.js"]:::server
            RecordCtrl["controllers/record-controller.js"]:::server
            NoteCtrl["controllers/note-controller.js"]:::server
            CommentCtrl["controllers/comment-controller.js"]:::server
            FriendCtrl["controllers/friend-controller.js"]:::server
            ContestCtrl["controllers/contest-controller.js"]:::server
            AdminCtrl["controllers/admin-controller.js"]:::server
        end
        subgraph "Helpers"
            AuthHelpers["helpers/auth-helpers.js"]:::server
            FileHelpers["helpers/file-helpers.js"]:::server
            HBSHelpers["helpers/handlebars-helpers.js"]:::server
            PaginationHelper["helpers/pagination-helper.js"]:::server
        end
        Views["Handlebars Views (views/)"]:::server
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "ORM Layer"
            ModelsIndex["models/index.js"]:::server
            UserModel["models/user.js"]:::server
            PatientModel["models/patient.js"]:::server
            RecordModel["models/record.js"]:::server
            NoteModel["models/note.js"]:::server
            CommentModel["models/comment.js"]:::server
            FriendshipModel["models/friendship.js"]:::server
            AcquaintanceModel["models/acquaintance.js"]:::server
            Migrations["migrations/*.js"]:::server
            Seeders["seeders/*.js"]:::server
        end
        MySQLDB["MySQL Database"]:::db
    end

    %% External Services
    subgraph "External Services"
        LINEAPI["LINE Messaging API"]:::external
    end

    %% Connections
    Browser -->|"HTTP Request"| IndexRoute
    Browser --> PublicAssets
    IndexRoute --> AuthMW
    AdminRoute --> AuthMW
    AuthMW --> App
    App --> ConfigDB
    App --> PassportConfig
    App --> IndexRoute
    App --> AdminRoute
    IndexRoute --> UserCtrl
    IndexRoute --> PatientCtrl
    IndexRoute --> RecordCtrl
    IndexRoute --> NoteCtrl
    IndexRoute --> CommentCtrl
    IndexRoute --> FriendCtrl
    IndexRoute --> ContestCtrl
    IndexRoute --> AdminCtrl
    AdminRoute --> AdminCtrl
    UserCtrl --> AuthHelpers
    RecordCtrl --> FileHelpers
    UserCtrl --> HBSHelpers
    IndexRoute --> Views
    Views --> Browser
    UserCtrl --> ModelsIndex
    PatientCtrl --> ModelsIndex
    RecordCtrl --> ModelsIndex
    NoteCtrl --> ModelsIndex
    CommentCtrl --> ModelsIndex
    FriendCtrl --> ModelsIndex
    ContestCtrl --> ModelsIndex
    AdminCtrl --> ModelsIndex
    ModelsIndex --> MySQLDB
    LINEAPI -.-> UserCtrl

    %% Click Events
    click App "https://github.com/wei-hsiang86/care-together/blob/main/app.js"
    click ConfigDB "https://github.com/wei-hsiang86/care-together/blob/main/config/config.js"
    click PassportConfig "https://github.com/wei-hsiang86/care-together/blob/main/config/passport.js"
    click IndexRoute "https://github.com/wei-hsiang86/care-together/blob/main/routes/index.js"
    click AdminRoute "https://github.com/wei-hsiang86/care-together/blob/main/routes/modules/admin.js"
    click AuthMW "https://github.com/wei-hsiang86/care-together/blob/main/middleware/auth.js"
    click MulterMW "https://github.com/wei-hsiang86/care-together/blob/main/middleware/multer.js"
    click ErrorMW "https://github.com/wei-hsiang86/care-together/blob/main/middleware/error-handler.js"
    click UserCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/user-controller.js"
    click PatientCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/patient-controller.js"
    click RecordCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/record-controller.js"
    click NoteCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/note-controller.js"
    click CommentCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/comment-controller.js"
    click FriendCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/friend-controller.js"
    click ContestCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/contest-controller.js"
    click AdminCtrl "https://github.com/wei-hsiang86/care-together/blob/main/controllers/admin-controller.js"
    click AuthHelpers "https://github.com/wei-hsiang86/care-together/blob/main/helpers/auth-helpers.js"
    click FileHelpers "https://github.com/wei-hsiang86/care-together/blob/main/helpers/file-helpers.js"
    click HBSHelpers "https://github.com/wei-hsiang86/care-together/blob/main/helpers/handlebars-helpers.js"
    click PaginationHelper "https://github.com/wei-hsiang86/care-together/blob/main/helpers/pagination-helper.js"
    click ModelsIndex "https://github.com/wei-hsiang86/care-together/blob/main/models/index.js"
    click UserModel "https://github.com/wei-hsiang86/care-together/blob/main/models/user.js"
    click PatientModel "https://github.com/wei-hsiang86/care-together/blob/main/models/patient.js"
    click RecordModel "https://github.com/wei-hsiang86/care-together/blob/main/models/record.js"
    click NoteModel "https://github.com/wei-hsiang86/care-together/blob/main/models/note.js"
    click CommentModel "https://github.com/wei-hsiang86/care-together/blob/main/models/comment.js"
    click FriendshipModel "https://github.com/wei-hsiang86/care-together/blob/main/models/friendship.js"
    click AcquaintanceModel "https://github.com/wei-hsiang86/care-together/blob/main/models/acquaintance.js"
    click Migrations "https://github.com/wei-hsiang86/care-together/blob/main/migrations/*.js"
    click Seeders "https://github.com/wei-hsiang86/care-together/blob/main/seeders/*.js"

    %% Styles
    classDef client fill:#FFA500,stroke:#333,stroke-width:1px
    classDef static fill:#FFD580,stroke:#333,stroke-width:1px
    classDef server fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke-dasharray: 5 5,stroke:#333,stroke-width:1px
```
