# g1patidar/mini-loan-application architecture

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

- Interactive diagram: https://gitdiagram.com/g1patidar/mini-loan-application
- Repository: https://github.com/g1patidar/mini-loan-application

## Overview

##### Main Components
- Frontend: This is a React application (note the presence of src, public, tailwind.config.js, etc.). It handles the user interface, user interactions, and makes API calls to the backend.
- Backend: A Node.js/Express server (with structured directories for controllers, helpers, models, and routes). It implements business logic such as JWT authentication, role-based access control, loan processing, and admin functionalities.
- Database: Even though the MongoDB connection details aren’t directly visible in the file tree, the README and usage of Mongoose models in the backend (loan.js, user.js) indicate that MongoDB is the data store.
- External Services & Dependencies: JWT libraries, Redux for state management on the frontend, and likely additional modules for authentication and styling (tailwind CSS).

##### Relationships and Interactions
- Backend ↔ Database: Illustrate that backend controllers/models interact with the MongoDB database (represented by models such as user.js and loan.js).
- Role-Based Flow: Highlight the role-based access (for example, different flows or endpoints accessible by regular users vs. admin users). This can be indicated by alternate paths or separate annotated components.
- JWT Authentication: Represent middleware or helper functions (such as backend/helpers/auth.js) that enforce security and manage JWT tokens for user sessions.

- MVC Pattern in the Backend: Clearly mark the separation where controllers handle incoming requests, models interact with the database, and routes handle endpoint designation.
- Client-Server Architecture: Separate the frontend client from the backend server with a clear API boundary.
- State Management on Frontend: Although not depicted by separate files, note that Redux is used to manage the application state in the frontend.
- Security: Emphasize JWT authentication and RBAC for secure, role-based interactions.

- Backend to the Database block (MongoDB).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "React Frontend"
        FE_Entry["Entry Point (index.js)"]:::frontend
        FE_App["Main App Component (App.js)"]:::frontend
        FE_Tailwind["Tailwind Config (tailwind.config.js)"]:::frontend
        FE_IndexCSS["Index CSS (index.css)"]:::frontend
        FE_Components["Components Folder (e.g., AdminPanel, Dashboard, SignIn, Register)"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Express Backend"
        BE_Entry["Entry Script (index.js)"]:::backend
        BE_Env["Environment Config (.env)"]:::backend

        subgraph "Controllers"
            BE_AuthCtrl["Auth Controller (authController.js)"]:::backend
            BE_LoanCtrl["Loan Controller (loanController.js)"]:::backend
        end

        subgraph "Models"
            BE_UserModel["User Model (user.js)"]:::backend
            BE_LoanModel["Loan Model (loan.js)"]:::backend
        end

        subgraph "Routes"
            BE_AuthRoutes["Auth Routes (authRoutes.js)"]:::backend
            BE_LoanRoutes["Loan Routes (loanRoutes.js)"]:::backend
        end

        subgraph "Helpers"
            BE_AuthHelper["Auth Helper (auth.js)"]:::backend
        end
    end

    %% Database Node
    DB["MongoDB"]:::database

    %% API Flow from Frontend to Backend Routes
    FE_Components -->|"API call"| BE_AuthRoutes
    FE_Components -->|"API call"| BE_LoanRoutes

    %% Backend Routes to Controllers
    BE_AuthRoutes -->|"routes to"| BE_AuthCtrl
    BE_LoanRoutes -->|"routes to"| BE_LoanCtrl

    %% Controllers interacting with Models
    BE_AuthCtrl -->|"queries"| BE_UserModel
    BE_LoanCtrl -->|"queries"| BE_LoanModel

    %% Models interacting with Database
    BE_UserModel -->|"persists data"| DB
    BE_LoanModel -->|"persists data"| DB

    %% JWT Authentication Flow using Helper between Controllers
    BE_AuthHelper -- "JWT/Role Auth" --> BE_AuthCtrl
    BE_AuthHelper -- "JWT/Role Auth" --> BE_LoanCtrl

    %% Frontend direct Business connection (entry point initiates API calls)
    FE_Entry -->|"initializes"| FE_Components
    FE_App -->|"renders UI"| FE_Components

    %% Backend Entry Point connects to Routes
    BE_Entry -->|"starts server"| BE_AuthRoutes
    BE_Entry -->|"starts server"| BE_LoanRoutes

    %% Styles
    classDef frontend fill:#a8d5e2,stroke:#07689f,stroke-width:2px;
    classDef backend fill:#f7c59f,stroke:#c84b31,stroke-width:2px;
    classDef database fill:#ffef82,stroke:#f9a825,stroke-width:2px;

    %% Click Events
    click FE_Entry "https://github.com/g1patidar/mini-loan-application/blob/main/frontend/src/index.js"
    click FE_App "https://github.com/g1patidar/mini-loan-application/blob/main/frontend/src/App.js"
    click FE_Tailwind "https://github.com/g1patidar/mini-loan-application/blob/main/frontend/tailwind.config.js"
    click FE_IndexCSS "https://github.com/g1patidar/mini-loan-application/blob/main/frontend/src/index.css"
    click FE_Components "https://github.com/g1patidar/mini-loan-application/tree/main/frontend/src/components/"

    click BE_Entry "https://github.com/g1patidar/mini-loan-application/blob/main/backend/index.js"
    click BE_Env "https://github.com/g1patidar/mini-loan-application/blob/main/backend/.env"
    click BE_AuthCtrl "https://github.com/g1patidar/mini-loan-application/blob/main/backend/controllers/authController.js"
    click BE_LoanCtrl "https://github.com/g1patidar/mini-loan-application/blob/main/backend/controllers/loanController.js"
    click BE_UserModel "https://github.com/g1patidar/mini-loan-application/blob/main/backend/models/user.js"
    click BE_LoanModel "https://github.com/g1patidar/mini-loan-application/blob/main/backend/models/loan.js"
    click BE_AuthRoutes "https://github.com/g1patidar/mini-loan-application/blob/main/backend/routes/authRoutes.js"
    click BE_LoanRoutes "https://github.com/g1patidar/mini-loan-application/blob/main/backend/routes/loanRoutes.js"
    click BE_AuthHelper "https://github.com/g1patidar/mini-loan-application/blob/main/backend/helpers/auth.js"
```
