# trishitchar/tchargram architecture

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

- Interactive diagram: https://gitdiagram.com/trishitchar/tchargram
- Repository: https://github.com/trishitchar/tchargram

## Overview

##### Main Components

a) Client-Side (Frontend):
- User Interface Layer (Components)
- Feed Components
- Chat Components
- Profile Components
- Common Components
- State Management (Redux)
- Auth Slice
- Posts Slice
- Chat Slice
- Socket Slice
- API Services Layer
- User API
- Post API
- Message API

b) Server-Side (Backend):
- API Layer (Express.js)
- User Routes
- Post Routes
- Message Routes
- Controller Layer
- User Controller
- Post Controller
- Message Controller
- Middleware Layer
- Authentication
- File Upload (Multer)
- Model Layer (MongoDB Schemas)
- User Model
- Post Model
- Message Model
- Conversation Model
- Comment Model

c) External Services:
- MongoDB Database
- Cloudinary (for media storage)
- Socket.io Server (for real-time communication)

##### Connection and Data Flow

- Client → Backend API (REST calls)
- Client ↔ Socket.io Server (bidirectional real-time communication)
- Backend → MongoDB (database operations)
- Backend → Cloudinary (media upload/retrieval)

##### Additional Elements

Specific sections for:
- Authentication flow
- Real-time messaging architecture
- File upload pipeline
- State management flow

##### Architectural Patterns to Highlight

- MVC pattern in the backend
- Redux state management in frontend
- RESTful API architecture
- WebSocket implementation
- Middleware pipeline

##### Database/Storage Layer (Bottom)

- Separation between frontend and backend services
- Real-time communication infrastructure
- Security middleware placement
- Data flow for both synchronous (REST) and asynchronous (WebSocket) communications
- Notes about scalability points
- Deployment considerations (Docker containers)

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that impact the system's behavior and maintainability.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI["User Interface Layer"]
        
        subgraph Components
            FC["Feed Components"]:::frontend
            CC["Chat Components"]:::frontend
            PC["Profile Components"]:::frontend
            CoC["Common Components"]:::frontend
        end
        
        subgraph Redux["State Management"]
            AS["Auth Slice"]:::frontend
            PS["Posts Slice"]:::frontend
            CS["Chat Slice"]:::frontend
            SS["Socket Slice"]:::frontend
        end
        
        subgraph APIServices["API Services Layer"]
            UA["User API"]:::frontend
            PA["Post API"]:::frontend
            MA["Message API"]:::frontend
        end
    end
    
    subgraph Backend
        subgraph APILayer["API Layer"]
            UR["User Routes"]:::backend
            PR["Post Routes"]:::backend
            MR["Message Routes"]:::backend
        end
        
        subgraph Controllers
            UC["User Controller"]:::backend
            PC2["Post Controller"]:::backend
            MC["Message Controller"]:::backend
        end
        
        subgraph Middleware
            Auth["Authentication"]:::security
            FU["File Upload (Multer)"]:::utility
        end
        
        subgraph Models
            UM["User Model"]:::backend
            PM["Post Model"]:::backend
            MM["Message Model"]:::backend
            CM["Conversation Model"]:::backend
            CoM["Comment Model"]:::backend
        end
    end
    
    subgraph ExternalServices
        MongoDB[(MongoDB Database)]:::external
        Cloudinary["Cloudinary Storage"]:::external
        Socket["Socket.io Server"]:::external
    end
    
    Components --> Redux
    Redux --> APIServices
    APIServices --> APILayer
    APILayer --> Controllers
    Controllers --> Models
    Models --> MongoDB
    Controllers --> Cloudinary
    Socket <--> UI
    
    %% Click events for components
    click FC "https://github.com/trishitchar/TcharGram/tree/main/client/src/components/feed/"
    click CC "https://github.com/trishitchar/TcharGram/tree/main/client/src/components/chatting/"
    click PC "https://github.com/trishitchar/TcharGram/tree/main/client/src/components/profile/"
    click CoC "https://github.com/trishitchar/TcharGram/tree/main/client/src/components/common/"
    click AS "https://github.com/trishitchar/TcharGram/blob/main/client/src/redux/slices/authSlice.ts"
    click PS "https://github.com/trishitchar/TcharGram/blob/main/client/src/redux/slices/allPostSlice.ts"
    click CS "https://github.com/trishitchar/TcharGram/blob/main/client/src/redux/slices/chatSlice.ts"
    click SS "https://github.com/trishitchar/TcharGram/blob/main/client/src/redux/slices/socketSlice.ts"
    click UA "https://github.com/trishitchar/TcharGram/blob/main/client/src/api/user.api.ts"
    click PA "https://github.com/trishitchar/TcharGram/blob/main/client/src/api/post.api.ts"
    click MA "https://github.com/trishitchar/TcharGram/blob/main/client/src/api/message.api.ts"
    click UR "https://github.com/trishitchar/TcharGram/blob/main/backend/src/routes/user.route.ts"
    click PR "https://github.com/trishitchar/TcharGram/blob/main/backend/src/routes/post.route.ts"
    click MR "https://github.com/trishitchar/TcharGram/blob/main/backend/src/routes/message.route.ts"
    click UC "https://github.com/trishitchar/TcharGram/blob/main/backend/src/controllers/user.controller.ts"
    click PC2 "https://github.com/trishitchar/TcharGram/blob/main/backend/src/controllers/post.controller.ts"
    click MC "https://github.com/trishitchar/TcharGram/blob/main/backend/src/controllers/message.controller.ts"
    click Auth "https://github.com/trishitchar/TcharGram/blob/main/backend/src/middlewares/isTokenValid.ts"
    click FU "https://github.com/trishitchar/TcharGram/blob/main/backend/src/middlewares/multer.ts"
    click UM "https://github.com/trishitchar/TcharGram/blob/main/backend/src/models/user.model.ts"
    click PM "https://github.com/trishitchar/TcharGram/blob/main/backend/src/models/post.model.ts"
    click MM "https://github.com/trishitchar/TcharGram/blob/main/backend/src/models/message.model.ts"
    click CM "https://github.com/trishitchar/TcharGram/blob/main/backend/src/models/conversation.model.ts"
    click CoM "https://github.com/trishitchar/TcharGram/blob/main/backend/src/models/comment.model.ts"
    click Socket "https://github.com/trishitchar/TcharGram/blob/main/backend/src/socketio/socketio.ts"
    click Cloudinary "https://github.com/trishitchar/TcharGram/blob/main/backend/src/utils/cloudinary.ts"
    click MongoDB "https://github.com/trishitchar/TcharGram/blob/main/backend/src/utils/db.ts"
    
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef utility fill:#95a5a6,stroke:#7f8c8d,color:white
```
