# zak1sn0good/mini-social-media-backend architecture

> Architecture diagram of the GitHub repository zak1sn0good/mini-social-media-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zak1sn0good/mini-social-media-backend
- Repository: https://github.com/zak1sn0good/mini-social-media-backend

## Overview

##### Main System Components

a) API Layer:
- A GraphQL API Gateway component at the top level
- Apollo Server integration (evident from the server.js file)

b) Business Logic Layer:
- User Resolvers
- Post Resolvers
- Comment Resolvers
- Like Resolvers
- To the GraphQL Schema (typeDefs.js)

c) Data Model Layer:
- MongoDB as the database layer
- Two main models:
- User Model
- Post Model

d) Utility Services:
- Authentication Service (checkAuth.js)
- Validation Service (validators.js)

##### Component Relationships and Flow

- Client requests → GraphQL API Gateway
- API Gateway → GraphQL Schema (typeDefs)
- Schema → Respective Resolvers
- Resolvers → Models
- Models → MongoDB
- Cross-cutting concerns (Auth & Validation) should be shown as vertical layers

**[Client Applications] (top)**
- ↓
**[GraphQL API Gateway]**
- ↓
**[Schema Definitions] ←→ [Authentication]**
- ↓                     ↕
**[Resolver Layer]    ←→   [Validation]**
- ↓
**[Data Models]**
- ↓
**[MongoDB Database] (bottom)**

##### Additional Elements

- Security boundaries
- Component types

Remember to emphasize the modular nature of the GraphQL resolvers and how they map to the type definitions, as this is a key architectural feature of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Applications]
    end

    subgraph "API Gateway"
        API["GraphQL API Gateway/Apollo Server"]:::apiGateway
    end

    subgraph "Schema Layer"
        SCHEMA["GraphQL Schema"]:::schema
    end

    subgraph "Resolver Layer"
        RES_IDX["Resolver Index"]:::resolver
        USER_RES["User Resolvers"]:::resolver
        POST_RES["Post Resolvers"]:::resolver
        COMMENT_RES["Comment Resolvers"]:::resolver
        LIKE_RES["Like Resolvers"]:::resolver
    end

    subgraph "Data Models"
        USER_MODEL["User Model"]:::model
        POST_MODEL["Post Model"]:::model
    end

    subgraph "Utility Services"
        AUTH["Authentication Service"]:::utility
        VAL["Validation Service"]:::utility
    end

    subgraph "Database"
        DB[(MongoDB)]:::database
    end

    %% Connections
    CL --> API
    API --> SCHEMA
    SCHEMA --> RES_IDX
    RES_IDX --> |Delegates to| USER_RES
    RES_IDX --> |Delegates to| POST_RES
    RES_IDX --> |Delegates to| COMMENT_RES
    RES_IDX --> |Delegates to| LIKE_RES

    USER_RES --> USER_MODEL
    POST_RES & COMMENT_RES & LIKE_RES --> POST_MODEL
    
    USER_MODEL & POST_MODEL --> DB

    %% Cross-cutting concerns
    AUTH -.-> API
    AUTH -.-> RES_IDX
    VAL -.-> USER_RES
    VAL -.-> POST_RES

    %% Click events
    click API "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/server.js"
    click SCHEMA "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/graphql/typeDefs.js"
    click RES_IDX "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/graphql/resolvers/index.js"
    click USER_RES "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/graphql/resolvers/users.js"
    click POST_RES "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/graphql/resolvers/posts.js"
    click COMMENT_RES "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/graphql/resolvers/comments.js"
    click LIKE_RES "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/graphql/resolvers/likes.js"
    click USER_MODEL "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/models/User.js"
    click POST_MODEL "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/models/Post.js"
    click AUTH "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/utils/checkAuth.js"
    click VAL "https://github.com/zak1sn0good/mini-social-media-backend/blob/main/utils/validators.js"

    %% Styles
    classDef apiGateway fill:#2196F3,stroke:#1565C0,color:white
    classDef schema fill:#42A5F5,stroke:#1976D2,color:white
    classDef resolver fill:#4CAF50,stroke:#388E3C,color:white
    classDef model fill:#FFC107,stroke:#FFA000,color:black
    classDef utility fill:#F44336,stroke:#D32F2F,color:white
    classDef database fill:#757575,stroke:#616161,color:white

    %% Legend
    subgraph Legend
        L1["API Gateway"]:::apiGateway
        L2["Schema"]:::schema
        L3["Resolver"]:::resolver
        L4["Model"]:::model
        L5["Utility"]:::utility
        L6["Database"]:::database
    end
```
