# mian-ali/devconnections architecture

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

- Interactive diagram: https://gitdiagram.com/mian-ali/devconnections
- Repository: https://github.com/mian-ali/devconnections

## Overview

##### Project Type and Purpose
- This is a full-stack MERN (MongoDB, Express, React, Node) social networking application called “Dev Connections.”
- The frontend is a React/Redux single-page app; the backend is an Express/Node REST API; data is stored in MongoDB Atlas; authentication uses JWT; the app also integrates with the GitHub API.

##### File Structure Analysis
- Top-level “client” directory holds the React app (components, actions, reducers, store, utils, public, build artifacts).
- Root contains server code:
– config/ for DB and environment settings
– middleware/ for auth checks
– models/ (Mongoose schemas: User, Profile, Post)
– routes/api/ defines REST endpoints (auth, users, profile, posts)
– server.js boots Express, connects to MongoDB, wires middleware and routes
– Procfile for deployment on Heroku/Cyclic
- package.json scripts include “npm run dev” to launch both client and server concurrently.

##### README Insights
- Describes tech stack (MongoDB, Express, React, Node) and core features (authentication, profiles, posts).
- Instructs how to run in development and production modes.
- Mentions future features (logging, GitHub repo fetching).

##### Main Components
a. Client (Browser) – React + Redux SPA
b. Server/API Layer – Node.js + Express application
c. Database – MongoDB Atlas cluster
d. External Service – GitHub REST API
e. Authentication – JWT token issuance & validation
f. Deployment/Hosting – Heroku/Cyclic (Procfile)

##### Relationships & Data Flow
- User (browser) interacts with the React UI → dispatches Redux actions → makes HTTP requests to Express REST endpoints.
- Express routes → pass through middleware/auth → controller logic → Mongoose models → MongoDB operations → return JSON responses.
- For GitHub integration, server calls GitHub API using the stored githubToken and returns fetched data to client.
- JWT tokens flow: upon login/register the server signs a token → client stores it (localStorage) → attaches it to subsequent requests via headers.

##### Architectural Patterns & Design Principles
- Client-Server separation (SPA vs REST API)
- MVC-like structure on server:
– Models (Mongoose schemas)
– Controllers (route handlers)
– Middleware (auth, error handling)
- Redux for predictable client state management (actions, reducers, store)
- Single monolithic codebase but clearly separated concerns

##### Relevant Technologies & Frameworks
- Frontend: React, Redux, React Router, Axios (via utils/api.js), CSS modules
- Backend: Node.js, Express, Mongoose, jsonwebtoken, bcryptjs
- DevOps/Deployment: Heroku/Cyclic (Procfile), dotenv/config JSON

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (React + Redux SPA)"
        direction TB
        Browser["User Browser"]:::frontend
        Components["UI Components"]:::frontend
        ReduxActions["Redux Actions"]:::store
        ReduxReducers["Redux Reducers"]:::store
        ReduxStore["Redux Store"]:::store
        APIUtility["API Utility (Axios)"]:::util
        PrivateRoute["PrivateRoute"]:::route
        GithubComp["ProfileGithub Component"]:::frontend
    end

    %% Server/API Layer
    subgraph "Server/API (Node.js + Express)"
        direction TB
        ExpressServer["Express Server"]:::backend
        AuthMiddleware["Auth Middleware"]:::backend
        RoutesAuth["Auth Routes"]:::backend
        RoutesUsers["User Routes"]:::backend
        RoutesProfile["Profile Routes"]:::backend
        RoutesPosts["Post Routes"]:::backend
        ModelsUser["User Model"]:::backend
        ModelsProfile["Profile Model"]:::backend
        ModelsPost["Post Model"]:::backend
        DBConfig["DB Config"]:::backend
        EnvSettings["Env Settings"]:::backend
    end

    %% Database and External
    MongoDB["MongoDB Atlas"]:::database
    GitHubAPI["GitHub REST API"]:::external
    Deployment["Procfile / Hosting"]:::devops

    %% Client to Server Flow
    Browser -->|"interacts with"| Components
    Components -->|"dispatches"| ReduxActions
    ReduxActions -->|"update"| ReduxStore
    ReduxStore -->|"state to"| Components
    Components -->|"calls"| APIUtility
    APIUtility -->|"HTTP requests"| ExpressServer

    %% Server Internal Flow
    ExpressServer -->|"uses"| AuthMiddleware
    AuthMiddleware -->|checks token| RoutesAuth
    AuthMiddleware -->|checks token| RoutesUsers
    AuthMiddleware -->|checks token| RoutesProfile
    AuthMiddleware -->|checks token| RoutesPosts

    RoutesAuth -->|"controller logic"| ModelsUser
    RoutesUsers -->|"controller logic"| ModelsProfile
    RoutesProfile -->|"controller logic & GitHub"| ModelsProfile
    RoutesProfile -->|"calls"| GitHubAPI
    RoutesPosts -->|"controller logic"| ModelsPost

    ModelsUser -->|"CRUD ops"| MongoDB
    ModelsProfile -->|"CRUD ops"| MongoDB
    ModelsPost -->|"CRUD ops"| MongoDB

    %% GitHub Data Flow
    GitHubAPI -->|"response data"| RoutesProfile
    RoutesProfile -->|"JSON data"| APIUtility

    %% JWT Token Flow
    RoutesAuth -->|"issues JWT"| APIUtility
    APIUtility -->|"stores token"| Browser
    Browser -->|"sends token"| APIUtility
    APIUtility -->|"authorizes"| AuthMiddleware

    %% Configurations
    DBConfig -->|configures| MongoDB
    EnvSettings -->|provides env vars| ExpressServer
    Deployment -->|hosts| ExpressServer
    Deployment -->|hosts| APIUtility

    %% Click Events
    click Components "https://github.com/mian-ali/devconnections/tree/master/client/src/components"
    click ReduxActions "https://github.com/mian-ali/devconnections/tree/master/client/src/actions"
    click ReduxReducers "https://github.com/mian-ali/devconnections/tree/master/client/src/reducers"
    click ReduxStore "https://github.com/mian-ali/devconnections/blob/master/client/src/store.js"
    click APIUtility "https://github.com/mian-ali/devconnections/blob/master/client/src/utils/api.js"
    click PrivateRoute "https://github.com/mian-ali/devconnections/blob/master/client/src/components/routing/PrivateRoute.js"
    click GithubComp "https://github.com/mian-ali/devconnections/blob/master/client/src/components/profile/ProfileGithub.js"
    click ExpressServer "https://github.com/mian-ali/devconnections/blob/master/server.js"
    click DBConfig "https://github.com/mian-ali/devconnections/blob/master/config/db.js"
    click EnvSettings "https://github.com/mian-ali/devconnections/blob/master/config/production.json"
    click AuthMiddleware "https://github.com/mian-ali/devconnections/blob/master/middleware/auth.js"
    click RoutesAuth "https://github.com/mian-ali/devconnections/blob/master/routes/api/auth.js"
    click RoutesUsers "https://github.com/mian-ali/devconnections/blob/master/routes/api/users.js"
    click RoutesProfile "https://github.com/mian-ali/devconnections/blob/master/routes/api/profile.js"
    click RoutesPosts "https://github.com/mian-ali/devconnections/blob/master/routes/api/posts.js"
    click ModelsUser "https://github.com/mian-ali/devconnections/blob/master/models/User.js"
    click ModelsProfile "https://github.com/mian-ali/devconnections/blob/master/models/Profile.js"
    click ModelsPost "https://github.com/mian-ali/devconnections/blob/master/models/Post.js"
    click Deployment "https://github.com/mian-ali/devconnections/tree/master/Procfile"

    %% Styles
    classDef frontend fill:#D0E6FA,stroke:#045FB4,color:#000
    classDef store fill:#D6EAF8,stroke:#2874A6,color:#000
    classDef util fill:#EBDEF0,stroke:#8E44AD,color:#000
    classDef route fill:#FDEBD0,stroke:#B9770E,color:#000
    classDef backend fill:#D5F5E3,stroke:#196F3D,color:#000
    classDef database fill:#F9E79F,stroke:#B7950B,color:#000
    classDef external fill:#FADBD8,stroke:#C0392B,color:#000
    classDef devops fill:#E8DAEF,stroke:#6C3483,color:#000
```
