# dminghao/neurosoft architecture

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

- Interactive diagram: https://gitdiagram.com/dminghao/neurosoft
- Repository: https://github.com/dminghao/neurosoft

## Overview

##### Project Type and Purpose
- NeuroSoft is a full‐stack medical surveying platform built with the MERN stack (MongoDB, Express, React, Node.js). It enables surgeons to create, manage, and distribute treatment admission surveys, while also incorporating a conventional SQL database for generating medical reports.

##### Analyzing the File Structure
- The “Main” directory holds the full application.
– The “backend” subdirectory contains server-side code: environment configuration (.env), middleware (auth.js), data models (for survey and user objects), and API routes.
– The “src” subdirectory contains React components and context management for the frontend (navigation, survey display/creation, dashboards for doctors and patients, authentication).
- The structure reflects an MVC or layered architecture where the front end, back end, and databases are kept separate.

##### Key Components
- Frontend:
- React Application (located in Main/src)
- Core components such as Navbar, Home, Surveys, Dashboards for various roles (Doctor, Patient)
- Client side routing and context providers (UserContext, MsgContext)
- Backend:
- Express Server (Main/backend/server.js) responsible for API handling, connecting to both MongoDB (for storing surveys, users, etc.) and the SQL Database (for medical report generation)
- Middleware (e.g., auth.js) for security/authentication
- API endpoints for surveys, templates, and user management
- Databases:
- MongoDB for the core data of surveys, users, etc.
- A conventional SQL database (as indicated in the README for report generation)
- Deployment & Infrastructure:
- AWS EC2: Deployment of the application via PM2 for the backend (e.g., using nodemon/node server)
- Environment configuration (.env file) and build/deployment steps described in the README.

##### Relationships and Interactions
- Data Flow: The React frontend sends HTTP requests (via API calls) to the Express backend.
- The backend processes these requests, applying middleware (authentication) before reaching the appropriate API routes.
- Backend interacts with both MongoDB (for surveys, users) and a SQL Database (for generating and storing reports).
- Deployment pipelines and configuration management (such as changes in .env and using PM2) should be depicted to show the lifecycle from development to production.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clearly separate client-side rendering (React) and server-side logic (Express).
- MVC-like Structure: Use models (in /models), views (served via React), and controllers (API routes) on the backend.
- Security: Emphasize the role of authentication middleware within the API call flow.

2. The server-side (Express/Node.js) that includes middleware and routing.
3. The databases (MongoDB and SQL) that the server interacts with.
4. Deployment context: an AWS EC2 block with PM2 managing the production server.

graph TD
FE[React Application]
end

BE[Express/Node.js Server]
Middleware[Authentication Middleware]
BE --> Middleware
end

MDB[MongoDB]
SQL[SQL Database]
end

FE -->|HTTP API Calls| BE
BE -->|CRUD Operations| MDB
BE -->|Report Generation Queries| SQL

AWS[AWS EC2 (PM2 Managed)]
end

BE --> AWS

- Use this as a base template, and expand with more detailed components if needed (for example, listing specific API endpoints or frontend subcomponents).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
      FE["Client (React Frontend)"]:::frontend
      Navbar["Navbar Component"]:::frontend
      Auth["Authentication Components"]:::frontend
      DoctorDash["Doctor Dashboard"]:::frontend
      PatientDash["Patient Dashboard"]:::frontend
      Context["Context Providers"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
      BE["API Server (Express/Node.js)"]:::backend
      Middleware["Authentication Middleware"]:::backend
      Env["Environment Config (.env)"]:::backend
      Models["Data Models"]:::backend
      SurveyModel["Survey Models"]:::backend
      UserModel["User Model"]:::backend
      API["API Endpoints"]:::backend
    end

    %% Databases
    subgraph "Databases"
      MDB["MongoDB"]:::database
      SQLDB["SQL Database"]:::database
    end

    %% Deployment
    subgraph "Deployment"
      AWS["AWS EC2 (PM2 Managed)"]:::deployment
    end

    %% Frontend Internal Components
    FE -->|"contains"| Navbar
    FE -->|"contains"| Auth
    FE -->|"contains"| DoctorDash
    FE -->|"contains"| PatientDash
    FE -->|"contains"| Context

    %% Data Flow from Frontend to Backend
    FE -->|"HTTP_API_Calls"| BE

    %% Backend Component Relationships
    BE -->|"uses"| Middleware
    BE --> Env
    BE --> Models
    Models --> SurveyModel
    Models --> UserModel
    BE --> API
    BE -->|"CRUD_Operations"| MDB
    BE -->|"ReportGeneration"| SQLDB
    BE --> AWS

    %% Click Events for Frontend
    click FE "https://github.com/dminghao/neurosoft/tree/master/Main/src"
    click Navbar "https://github.com/dminghao/neurosoft/blob/master/Main/src/components/Navbar.component.js"
    click Auth "https://github.com/dminghao/neurosoft/tree/master/Main/src/components/Auth"
    click DoctorDash "https://github.com/dminghao/neurosoft/tree/master/Main/src/components/Dashboards/Doctor"
    click PatientDash "https://github.com/dminghao/neurosoft/tree/master/Main/src/components/Dashboards/Patient"
    click Context "https://github.com/dminghao/neurosoft/tree/master/Main/src/context"

    %% Click Events for Backend
    click BE "https://github.com/dminghao/neurosoft/blob/master/Main/backend/server.js"
    click Env "https://github.com/dminghao/neurosoft/blob/master/Main/backend/.env"
    click Middleware "https://github.com/dminghao/neurosoft/blob/master/Main/backend/middleware/auth.js"
    click SurveyModel "https://github.com/dminghao/neurosoft/tree/master/Main/backend/models/survey"
    click UserModel "https://github.com/dminghao/neurosoft/blob/master/Main/backend/models/user.model.js"
    click API "https://github.com/dminghao/neurosoft/tree/master/Main/backend/routes/API"

    %% Styles
    classDef frontend fill:#A8DADC,stroke:#1D3557,stroke-width:2px;
    classDef backend fill:#457B9D,stroke:#1D3557,stroke-width:2px;
    classDef database fill:#F4A261,stroke:#E76F51,stroke-width:2px;
    classDef deployment fill:#2A9D8F,stroke:#264653,stroke-width:2px;
```
