# justteshi/menta-social-app architecture

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

- Interactive diagram: https://gitdiagram.com/justteshi/menta-social-app
- Repository: https://github.com/justteshi/menta-social-app

## Overview

##### Project Type & Purpose
- This project is a full-stack social media application that allows users to register, log in, create posts, comment, and like content.
- The backend is built using Apollo Server with GraphQL and uses MongoDB (with Mongoose) as its data store. Authentication (via JsonWebToken and BcryptJS) is a central feature.
- The frontend is a React application (with components like NavBar, PostCard, PostForm, etc.) that interacts with the backend via GraphQL.

##### Main Components
- Client (Frontend) – This is located in the "client" directory.
- Contains React components, routing (pages like Home, Login, Register, Profile, Cocktail/Posts pages), context for authentication, and utility files such as hooks and GraphQL utility functions.
- GraphQL API Server (Backend) – The root-level index.js is the entry point.
- Uses Apollo Server to manage GraphQL queries/mutations.
- The "graphql" directory contains type definitions and resolvers (separated for posts, comments, and users).
- Models & Utilities – In the "models" directory are Mongoose schemas (User.js, Post.js) that represent how data is stored in MongoDB.
- The "util" directory contains authentication checks and validation logic.
- External Services – MongoDB Atlas is used as the external database service.
- Infrastructure Components: Although not explicitly shown, environment configuration and server setup should also be highlighted (ports, dependency injection, etc.).

##### Relationships and Interactions
- An authentication flow, showing that login/registration in the client triggers backend processes using JsonWebToken and Bcrypt for security.
- Data flows within the GraphQL server—for example, how resolvers (posts.js, users.js, comments.js) interact with the models and utilities (authentication and validators).

##### Architectural Patterns & Design Principles
- Separation of concerns: the project clearly separates the frontend (React) from the backend (GraphQL API).
- MVC/MVP patterns on the backend: GraphQL resolvers serve as controllers that manage interactions between the HTTP layer and Mongoose models.
- Use of a context provider in the client (ApolloProvider, context/auth) to manage state, possibly implying a clear mapping between UI components and API data.
- Security best practices using token-based authentication and proper validation.

- Clear labels for each component (e.g., “React Client”, “Apollo Server / GraphQL Layer”, “Mongoose Models (MongoDB)”).
○ Presentation layer (frontend UI)
○ API layer (GraphQL server and resolvers)
○ Data persistence layer (MongoDB)
○ Shared utility modules (authentication, validation)
- Optionally, include ancillary processes such as the build/deploy process (e.g., package.json usage in both client and server directories) if needed for completeness.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React Client)"
        FE1("React Client"):::frontend
        FE2("UI Components (NavBar,PostCard,PostForm,etc.)"):::frontend
        FE3("Pages (Home,Login,Register,Profile,Posts)"):::frontend
        FE4("Auth Context"):::frontend
    end

    %% Backend Layer
    subgraph "GraphQL API Server (Backend)"
        BE1("Server Entry (index.js)"):::backend
        BE2("Resolvers (Posts,Comments,Users)"):::backend
        BE3("Type Definitions"):::backend
    end

    %% Utility Modules
    subgraph "Utility Modules"
        UTIL1("Auth Check (check-auth.js)"):::util
        UTIL2("Validators (validators.js)"):::util
    end

    %% Data Persistence Layer
    subgraph "Mongoose Models (MongoDB)"
        DB1("User Model (User.js)"):::database
        DB2("Post Model (Post.js)"):::database
        DB("MongoDB Atlas"):::database
    end

    %% Connections between Frontend and Backend
    FE1 -->|"GraphQLRequest"| BE1
    FE2 -->|"UIInteraction"| FE1
    FE3 -->|"UserNavigation"| FE1
    FE4 -->|"JWTToken"| BE1

    %% Connections within Backend
    BE1 -->|"InitializeResolvers"| BE2
    BE1 -->|"LoadSchema"| BE3

    %% Connections from Backend to Utility Modules
    BE2 -->|"Uses"| UTIL1
    BE2 -->|"Uses"| UTIL2

    %% Connections from Backend to Database Models
    BE2 -->|"CRUDOperations"| DB1
    BE2 -->|"CRUDOperations"| DB2

    %% Connections from Models to External Database
    DB1 -->|"StoresData"| DB
    DB2 -->|"StoresData"| DB

    %% Click Events
    click FE1 "https://github.com/justteshi/menta-social-app/tree/master/client/"
    click FE2 "https://github.com/justteshi/menta-social-app/tree/master/client/src/components/"
    click FE3 "https://github.com/justteshi/menta-social-app/tree/master/client/src/pages/"
    click FE4 "https://github.com/justteshi/menta-social-app/blob/master/client/src/context/auth.js"
    click BE1 "https://github.com/justteshi/menta-social-app/blob/master/index.js"
    click BE2 "https://github.com/justteshi/menta-social-app/tree/master/graphql/resolvers/"
    click BE3 "https://github.com/justteshi/menta-social-app/blob/master/graphql/typeDefs.js"
    click UTIL1 "https://github.com/justteshi/menta-social-app/blob/master/util/check-auth.js"
    click UTIL2 "https://github.com/justteshi/menta-social-app/blob/master/util/validators.js"
    click DB1 "https://github.com/justteshi/menta-social-app/blob/master/models/User.js"
    click DB2 "https://github.com/justteshi/menta-social-app/blob/master/models/Post.js"

    %% Styling
    classDef frontend fill:#DFF0D8,stroke:#3C763D,stroke-width:2px;
    classDef backend fill:#D9EDF7,stroke:#31708F,stroke-width:2px;
    classDef util fill:#FCF8E3,stroke:#8A6D3B,stroke-width:2px;
    classDef database fill:#F2DEDE,stroke:#A94442,stroke-width:2px;
```
