# ayjuyaas/summer-project architecture

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

- Interactive diagram: https://gitdiagram.com/ayjuyaas/summer-project
- Repository: https://github.com/ayjuyaas/summer-project

## Overview

##### Project type and purpose
- TheraFind is a full-stack web application with an ML microservice.
- Purpose: recommend therapists based on user-entered mental health concerns, support user-therapist communication, and perform real-time chat.

##### File structure
- Top-level directories:
- frontend – React/Vite/Tailwind UI code
- backendNode – Node.js/Express REST API, WebSocket server, authentication, business logic
- backendFlask – Python/Flask ML microservice for problem identification
- Key patterns:
- MVC-style organization in backendNode (models, controllers, routes)
- Socket folder for real-time messaging (backendNode/src/socket and frontend/src/socket)
- Separate ML service in Flask, loading Keras model and TF-IDF vectorizer
- Config files: .env, package.json, tsconfig, Vite config for frontend; .env.example for backend; Python dependencies implied by README.

##### README for additional insights
- Stack summary: React.js + Tailwind, Node.js + Express, Flask + TensorFlow/Sci-kit, MongoDB
- Three servers:
- Frontend at localhost:5173
- Node backend at localhost:5000
- Flask ML service at localhost:5001
- Database: MongoDB, with URI in .env

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend"
        FE["React SPA (5173)"]:::frontend
        APIClient["HTTP API Client"]:::frontend
        WSClient["WebSocket Client"]:::frontend
    end

    %% Backend Node Layer
    subgraph "Backend - Node.js"
        WS["WebSocket Server (5000)"]:::backend
        subgraph "Express REST API"
            REST["Express API (5000)"]:::backend
            DBConfig["Database Config"]:::backend
            CloudCfg["Cloudinary Config"]:::backend
            AuthMid["JWT Auth Middleware"]:::backend
            subgraph "Routes"
                AuthRoute["Auth Routes"]:::backend
                UserRoute["User Routes"]:::backend
                MatchRoute["Match Routes"]:::backend
                MessageRoute["Message Routes"]:::backend
                TherapistRoute["Therapist Routes"]:::backend
            end
            subgraph "Controllers"
                UserAuthCtrl["UserAuth Controller"]:::backend
                TherAuthCtrl["TherapistAuth Controller"]:::backend
                MatchCtrl["Match Controller"]:::backend
                MsgCtrl["Message Controller"]:::backend
                TherapistCtrl["Therapist Controller"]:::backend
                ReviewCtrl["Review Controller"]:::backend
            end
            Models["Mongoose Models"]:::backend
        end
    end

    %% ML Microservice Layer
    subgraph "ML Microservice - Flask"
        FlaskApp["Flask Service (5001)"]:::backend
        ModelArt["Keras Model"]:::backend
        Vector["TF-IDF Vectorizer"]:::backend
    end

    %% Data Stores and External
    MongoDB["MongoDB"]:::datastore
    Cloud["Cloudinary"]:::external

    %% Data Flows
    FE -->|HTTP/REST| REST
    APIClient -->|requests| REST
    FE -->|WebSocket| WS
    WS <-->|real-time chat| WSClient
    REST -->|CRUD & auth| MongoDB
    REST -->|upload/download| Cloud
    REST -->|POST /predict| FlaskApp
    FlaskApp -->|loads model| ModelArt
    FlaskApp -->|loads vectorizer| Vector

    %% Internal Backend Flows
    REST -->|routes| AuthRoute
    REST -->|routes| UserRoute
    REST -->|routes| MatchRoute
    REST -->|routes| MessageRoute
    REST -->|routes| TherapistRoute
    AuthRoute -->|controllers| UserAuthCtrl
    AuthRoute -->|controllers| TherAuthCtrl
    UserRoute -->|controllers| UserAuthCtrl
    MatchRoute -->|controllers| MatchCtrl
    MessageRoute -->|controllers| MsgCtrl
    TherapistRoute -->|controllers| TherapistCtrl
    ReviewCtrl -.->|uses| Models
    MatchCtrl -->|uses| Models
    MsgCtrl -->|uses| Models
    TherapistCtrl -->|uses| Models

    %% Click Events
    click FE "https://github.com/ayjuyaas/summer-project/tree/main/frontend/src"
    click APIClient "https://github.com/ayjuyaas/summer-project/blob/main/frontend/src/lib/Axios.tsx"
    click WSClient "https://github.com/ayjuyaas/summer-project/blob/main/frontend/src/socket/socket.client.tsx"
    click REST "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/server.js"
    click WS "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/socket/socket.server.js"
    click DBConfig "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/config/database.js"
    click CloudCfg "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/config/cloudinary.js"
    click AuthMid "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/middleware/auth.middle.js"
    click UserAuthCtrl "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/controllers/userAuth.controller.js"
    click TherAuthCtrl "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/controllers/therapistAuth.controller.js"
    click AuthRoute "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/routes/auth.route.js"
    click UserRoute "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/routes/user.route.js"
    click MatchRoute "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/routes/match.route.js"
    click MessageRoute "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/routes/message.route.js"
    click TherapistRoute "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/routes/therapist.route.js"
    click MatchCtrl "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/controllers/match.controller.js"
    click MsgCtrl "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/controllers/message.controller.js"
    click TherapistCtrl "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/controllers/therapist.controller.js"
    click ReviewCtrl "https://github.com/ayjuyaas/summer-project/blob/main/backendNode/src/controllers/review.controller.js"
    click Models "https://github.com/ayjuyaas/summer-project/tree/main/backendNode/src/models"
    click FlaskApp "https://github.com/ayjuyaas/summer-project/blob/main/backendFlask/app.py"
    click ModelArt "https://github.com/ayjuyaas/summer-project/blob/main/backendFlask/mental_health_ann_model.keras"
    click Vector "https://github.com/ayjuyaas/summer-project/blob/main/backendFlask/tfidf_vectorizer.pkl"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px
    classDef backend fill:#bbf,stroke:#333,stroke-width:1px
    classDef datastore fill:#bfb,stroke:#333,stroke-width:1px
    classDef external fill:#ffb,stroke:#333,stroke-width:1px
```
