# bigoldmaple/mindmate-server architecture

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

- Interactive diagram: https://gitdiagram.com/bigoldmaple/mindmate-server
- Repository: https://github.com/bigoldmaple/mindmate-server

## Overview

##### Main Components
- Mobile Client (MindMate):
- UI Layer: Consists of screens under the “app” directory – with separate subfolders for authentication, tabs (community, messages, profile), home, etc.
- Reusable Components: Under “components” for visual elements and theming.
- Services & Utilities: “services” and “utils” folders that handle API calls, authentication, Health Connect integration, and WebSocket communication.
- Native Integration: “android” folder for native code/configuration (build files, manifest, resources) that integrate the Java/Kotlin parts with React Native.
- Asset Management: “assets” directory for images and fonts.

- Backend Server (MindMateServer):
- API Routes: Located under “src/routes” that include endpoints for authentication, community, chat, buddy, profile, notifications, etc.
- Middleware: Error handling and request processing under “src/middleware.”
- Services: Business logic and external service interactions such as push notifications and WebSocket server (located in “src/services”).
- Database Integration: Database schemas under “src/Database” (ChatSchema, CheckInSchema, etc.) and related configuration in “src/config.”
- Utility Functions: Helpers under “src/utils.”

##### Relationships & Interactions
- The Mobile Client communicates with the Backend Server via API calls. This occurs through the services (e.g., auth.ts, chatApi.ts, communityApi.ts) in the client.
- Health Connect integration on Android is accessed via the native code and the corresponding HealthConnectService.
- Real-time features (like messaging) may use WebSockets, as indicated by both client-side (websocketService.ts) and server-side (websocketServer.ts) implementations.
- The backend server interacts with a database (evidenced by the schema files) to store and retrieve data related to chats, check-ins, community posts, and notifications.
- The mobile client utilizes Expo to bridge JavaScript code and native modules, and the build process involves Android Studio (for native modules) and Expo CLI.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The project clearly separates the mobile client code (UI, components, services) from the backend server logic.
- Modular Architecture: Both client and server code are modularized into directories for screens/components/routes, promoting loose coupling.
- Service-Oriented Communication: Client-side “services” abstract API calls while the server organizes routing, middleware, and service logic.
- Real-time Communication: Usage of WebSocket services indicates support for low-latency real-time messaging.
- Native Bridge: The integration of native Android code with React Native indicates the use of bridging techniques to handle platform-specific features.

##### Relevant Technologies, Frameworks, and Libraries
- React Native/Expo for the mobile client
- TypeScript for both client and server code
- Android native development (Kotlin/Java)
- Express (or similar Node web framework) on the backend server
- WebSocket for real-time communication
- Health Connect for health and step tracking
- Likely a NoSQL database (MongoDB, inferred from the schema structure) for persistence
- Various build tools such as Gradle for Android and Expo CLI for the client

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Client Section
    subgraph "Mobile Client (React Native/Expo)"
        MC_UI["UI Screens (app)"]:::client
        MC_Components["Reusable Components (components)"]:::client
        MC_Services["Services & Utilities (services/utils)"]:::client
        MC_Android["Native Android Modules (android)"]:::client
        MC_Assets["Asset Management (assets)"]:::client
    end

    %% Backend Server Section
    subgraph "Backend Server (Node/TypeScript)"
        BE_Routes["API Routes (src/routes)"]:::backend
        BE_Middleware["Middleware (src/middleware)"]:::backend
        BE_Services["Services (src/services)"]:::backend
        BE_Utils["Utility Functions (src/utils)"]:::backend
        BE_WebSocket["WebSocket Server"]:::backend
        subgraph "Database Integration"
            DB_Schemas["Schemas (src/Database)"]:::backend
            DB_Config["Configuration (src/config)"]:::backend
        end
    end

    %% Connections within Mobile Client
    MC_UI -->|"triggers"| MC_Services
    MC_Components -->|"renders in"| MC_UI
    MC_UI -->|"accesses"| MC_Android
    MC_UI -->|"displays"| MC_Assets

    %% Connections between Mobile Client and Backend Server
    MC_Services -->|"HTTP_API"| BE_Routes
    MC_Services -->|"WebSocket"| BE_WebSocket

    %% Backend Server internal flow
    BE_Routes -->|"processes"| BE_Middleware
    BE_Routes -->|"delegates"| BE_Services
    BE_Services -->|"db_ops"| DB_Schemas
    BE_Services -->|"config"| DB_Config
    BE_Services -->|"helpers"| BE_Utils
    BE_WebSocket -->|"messaging_ack"| MC_Services

    %% Click Events - Mobile Client
    click MC_UI "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMate/app"
    click MC_Components "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMate/components"
    click MC_Services "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMate/services"
    click MC_Android "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMate/android"
    click MC_Assets "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMate/assets"

    %% Click Events - Backend Server
    click BE_Routes "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMateServer/src/routes"
    click BE_Middleware "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMateServer/src/middleware"
    click BE_Services "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMateServer/src/services"
    click BE_Utils "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMateServer/src/utils"
    click DB_Schemas "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMateServer/src/Database"
    click DB_Config "https://github.com/bigoldmaple/mindmate-server/tree/main/MindMateServer/src/config"

    %% Styles
    classDef client fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
```
