# romeirofernandes/unified architecture

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

- Interactive diagram: https://gitdiagram.com/romeirofernandes/unified
- Repository: https://github.com/romeirofernandes/unified

## Overview

##### Project type and purpose
- This is a full-stack feedback management platform (the “Unified” system) composed of:
- A React-based Admin Dashboard (frontend)
- An Express.js API Server (backend)
- A MongoDB database for persistence
- A React SDK (unified-sdk NPM package) for embedding feedback widgets into third-party apps
- Firebase Authentication for user management

##### File structure
- Top-level directories:
- backend/ – the Express API server with config, controllers, models, routes, and middleware
- frontend/ – the Vite-powered React dashboard app
- unified-sdk/ – the SDK code that ships as an NPM package
- Patterns & Config:
- MVC-style structure in backend (models/, controller/, routes/)
- dotenv / .env for environment variables (DB URI, Firebase keys, backend URL)
- Vite config in both frontends, ESLint setups, deployment config (vercel.json)

##### README for additional insights
- Tech stack: React 18, Express 4, MongoDB 6, Firebase 9
- Hosting: Vercel (frontend/dashboard), Railway (backend)
- Key features: one-line SDK integration, real-time dashboard, AI analytics, theme support

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Consumer
    subgraph "Third-Party Application"
        TP["Third-Party Application"]:::external
    end

    %% SDK Package
    subgraph "Unified SDK (NPM Package)" 
        SDKEntry["src/index.jsx"]:::sdk
        WidgetComp["UnifiedFeedback.jsx"]:::sdk
        FeedbackModal["FeedbackModal.jsx"]:::sdk
        DeleteZone["DeleteZone.jsx"]:::sdk
        FieldComp["Field.jsx"]:::sdk
        ToastComp["Toast.jsx"]:::sdk
        ViteSDKConfig["vite.config.js"]:::config
    end

    %% Backend API
    subgraph "Express API Server" 
        Server["server.js"]:::backend
        DBConfig["config/db.js"]:::backend
        AuthMiddleware["middleware/auth.js"]:::backend
        FeedbackModel["models/Feedback.js"]:::backend
        FeedbackRoutes["routes/feedback.js"]:::backend
        ProjectModel["models/Project.js"]:::backend
        ProjectRoutes["routes/projects.js"]:::backend
        UserModel["models/User.js"]:::backend
        AuthRoutes["routes/auth.js"]:::backend
        PaymentController["controller/paymentController.js"]:::backend
        PaymentRoutes["routes/payments.js"]:::backend
    end

    %% Database & Services
    MongoDB["MongoDB Database"]:::db
    FirebaseAuth["Firebase Authentication"]:::auth
    AIAnalytics["AI Analytics Service"]:::service

    %% Admin Dashboard
    subgraph "Admin Dashboard (React/Vite)" 
        DashboardLayout["DashboardLayout.jsx"]:::frontend
        PageViews["src/pages/"]:::frontend
        AuthContext["AuthContext.jsx"]:::frontend
        ProtectedRoute["ProtectedRoute.jsx"]:::frontend
        FirebaseConfig["src/firebaseConfig.js"]:::config
        ViteDashConfig["vite.config.js"]:::config
    end

    %% Data Flows
    TP -->|"imports UnifiedFeedback widget"| WidgetComp
    WidgetComp -->|"SDK init"| SDKEntry
    SDKEntry -->|"auth via Firebase JWT"| FirebaseAuth
    SDKEntry -->|"POST /api/feedback"| Server
    Server -->|"verify token"| AuthMiddleware
    AuthMiddleware -->|"check with"| FirebaseAuth
    Server -->|"read/write feedback"| MongoDB
    Server -->|"trigger analytics"| AIAnalytics
    DashboardLayout -->|"GET /api/projects/:id & feedback"| Server
    AuthContext -->|"token mgmt"| FirebaseAuth
    ProtectedRoute -->|"guard routes"| AuthContext

    %% Config Links
    DashboardLayout -.->|"uses"| FirebaseConfig
    DashboardLayout -.->|"env var VITE_BACKEND_URL"| ViteDashConfig
    SDKEntry -.->|"env var BACKEND_URL"| ViteSDKConfig

    %% Click Events
    click TP "https://github.com/romeirofernandes/unified/tree/main/unified-sdk/"
    click SDKEntry "https://github.com/romeirofernandes/unified/blob/main/unified-sdk/src/index.jsx"
    click WidgetComp "https://github.com/romeirofernandes/unified/blob/main/unified-sdk/src/components/UnifiedFeedback.jsx"
    click FeedbackModal "https://github.com/romeirofernandes/unified/blob/main/unified-sdk/src/components/FeedbackModal.jsx"
    click DeleteZone "https://github.com/romeirofernandes/unified/blob/main/unified-sdk/src/components/DeleteZone.jsx"
    click FieldComp "https://github.com/romeirofernandes/unified/blob/main/unified-sdk/src/components/Field.jsx"
    click ToastComp "https://github.com/romeirofernandes/unified/blob/main/unified-sdk/src/components/Toast.jsx"
    click ViteSDKConfig "https://github.com/romeirofernandes/unified/blob/main/unified-sdk/vite.config.js"
    click Server "https://github.com/romeirofernandes/unified/blob/main/backend/server.js"
    click DBConfig "https://github.com/romeirofernandes/unified/blob/main/backend/config/db.js"
    click AuthMiddleware "https://github.com/romeirofernandes/unified/blob/main/backend/middleware/auth.js"
    click FeedbackModel "https://github.com/romeirofernandes/unified/blob/main/backend/models/Feedback.js"
    click FeedbackRoutes "https://github.com/romeirofernandes/unified/blob/main/backend/routes/feedback.js"
    click ProjectModel "https://github.com/romeirofernandes/unified/blob/main/backend/models/Project.js"
    click ProjectRoutes "https://github.com/romeirofernandes/unified/blob/main/backend/routes/projects.js"
    click UserModel "https://github.com/romeirofernandes/unified/blob/main/backend/models/User.js"
    click AuthRoutes "https://github.com/romeirofernandes/unified/blob/main/backend/routes/auth.js"
    click PaymentController "https://github.com/romeirofernandes/unified/blob/main/backend/controller/paymentController.js"
    click PaymentRoutes "https://github.com/romeirofernandes/unified/blob/main/backend/routes/payments.js"
    click DashboardLayout "https://github.com/romeirofernandes/unified/blob/main/frontend/src/components/dashboard/DashboardLayout.jsx"
    click PageViews "https://github.com/romeirofernandes/unified/tree/main/frontend/src/pages/"
    click AuthContext "https://github.com/romeirofernandes/unified/blob/main/frontend/src/context/AuthContext.jsx"
    click ProtectedRoute "https://github.com/romeirofernandes/unified/blob/main/frontend/src/components/ProtectedRoute.jsx"
    click FirebaseConfig "https://github.com/romeirofernandes/unified/blob/main/frontend/src/firebaseConfig.js"
    click ViteDashConfig "https://github.com/romeirofernandes/unified/blob/main/frontend/vite.config.js"

    %% Styles
    classDef external fill:#e0f7fa,stroke:#006064;
    classDef sdk fill:#f1f8e9,stroke:#33691e;
    classDef backend fill:#fff3e0,stroke:#e65100;
    classDef frontend fill:#e8eaf6,stroke:#283593;
    classDef db fill:#f3e5f5,stroke:#6a1b9a,stroke-width:2px;
    classDef auth fill:#ffebee,stroke:#b71c1c,stroke-width:2px;
    classDef service fill:#e0f2f1,stroke:#004d40,stroke-dasharray: 5 5;
    classDef config fill:#eceff1,stroke:#455a64,stroke-dasharray: 2 2;
```
