# prathi912/rdc-imr architecture

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

- Interactive diagram: https://gitdiagram.com/prathi912/rdc-imr
- Repository: https://github.com/prathi912/rdc-imr

## Overview

##### Project type and purpose
- This is a full-stack, role-based web portal (“Research & Development Portal”) built with Next.js (App Router) on the front- and back-end, coupled with Firebase services (Auth, Firestore, Storage, Hosting, Cloud Functions) and Google Genkit for AI. It’s used by faculty, evaluators, CROs, admins, and super-admins to manage Intramural Research (IMR) lifecycle: proposal submission, review (AI-assisted), scheduling, grant management, analytics, and user/module administration.

##### File structure
- Top-level directories and files:
- src/app/… : Next.js App Router pages, layouts, and API routes (serverless functions)
- src/components/… : React UI components organized by feature and generic UI primitives
- src/lib/… : Firebase configuration & admin SDK, security modules, utilities
- src/ai/… : Google Genkit flows for AI-powered features
- dataconnect/… : A GraphQL connector layer (YAML + .gql files) for external data sources
- firebase.json, firestore.rules/indexes: Firebase config for Hosting, Firestore rules
- apphosting.yaml: deployment config for Firebase App Hosting
- package.json, tsconfig.json, tailwind.config.ts, postcss.config.mjs: build & styling
- Architectural patterns:
- Client-server separation within a single Next.js monorepo
- API routes = serverless functions
- RBAC implemented via Firebase Auth + custom security modules
- AI services abstracted behind a “Genkit flows” layer
- Data-connector layer for external GraphQL sources
- Cron triggers as serverless functions for scheduled tasks
- Bulk data import via Excel templates and an upload API

##### Extract insights from the README
- Roles & their permissions (faculty, evaluators, CRO, admin, super-admin) → RBAC is central
- Workflows: multi-step submission, review with AI prompts, scheduling with email notifications, grant disbursement
- AI integrations: summarization, domain suggestion, journal website finder
- Tech stack: Next.js, TypeScript, Tailwind, ShadCN UI, Firebase suite, Genkit, Nodemailer, optional external APIs
- Deployment: Firebase Hosting (apphosting.yaml controls build), CI/CD via GitHub → Firebase

a. Main components
- Client Browser / SPA (React + ShadCN UI in Next.js)
- Next.js App (Hosted on Firebase Hosting / Cloud Functions)
- API Layer (Next.js serverless functions under src/app/api)
- Authentication Service (Firebase Auth)
- Database (Cloud Firestore)
- Storage (Firebase Cloud Storage)
- Cloud Functions
- Cron jobs (send-meeting-reminders)
- Bulk upload processing
- Email notifications (Nodemailer + Gmail)
- AI Engine (Google Genkit flows invoked by serverless functions)
- Data Connector (GraphQL connector for external academic data)
- External APIs
- Optional: Scopus, WOS, Springer
- CI/CD Pipeline (GitHub → Firebase Hosting)

b. Relationships and interactions
- Browser ↔ Next.js Frontend (SSR/CSR)
- Frontend ↔ Serverless API Endpoints (auth, get-departments, research-papers, staff-data, cron triggers)
- API Endpoints ↔ Firebase Auth (validate tokens, enforce RBAC)
- API ↔ Firestore (read/write research projects, user profiles, logs)
- API ↔ Cloud Storage (upload/download proposal PDFs, CVs)
- Cron Functions ↔ Firestore + Nodemailer → email reminders
- AI Functions ↔ Genkit SDK → AI flows → Firestore updates
- Data Connector ↔ External GraphQL endpoints → enrich AI and UI workflows
- CI/CD ↔ Firebase Hosting (push new build)

c. Architectural patterns/design principles
- Monorepo with co-located frontend/back-end reduces context switching
- Serverless functions for horizontal scaling and granular security
- RBAC centralized in Firebase + custom “modules.ts” guards
- Flows layer for AI isolates complexity and eases extension
- GraphQL-based connector for decoupling external data sources
- Cron scheduling via HTTP-triggered serverless functions (Firestore triggers optional)

d. Key technologies/frameworks
- Next.js (App Router, serverless API routes)
- React, TypeScript, Tailwind CSS, ShadCN UI
- Firebase (Auth, Firestore, Storage, Hosting, Cloud Functions)
- Google Genkit (AI Toolkit)
- GraphQL connector (dataconnect folder)
- Nodemailer + Gmail for transactional email

##### Final advice
- Break the system into logical tiers: Presentation, API, Business Logic (AI/Connector), Persistence, External Integrations.
- Essential elements: RBAC, AI layer, dataconnect, cron jobs, external APIs.
- Don’t overcomplicate—detail comes from decomposing each service and showing its dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Presentation Layer"
        Browser["Client Browser / SPA"]:::client
    end

    subgraph "Next.js Server"
        subgraph "Frontend"
            NextApp["Next.js App (App Router)"]:::server
        end
        subgraph "API Layer"
            APILayer["Next.js API Routes"]:::server
        end
    end

    subgraph "Business Logic"
        Cron["Cron Jobs"]:::server
        EmailNotif["Email Notifications (Nodemailer)"]:::external
        AIEngine["AI Engine (Genkit Flows)"]:::external
        DataConn["Data Connector (GraphQL)"]:::external
    end

    subgraph "Firebase Services"
        Auth["Authentication Service (Firebase Auth & RBAC)"]:::firebase
        Firestore["Cloud Firestore"]:::firebase
        Storage["Cloud Storage"]:::firebase
        Functions["Cloud Functions"]:::firebase
    end

    subgraph "CI/CD & Hosting"
        CICD["CI/CD & Hosting Config"]:::ci
    end

    subgraph "Bulk Data Import"
        Bulk["Bulk Data Import (Excel Upload)"]:::server
    end

    Browser --> NextApp
    NextApp --> APILayer
    APILayer --> Auth
    APILayer --> Firestore
    APILayer --> Storage
    APILayer --> AIEngine
    APILayer --> DataConn

    Cron --> Firestore
    Cron --> EmailNotif
    EmailNotif -->|sends email to| Browser

    AIEngine --> Firestore
    DataConn --> APILayer

    CICD --> NextApp
    Bulk --> APILayer
    Bulk --> Firestore

    click Browser "https://github.com/prathi912/rdc-imr/tree/master/src/app"
    click NextApp "https://github.com/prathi912/rdc-imr/tree/master/src/app"
    click APILayer "https://github.com/prathi912/rdc-imr/tree/master/src/app/api"
    click Auth "https://github.com/prathi912/rdc-imr/blob/master/src/lib/config.ts"
    click Firestore "https://github.com/prathi912/rdc-imr/blob/master/firebase.json"
    click Storage "https://github.com/prathi912/rdc-imr/blob/master/storage.rules"
    click Cron "https://github.com/prathi912/rdc-imr/blob/master/src/app/api/cron/send-meeting-reminders/route.ts"
    click EmailNotif "https://github.com/prathi912/rdc-imr/blob/master/src/lib/email.ts"
    click AIEngine "https://github.com/prathi912/rdc-imr/blob/master/src/ai/genkit.ts"
    click DataConn "https://github.com/prathi912/rdc-imr/blob/master/dataconnect/connector/connector.yaml"
    click CICD "https://github.com/prathi912/rdc-imr/blob/master/apphosting.yaml"
    click Bulk "https://github.com/prathi912/rdc-imr/blob/master/src/app/dashboard/bulk-upload/page.tsx"

    classDef client fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef server fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef firebase fill:#FFF3E0,stroke:#EF6C00,color:#E65100
    classDef external fill:#F3E5F5,stroke:#6A1B9A,color:#4A148C
    classDef ci fill:#ECEFF1,stroke:#546E7A,color:#263238
```
