# attr-cs/neuron architecture

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

- Interactive diagram: https://gitdiagram.com/attr-cs/neuron
- Repository: https://github.com/attr-cs/neuron

## Overview

##### Project type and purpose
- This is a full-stack social media application (“Neuron Social Media App”) with a React-based frontend, a Node.js/Express backend, real-time features via Socket.IO, and MongoDB as the primary datastore. It supports posts, comments, direct messages, audio/video calls, notifications, user management, admin functionality, and AI-powered features.

##### File structure
- Top-level separation:
- frontend/ – a Vite-powered React application with Tailwind CSS, various UI components, context providers, hooks, services, and state atoms.
- backend/ – an Express server structured around MVC: config (db.js), models (Mongoose schemas), controllers (business logic), routes (HTTP endpoints), middlewares (auth, admin), services (email), and a Socket.IO module for real-time events.
- Key patterns:
- Frontend component hierarchy with React Router for pages and protected/public routes
- Backend MVC and layer separation (controllers vs services vs models)
- WebSocket layer in backend/socket and frontend/src/contexts + services/socketService.js
- Zod for validation under backend/zod

##### README for additional insights
- Confirms tech stack: React, Next.js labels (though code is Vite), Tailwind, TypeScript badges (but code uses .jsx/.js), AI features, email notifications, analytics dashboard, global reach.

##### Elements
- Labels: “React Client,” “Express API,” “Socket.IO,” “MongoDB,” “SMTP/Email Service”
- Green for backend services

##### Detailed breakdown suggestions
- UI Components
- Contexts & State Store
- Service layer (API calls, socket wrappers)
- Routes & Controllers
- Middlewares (auth, validation)
- Services (email, business logic)
- WebSocket handlers
- Data layer (models)
- Database connected to both REST and WebSocket sub-layers

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (React Client)"
        ENTRY("Frontend Entry Point"):::frontend
        APPSHELL("Frontend App Shell & Routing"):::frontend
        UI("UI Components"):::frontend
        PAGES("Pages & Routes"):::frontend
        STYLES("Global Styles & Config"):::frontend
        STATE("State Management (Atoms & Selectors)"):::frontend
        CONTEXT("Contexts & Socket.IO Client"):::frontend
        SERVICES("Services: API, Socket, Call"):::frontend
        ADMINUI("Admin UI Components"):::frontend
        NOTIFUI("Notification UI & Pages"):::frontend
        CHATUI("Chat & Direct Messaging UI"):::frontend
        CALLUI("Audio/Video Call UI"):::frontend
        AUTHPAGES("User Authentication Pages & Flows"):::frontend
        PROFILE("Profile & Settings Pages"):::frontend
        ADMINDASH("Admin Dashboard"):::frontend
        ERROR("Error Handling & Boundary"):::frontend
    end

    subgraph "Backend (Express API)"
        SERVER("Express API Server"):::backend
        subgraph "Config"
            DBCONF("Database Configuration"):::backend
        end
        subgraph "Models"
            USER("User Model"):::backend
            POST("Post Model"):::backend
            COMMENT("Comment (embedded in Post)"):::backend
            MESSAGE("Message Model"):::backend
            NOTIMOD("Notification Model"):::backend
            REPORT("Report Model"):::backend
            CONTACT("Contact Model"):::backend
        end
        subgraph "Controllers"
            USERCTRL("User Controller"):::backend
        end
        subgraph "Routes"
            USERRT("User Routes"):::backend
            POSTRT("Post Routes"):::backend
            NOTIRT("Notification Routes"):::backend
            CHATRT("Chat Routes"):::backend
            REPORTRT("Report Routes"):::backend
            ADMINRT("Admin Routes"):::backend
            INDX("Index & Test Routes"):::backend
        end
        subgraph "Middlewares"
            AUTH("Verify JWT Token"):::backend
            ADMINM("Admin Guard"):::backend
        end
        subgraph "Services"
            EMAIL("Email Service (SMTP/API)"):::external
        end
        subgraph "WebSocket"
            SOCKET("Socket.IO Server"):::backend
        end
        ZOD("Input Validation (Zod)"):::backend
    end

    DB("MongoDB"):::database

    ENTRY --> APPSHELL
    APPSHELL --> UI
    APPSHELL --> PAGES
    UI --> SERVICES
    PAGES --> SERVICES
    STYLES --> ENTRY
    STATE --> UI
    STATE --> SERVICES
    CONTEXT --> SERVICES
    CONTEXT --> SOCKET
    SERVICES --> SERVER
    AUTHPAGES --> SERVICES
    PROFILE --> SERVICES
    ADMINDASH --> SERVICES
    ADMINUI --> SERVICES
    NOTIFUI --> SERVICES
    CHATUI --> SERVICES
    CALLUI --> SERVICES
    ERROR --> UI

    SERVICES -->|HTTP REST| SERVER
    CONTEXT -->|WebSocket| SOCKET

    SERVER --> DBCONF
    DBCONF --> DB

    SERVER --> USERCTRL
    USERCTRL --> USERRT
    USERRT --> SERVER
    POSTRT --> SERVER
    NOTIRT --> SERVER
    CHATRT --> SERVER
    REPORTRT --> SERVER
    ADMINRT --> SERVER
    INDX --> SERVER

    SERVER --> USER
    SERVER --> POST
    SERVER --> MESSAGE
    SERVER --> NOTIMOD
    SERVER --> REPORT
    SERVER --> CONTACT

    SERVER --> AUTH
    SERVER --> ADMINM

    SERVER --> EMAIL
    SERVER --> SOCKET
    SOCKET --> DB
    SERVER --> ZOD

    classDef frontend fill:#bbdefb,stroke:#1e88e5,stroke-width:1px
    classDef backend fill:#c8e6c9,stroke:#43a047,stroke-width:1px
    classDef database fill:#b2ebf2,stroke:#00acc1,stroke-width:1px
    classDef external fill:#e0e0e0,stroke:#757575,stroke-width:1px

    click ENTRY "https://github.com/attr-cs/neuron/blob/main/frontend/src/main.jsx"
    click APPSHELL "https://github.com/attr-cs/neuron/blob/main/frontend/src/App.jsx"
    click UI "https://github.com/attr-cs/neuron/tree/main/frontend/src/components"
    click PAGES "https://github.com/attr-cs/neuron/tree/main/frontend/src/pages"
    click STYLES "https://github.com/attr-cs/neuron/blob/main/frontend/src/index.css"
    click STYLES "https://github.com/attr-cs/neuron/blob/main/frontend/tailwind.config.js"
    click STYLES "https://github.com/attr-cs/neuron/blob/main/frontend/vite.config.js"
    click STATE "https://github.com/attr-cs/neuron/blob/main/frontend/src/store/atoms/index.js"
    click STATE "https://github.com/attr-cs/neuron/blob/main/frontend/src/store/selectors/index.js"
    click CONTEXT "https://github.com/attr-cs/neuron/blob/main/frontend/src/contexts/SocketContext.jsx"
    click SERVICES "https://github.com/attr-cs/neuron/blob/main/frontend/src/services/socketService.js"
    click SERVICES "https://github.com/attr-cs/neuron/blob/main/frontend/src/services/callService.js"
    click ADMINUI "https://github.com/attr-cs/neuron/tree/main/frontend/src/components/admin"
    click NOTIFUI "https://github.com/attr-cs/neuron/blob/main/frontend/src/components/NotificationDropdown.jsx"
    click NOTIFUI "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/NotificationsPage.jsx"
    click CHATUI "https://github.com/attr-cs/neuron/blob/main/frontend/src/components/Chat.jsx"
    click CHATUI "https://github.com/attr-cs/neuron/blob/main/frontend/src/components/DirectMessage.jsx"
    click CALLUI "https://github.com/attr-cs/neuron/blob/main/frontend/src/components/CallInterface.jsx"
    click AUTHPAGES "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/Signin.jsx"
    click AUTHPAGES "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/Signup.jsx"
    click AUTHPAGES "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/RequestReset.jsx"
    click AUTHPAGES "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/ResetPassword.jsx"
    click AUTHPAGES "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/CreatePassword.jsx"
    click PROFILE "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/ProfilePage.jsx"
    click PROFILE "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/Settings.jsx"
    click ADMINDASH "https://github.com/attr-cs/neuron/blob/main/frontend/src/pages/AdminDashboard.jsx"
    click ERROR "https://github.com/attr-cs/neuron/blob/main/frontend/src/components/ErrorBoundary.jsx"
    click SERVER "https://github.com/attr-cs/neuron/blob/main/backend/server.js"
    click DBCONF "https://github.com/attr-cs/neuron/blob/main/backend/config/db.js"
    click USER "https://github.com/attr-cs/neuron/blob/main/backend/models/userModel.js"
    click POST "https://github.com/attr-cs/neuron/blob/main/backend/models/postModel.js"
    click MESSAGE "https://github.com/attr-cs/neuron/blob/main/backend/models/messageModel.js"
    click NOTIMOD "https://github.com/attr-cs/neuron/blob/main/backend/models/notificationModel.js"
    click REPORT "https://github.com/attr-cs/neuron/blob/main/backend/models/reportModel.js"
    click CONTACT "https://github.com/attr-cs/neuron/blob/main/backend/models/Contact.js"
    click USERCTRL "https://github.com/attr-cs/neuron/blob/main/backend/controllers/userController.js"
    click USERRT "https://github.com/attr-cs/neuron/blob/main/backend/routes/user.js"
    click POSTRT "https://github.com/attr-cs/neuron/blob/main/backend/routes/post.js"
    click NOTIRT "https://github.com/attr-cs/neuron/blob/main/backend/routes/notification.js"
    click CHATRT "https://github.com/attr-cs/neuron/blob/main/backend/routes/chat.js"
    click REPORTRT "https://github.com/attr-cs/neuron/blob/main/backend/routes/report.js"
    click ADMINRT "https://github.com/attr-cs/neuron/blob/main/backend/routes/admin.js"
    click INDX "https://github.com/attr-cs/neuron/blob/main/backend/routes/index.js"
    click INDX "https://github.com/attr-cs/neuron/blob/main/backend/routes/test.js"
    click AUTH "https://github.com/attr-cs/neuron/blob/main/backend/middlewares/verifyToken.js"
    click ADMINM "https://github.com/attr-cs/neuron/blob/main/backend/middlewares/adminMiddleware.js"
    click EMAIL "https://github.com/attr-cs/neuron/blob/main/backend/services/emailService.js"
    click SOCKET "https://github.com/attr-cs/neuron/blob/main/backend/socket/index.js"
    click ZOD "https://github.com/attr-cs/neuron/blob/main/backend/zod/types.js"
```
