# rikibanik/heritage_hub architecture

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

- Interactive diagram: https://gitdiagram.com/rikibanik/heritage_hub
- Repository: https://github.com/rikibanik/heritage_hub

## Overview

##### Main Components
- Frontend (Two distinct applications):
- Client: This is the user-facing React application. It handles user authentication (including OTP and Google OAuth), ticket booking, profile management, and payment integration interfaces.
- Author: A separate React application for authors that includes modules for museum management, ticket/slot management, and dashboard views.
- Backend Server:
- A Node.js/Express application that handles the API endpoints for authentication, ticket booking, payment (integrated with Razorpay), role-based access control, and communication with the database.
- Database:
- MongoDB, which stores collections for users, authors, admins, tickets, venues, slots, OTPs, and blacklisted tokens.
- External Services and Third-Party Integrations:
- Authentication via Google OAuth2 and OTP via Nodemailer.
- Payment gateway integration using Razorpay.
- Hosting and file storage (AWS S3 for media assets and possibly AWS for deployment).

##### Relationships and Interactions
- The two frontend applications (client and author) interact with the backend server via RESTful API calls.
- The backend server communicates with the database to retrieve/update data (ticket bookings, user details, museum venues, etc.).
- Payment processing: The client initiates payment actions which are handled by the server via specific routes and services (e.g., the razorpay controller/service).
- Authentication flow: The server validates user credentials through different strategies (OTP, password, OAuth2) and manages sessions/tokens.
- Admin functionalities are partly rendered via server-side EJS views for dashboards and listings.

##### Architectural Patterns and Design Principles
- Separation of concerns: The project distinctly separates presentation (two frontend applications), business logic (server controllers, services, middleware), and data persistence (MongoDB).
- Role-based access control: Different flows and API endpoints exist for users, authors, and admins.
- Modularity: The backend code is organized in controllers, services, middleware, and models. Similarly, frontend components are grouped (e.g., home, dashboard, museum, RegLog) that indicate component-based architecture (React).
- Scalability: With divided responsibilities and external integration (e.g., payment, authentication, AWS services), the design can scale as each module can be scaled independently.

##### Relevant Technologies, Frameworks, and Libraries
- Frontend: React.js (developed using Vite), Tailwind CSS for styling, and component-based design patterns.
- Backend: Node.js, Express.js, and custom middleware for auth/security.
- Database: MongoDB interacting via defined models.
- External Tools: Razorpay for secure payments, Google OAuth via googleConfig utility, and use of Nodemailer for OTP-based authentication.
- Build Tools/Configurations: ESLint, PostCSS, Tailwind CSS, and Vite configurations on both frontend components.

##### Instructing the Principal Software Engineer
- Labels for each component:
- Client (User Frontend)
- Author (Author Management Frontend)
- Backend Server (REST API, Authentication Module, Payment Module, Admin Module)
- Database (MongoDB with collections for users, authors, tickets, venues, etc.)
- External Services (Google OAuth, Razorpay, AWS S3)
- A two-way connection between the Backend and MongoDB.
- Connections from the Backend to external services (OAuth, payment gateway, AWS).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Client["Client (User Frontend)"]:::frontend
        Author["Author (Museum Manager Frontend)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Backend["Backend Server (Node.js/Express)"]:::backend
        subgraph "Authentication Module"
            AuthController["Auth Controller"]:::backend
            AuthRoutes["Auth Routes"]:::backend
            OTPService["OTP Service"]:::backend
        end
        subgraph "Payment Module"
            PaymentModule["Payment Module (Razorpay)"]:::backend
        end
        subgraph "Admin Module"
            AdminController["Admin Controller"]:::backend
            AdminRoutes["Admin Routes"]:::backend
            AdminViews["Admin Views (EJS)"]:::backend
        end
        AWSService["File Storage Service (AWS S3)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["MongoDB (Collections: users, authors, tickets, venues, OTPs, tokens)"]:::database
        OTPModel["OTP Model"]:::database
    end

    %% External Services Layer
    subgraph "External Services"
        OAuth["Google OAuth2"]:::external
        RazorpayGateway["Razorpay Payment Gateway"]:::external
    end

    %% Connections between Layers
    Client -->|"APIcalls"| Backend
    Author -->|"APICalls"| Backend

    Backend -->|"StoresData"| DB
    DB -->|"RetrievesData"| Backend

    AuthController -->|"OAuthValidation"| OAuth
    AuthController -->|"SendOTP"| OTPService
    OTPService -->|"UsesModel"| OTPModel

    PaymentModule -->|"ProcessPayment"| RazorpayGateway

    Backend -->|"UsesStorage"| AWSService

    %% Click Events
    click Client "https://github.com/rikibanik/heritage_hub/tree/main/client/"
    click Author "https://github.com/rikibanik/heritage_hub/tree/main/author/"
    click Backend "https://github.com/rikibanik/heritage_hub/tree/main/server/"
    click AuthController "https://github.com/rikibanik/heritage_hub/blob/main/server/controller/authController.js"
    click AuthRoutes "https://github.com/rikibanik/heritage_hub/blob/main/server/routes/authRoutes.js"
    click PaymentModule "https://github.com/rikibanik/heritage_hub/blob/main/server/controller/razorpay.js"
    click AdminController "https://github.com/rikibanik/heritage_hub/blob/main/server/controller/adminController.js"
    click AdminRoutes "https://github.com/rikibanik/heritage_hub/blob/main/server/routes/adminRoutes.js"
    click AdminViews "https://github.com/rikibanik/heritage_hub/blob/main/server/views/admin.ejs"
    click DB "https://github.com/rikibanik/heritage_hub/tree/main/server/db/models/"
    click OAuth "https://github.com/rikibanik/heritage_hub/blob/main/server/utils/googleConfig.js"
    click OTPService "https://github.com/rikibanik/heritage_hub/blob/main/server/services/otpService.js"
    click OTPModel "https://github.com/rikibanik/heritage_hub/blob/main/server/db/models/otpModel.js"
    click AWSService "https://github.com/rikibanik/heritage_hub/blob/main/server/services/s3service.js"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef database fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
