# guptaryan73/aahar architecture

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

- Interactive diagram: https://gitdiagram.com/guptaryan73/aahar
- Repository: https://github.com/guptaryan73/aahar

## Overview

##### Main Components
- Frontend:
- EJS templates located under the “views” directory (with subdirectories for admin, agent, donor, auth, home and common partials).
- Static assets – CSS, JavaScript, and images in the “assets” folder.
- Backend:
- The main application defined in “app.js”.
- Routing modules under the “routes” directory, individually serving admin, agent, donor, auth, and home functionalities.
- Middleware in the “middleware” folder to manage request processing.
- Authentication is handled with Passport.js, as indicated in “config/passport.js”.
- Database:
- MongoDB is configured via “config/dbConnection.js” and environment variables in the “.env” file.
- Models:
- Data models defined under the “models” directory (e.g., user.js, donation.js) that contain schema definitions and represent collections in MongoDB.
- Configuration:
- Application configuration and environment settings via the “config” folder.

##### Relationships and Interactions
- Data Flow:
- Users interact via the Frontend (rendered EJS pages) which submits requests to the backend endpoints.
- The Express server (app.js) routes these requests through role-specific routes (admin.js, agent.js, donor.js, auth.js, home.js).
- Controllers (implicitly part of the route handlers) interact with the database through models.
- Passport.js integrated within the backend handles user authentication and session management.
- Separation of Concerns:
- Clear divisions between static content (assets), dynamic content (EJS views), business logic (routes and middleware), and data persistence (MongoDB models).

##### Architectural Patterns and Key Principles
- MVC-like Structure:
- Role-Based Access Control:
- Distinct routes and view folders indicate careful handling of different user roles (donor, agent, admin).
- Modularization:
- The application is broken down into modular directories (routing, middleware, models) to promote separation of concerns and maintainability.
- Real-time Updates (if any WebSockets or other schemes are used, otherwise it is mainly via HTTP requests).

##### Relevant Technologies
- Frontend: EJS, Bootstrap, CSS/JS assets.
- Backend: Node.js, Express.
- Authentication: Passport.js.
- Database: MongoDB.
- Configuration Management: Environment variables in .env.

##### Specific Elements
- Clear labels for each component:
- How users interact with the frontend and how requests are routed to the backend.
- Connection from the backend to the MongoDB.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        FE["Frontend (EJS Templates & Assets)"]:::frontend
        FE1["EJS Templates"]:::frontend
        FE2["Static Assets"]:::frontend
    end

    %% Server Layer
    subgraph "Server Layer"
        EXP["Express Server (app.js)"]:::server
        subgraph "Routes"
            AR["Admin Routes (routes/admin.js)"]:::route
            AGR["Agent Routes (routes/agent.js)"]:::route
            AU["Auth Routes (routes/auth.js)"]:::route
            DR["Donor Routes (routes/donor.js)"]:::route
            HR["Home Routes (routes/home.js)"]:::route
        end
        MW["Middleware (middleware/index.js)"]:::middleware
        PA["Authentication (Passport.js config)"]:::auth
        DBC["Database Config (.env & config/dbConnection.js)"]:::config
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["MongoDB"]:::database
        DM["Data Models (models)"]:::models
        UM["User Model (models/user.js)"]:::models
        DMN["Donation Model (models/donation.js)"]:::models
    end

    %% Data Flow Connections
    FE -->|"renders"| EXP
    FE1 -->|"loaded from"| FE
    FE2 -->|"loaded from"| FE
    EXP -->|"routes to"| AR
    EXP -->|"routes to"| AGR
    EXP -->|"routes to"| AU
    EXP -->|"routes to"| DR
    EXP -->|"routes to"| HR
    EXP -->|"invokes"| MW
    EXP -->|"authenticates with"| PA
    EXP -->|"uses"| DBC

    AR -->|" interacts with "| DB
    AGR -->|" interacts with "| DB
    AU -->|" interacts with "| DB
    DR -->|" interacts with "| DB
    HR -->|" interacts with "| DB

    DB -->|"persists via"| UM
    DB -->|"persists via"| DMN

    %% Click Events
    click FE1 "https://github.com/guptaryan73/aahar/tree/main/views/"
    click FE2 "https://github.com/guptaryan73/aahar/tree/main/assets/"
    click EXP "https://github.com/guptaryan73/aahar/blob/main/app.js"
    click AR "https://github.com/guptaryan73/aahar/blob/main/routes/admin.js"
    click AGR "https://github.com/guptaryan73/aahar/blob/main/routes/agent.js"
    click AU "https://github.com/guptaryan73/aahar/blob/main/routes/auth.js"
    click DR "https://github.com/guptaryan73/aahar/blob/main/routes/donor.js"
    click HR "https://github.com/guptaryan73/aahar/blob/main/routes/home.js"
    click MW "https://github.com/guptaryan73/aahar/blob/main/middleware/index.js"
    click PA "https://github.com/guptaryan73/aahar/blob/main/config/passport.js"
    click DBC "https://github.com/guptaryan73/aahar/blob/main/config/dbConnection.js"
    click UM "https://github.com/guptaryan73/aahar/blob/main/models/user.js"
    click DMN "https://github.com/guptaryan73/aahar/blob/main/models/donation.js"

    %% Styles
    classDef frontend fill:#f9c,stroke:#333,stroke-width:2px;
    classDef server fill:#bbf,stroke:#333,stroke-width:2px;
    classDef route fill:#ccf,stroke:#333,stroke-width:2px;
    classDef middleware fill:#cfc,stroke:#333,stroke-width:2px;
    classDef auth fill:#fcf,stroke:#333,stroke-width:2px;
    classDef config fill:#ffc,stroke:#333,stroke-width:2px;
    classDef database fill:#faa,stroke:#333,stroke-width:2px;
    classDef models fill:#aff,stroke:#333,stroke-width:2px;
```
