# pranabbhardwaj137/nirvaanai architecture

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

- Interactive diagram: https://gitdiagram.com/pranabbhardwaj137/nirvaanai
- Repository: https://github.com/pranabbhardwaj137/nirvaanai

## Overview

##### Main Components Identification
- Frontend Client: Represented in the "src" folder. This includes the core React application (App.tsx, main.tsx), individual pages (e.g., Home, Login, ProfilePage, etc.), components (e.g., Chatbot, MoodAssessment, Notifications), and context for managing authentication state.
- Backend Server: Found in the "server" directory with server.js managing API endpoints that likely interact with the database and third-party services.
- Database: As specified in the README (MongoDB with Mongoose) that stores user data, recommendations, forum posts, and happiness scores.
- External Services: Such as the Open AI API for chatbot support and any third-party integrations for stress relief (tailored recommendations for songs, movies, books).

##### Relationships and Interactions
- The Frontend communicates with the Backend through RESTful API calls. For example, after the user signs in or interacts with the chatbot, the data flows from components (e.g., Chatbot.tsx, MoodAssessment) to the server.
- The Backend, running on Node.js with Express, handles these requests, performs business logic, and interacts with the MongoDB database for read/write operations.
- Environmental configurations (like your OpenAI API key) are managed at the root with a .env file, influencing server behavior when integrating external services.
- There is a clear separation of authentication layers, as seen by the context/AuthContext.tsx being included in both the root "context" and "src/context" folders, indicating the use of context API for managing auth state on the client side.

##### Architectural Patterns and Design Principles
- MVC / Component-Based Architecture: The frontend uses React.js’s componentization (individual components, pages, and context) to manage UI and state.
- Separation of Concerns: The project extensively separates presentation (React JSX components) from backend logic (Express server) and further separates middleware/logic from static assets (public, imgs).
- API-driven Communication: The client makes HTTP requests to the server which in turn interacts with the database.
- Use of modern tooling: Vite for project bundling, Tailwind CSS for styling, and TypeScript for type safety, as evidenced by the tsconfig files.

##### Technologies, Frameworks, and Libraries
- Frontend: React.js (SPA components, pages), Vite (build tool), Tailwind CSS (styling), TypeScript.
- Backend: Node.js, Express.js, and possibly supporting libraries like nodemon for development.
- Database: MongoDB using Mongoose ODM.
- External: Open AI API integration for chatbot features.
- Tooling: ESLint (eslint.config.js) for linting rules, PostCSS for CSS transformations, and environment configuration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Client"
        FE_Root["Frontend Client"]:::frontend
        FE_App["App.tsx"]:::frontend
        FE_Main["main.tsx"]:::frontend
        FE_Pages["UI Pages"]:::frontend
        FE_Components["Shared Components"]:::frontend
        FE_Auth1["Auth Context (context/AuthContext.tsx)"]:::frontend
        FE_Auth2["Auth Context (src/context/AuthContext.tsx)"]:::frontend
    end

    subgraph "Backend API Server"
        BE_Server["Backend Server (server/server.js)"]:::backend
    end

    subgraph "Data Layer"
        DB["Database (MongoDB)"]:::database
        ES["External Services (Open AI API)"]:::external
    end

    %% Data Flow Connections
    FE_Root -->|"APIcalls"| BE_Server
    BE_Server -->|"Queries"| DB
    BE_Server -->|"Requests"| ES

    %% Click Events for Frontend Components
    click FE_Root "https://github.com/pranabbhardwaj137/nirvaanai/tree/main/src/"
    click FE_App "https://github.com/pranabbhardwaj137/nirvaanai/blob/main/src/App.tsx"
    click FE_Main "https://github.com/pranabbhardwaj137/nirvaanai/blob/main/src/main.tsx"
    click FE_Pages "https://github.com/pranabbhardwaj137/nirvaanai/tree/main/src/pages"
    click FE_Components "https://github.com/pranabbhardwaj137/nirvaanai/tree/main/src/components"
    click FE_Auth1 "https://github.com/pranabbhardwaj137/nirvaanai/blob/main/context/AuthContext.tsx"
    click FE_Auth2 "https://github.com/pranabbhardwaj137/nirvaanai/blob/main/src/context/AuthContext.tsx"

    %% Click Event for Backend Server
    click BE_Server "https://github.com/pranabbhardwaj137/nirvaanai/blob/main/server/server.js"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
```
