# disha-satpute/scholarhub architecture

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

- Interactive diagram: https://gitdiagram.com/disha-satpute/scholarhub
- Repository: https://github.com/disha-satpute/scholarhub

## Overview

##### Project type and purpose
- This is a full-stack web application (“ScholarHub”) for student scholarship discovery and management.
- The frontend is built in React.js, the backend in Node.js/Express, and it uses PostgreSQL for storage. Users can browse, filter, save, and apply for scholarships; admins can manage scholarships and users.

##### File structure
- Top-level split:
- backend/ – Node.js REST API
- frontend/ – React single-page application
- ScholarHub.sql – database schema
- backend/ substructure:
- config/ – database connection and environment settings
- middleware/ – JWT authentication handler
- models/ – ORM/entity definitions (Admin, User)
- routes/ – REST endpoints (auth, admin, scholarship, email)
- server.js – Express app bootstrap
- frontend/ substructure:
- public/ – static assets and index.html
- src/ – React source code, including components, pages, styles
- src/pages/ – React Router pages (Login, Register, Dashboard, etc.)
- src/components/ – UI pieces (Header, Footer, Navbar)
- Config files: package.json in both layers, plus .env instructions in README.

##### Key insights from README
- Uses JWT for authentication (stateless tokens).
- PostgreSQL CRM database holds Users, Admins, Scholarships.
- All client-server interaction is via HTTP/JSON REST endpoints.
- No microservices: single API server.
- Email routes indicate an external SMTP service integration.

a. Main components
1. User’s Browser (React SPA)
2. React Frontend (components + pages)
3. Express Backend (REST API)
4. PostgreSQL Database
5. External Email Service (SMTP or third-party)
b. Relationships & data flow
1. Browser ↔ Frontend: user clicks cause HTTP requests to the React app (served from public/index.html).
2. Frontend → Backend: REST API calls (fetch/axios) for auth, data retrieval, CRUD on scholarships.
3. Backend ↔ Database: ORM or query layer in config/db.js performs SQL operations on Users, Admins, Scholarships tables.
4. Backend → Email Service: email route invokes SMTP client to send notifications (password reset, confirmations).
c. Architectural patterns / design principles
- Client-Server: clear separation of UI and API.
- MVC-ish on backend: routes (controllers) → models (data) → config/db (data access).
- JWT-based stateless authentication via authMiddleware.
- React Router for page navigation and state management with React Hooks.
d. Technologies & frameworks
- Frontend: React.js, React Router, Bootstrap/CSS for styling.
- Backend: Node.js, Express.js, JWT, Sequelize or pg module (based on config/db.js).
- Database: PostgreSQL.
- External: SMTP/email library (e.g., nodemailer).

##### Detailed capture of essential elements
- Where authMiddleware intercepts and verifies JWTs.
- Database schema’s main tables (from ScholarHub.sql) as a mini ERD inset.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client Side (Browser)"
        direction TB
        Browser["User's Browser"]:::external
        IndexHtml["index.html"]:::frontend
        IndexJS["index.js"]:::frontend
        App["App.js"]:::frontend
        subgraph "React Pages & Components"
            direction TB
            LandingPage["LandingPage.js"]:::frontend
            AuthPages["Login/Register/Forgot/Reset/AdminAuth Pages"]:::frontend
            DashboardPages["User/Admin Dashboard & Profile"]:::frontend
            ScholarshipPages["Scholarship List/Details/Add/Update"]:::frontend
            UIComponents["Header/Navbar/Footer/LanguageSelector"]:::frontend
            Styles["styles/"]:::frontend
        end
    end

    %% Backend Server
    subgraph "Backend Server"
        direction TB
        Server["server.js"]:::backend
        subgraph "API Routes (Controllers)"
            direction TB
            AuthRoutes["authRoutes.js"]:::api
            AdminRoutes["adminRoutes.js"]:::api
            ScholarshipRoutes["scholarshipRoutes.js"]:::api
            EmailRoutes["email.js"]:::api
        end
        Middleware["authMiddleware.js"]:::middleware
        subgraph "Config & DB Connection"
            direction TB
            DBConfig["db.js"]:::config
            AppConfig["config.json"]:::config
        end
        subgraph "ORM Models"
            direction TB
            UserModel["User.js"]:::models
            AdminModel["Admin.js"]:::models
        end
    end

    %% Infrastructure
    DB["PostgreSQL Database"]:::database
    EmailService["External Email Service"]:::external

    %% Data Flows
    Browser -->|"load SPA"| IndexHtml
    IndexHtml -->|"bootstrap React"| IndexJS
    IndexJS -->|"render App"| App
    App -->|"navigate/render pages"| LandingPage
    LandingPage --> AuthPages
    AuthPages --> DashboardPages
    DashboardPages --> ScholarshipPages
    ScholarshipPages --> UIComponents
    UIComponents --> Styles

    App -->|"HTTP/JSON"| Server
    Server --> AuthRoutes
    Server --> AdminRoutes
    Server --> ScholarshipRoutes
    Server --> EmailRoutes

    AuthRoutes -->|uses| Middleware
    AdminRoutes -->|uses| Middleware
    ScholarshipRoutes -->|uses| Middleware

    AuthRoutes --> UserModel
    AdminRoutes --> AdminModel
    ScholarshipRoutes --> UserModel
    ScholarshipRoutes --> AdminModel

    UserModel --> DB
    AdminModel --> DB
    DBConfig --> DB

    EmailRoutes -->|"SMTP"| EmailService

    %% Click Events
    click App "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/App.js"
    click IndexJS "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/index.js"
    click IndexHtml "https://github.com/disha-satpute/scholarhub/blob/main/frontend/public/index.html"
    click LandingPage "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/LandingPage.js"
    click AuthPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/Login.js"
    click AuthPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/Register.js"
    click AuthPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/ForgotPassword.js"
    click AuthPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/ResetPassword.js"
    click AuthPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/AdminLogin.js"
    click AuthPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/AdminRegister.js"
    click DashboardPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/UserDashboard.js"
    click DashboardPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/UserProfile.js"
    click DashboardPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/AdminDashboard.js"
    click DashboardPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/AdminProfile.js"
    click ScholarshipPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/Scholarships.js"
    click ScholarshipPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/ScholarshipDetails.js"
    click ScholarshipPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/AddScholarship.js"
    click ScholarshipPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/UpdateScholarship.js"
    click ScholarshipPages "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/pages/Details.js"
    click UIComponents "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/components/Header.js"
    click UIComponents "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/components/Navbar.js"
    click UIComponents "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/components/Footer.js"
    click UIComponents "https://github.com/disha-satpute/scholarhub/blob/main/frontend/src/components/LanguageSelector.js"
    click Styles "https://github.com/disha-satpute/scholarhub/tree/main/frontend/src/styles/"
    click Server "https://github.com/disha-satpute/scholarhub/blob/main/backend/server.js"
    click DBConfig "https://github.com/disha-satpute/scholarhub/blob/main/backend/config/db.js"
    click AppConfig "https://github.com/disha-satpute/scholarhub/blob/main/backend/config/config.json"
    click Middleware "https://github.com/disha-satpute/scholarhub/blob/main/backend/middleware/authMiddleware.js"
    click UserModel "https://github.com/disha-satpute/scholarhub/blob/main/backend/models/User.js"
    click AdminModel "https://github.com/disha-satpute/scholarhub/blob/main/backend/models/Admin.js"
    click AuthRoutes "https://github.com/disha-satpute/scholarhub/blob/main/backend/routes/authRoutes.js"
    click AdminRoutes "https://github.com/disha-satpute/scholarhub/blob/main/backend/routes/adminRoutes.js"
    click ScholarshipRoutes "https://github.com/disha-satpute/scholarhub/blob/main/backend/routes/scholarshipRoutes.js"
    click EmailRoutes "https://github.com/disha-satpute/scholarhub/blob/main/backend/routes/email.js"
    click DB "https://github.com/disha-satpute/scholarhub/blob/main/ScholarHub.sql"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#2B6CB0,color:#2B6CB0
    classDef backend fill:#DFF6DF,stroke:#276749,color:#276749
    classDef api fill:#E6FFFA,stroke:#2C7A7B,color:#2C7A7B
    classDef middleware fill:#F0FFF4,stroke:#38A169,color:#38A169
    classDef config fill:#FFF5F7,stroke:#B83280,color:#B83280
    classDef models fill:#FEFCBF,stroke:#D69E2E,color:#D69E2E
    classDef database fill:#FFFAE6,stroke:#B7791F,color:#B7791F
    classDef external fill:#EDF2F7,stroke:#4A5568,color:#4A5568
```
