# hoaphamduc/jd-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/hoaphamduc/jd-assistant
- Repository: https://github.com/hoaphamduc/jd-assistant

## Overview

##### Project Type and Purpose
- The JD Assistant is a web application that generates interview questions based on a job description (JD). It leverages Google Generative AI for creating questions and evaluating candidate answers.
- The app is designed as a full-stack Node.js application with a clear separation between routing, controller logic, and view rendering.

##### File Structure
- Top-Level Files:
- .env: Contains configuration variables (such as API keys and port settings).
- server.js: The main entry point for starting the Express server.
- package.json and package-lock.json: Manage dependencies and scripts.
- Directories:
- controllers: Contains JDController.js, which houses the core business logic for generating questions and evaluating answers.
- routes: Contains jdRoutes.js, defining the HTTP endpoints and mapping them to controller actions.
- views: Contains jd.ejs, the EJS template for rendering the user interface where users interact with the app.
- Although not shown in the file tree provided, the README mentions a “public” directory for static assets (CSS, JavaScript, images), so be sure to include that component as well.

##### Main Components and Their Interactions
- Client/Browser: Represents the user interface. Users interact with the web page served via the EJS view (jd.ejs) and static assets from the public folder.
- Express Server:
- server.js initializes the Express application.
- It hosts middleware that processes incoming requests, serves static assets, and directs requests to routes.
- Routes (jdRoutes.js):
- Available endpoints (e.g., form submissions and file uploads).
- They forward requests to the appropriate controller.
- Controllers (JDController.js):
- Handle the business logic, including interfacing with the Google Generative AI API to generate interview questions and process candidate answers.
- External API:
- Google Generative AI: The controller calls this API using the API key stored in the .env file. This is an external dependency that is critical to the application's functionality.
- Configuration:
- Managed via the .env file (e.g., GEN_API_KEY, PORT), ensuring that sensitive data and server settings are configurable without changing source code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Client["Client/Browser"]:::frontend
        View["View (jd.ejs)"]:::frontend
        Public["Public Assets"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Express["Express Server"]:::backend
        Routes["Routes (jdRoutes.js)"]:::backend
        Controller["Controller (JDController.js)"]:::backend
        Config["Configuration (.env)"]:::backend
    end

    %% External Service
    ExtAPI["Google Generative AI"]:::external

    %% Connections
    Client -->|"HTTP_Request"| Express
    Express -->|"Route_Mapping"| Routes
    Routes -->|"Forward_Request"| Controller
    Controller -->|"API_Call"| ExtAPI
    Controller -->|"Render_View"| View
    Express -->|"Load_Config"| Config
    Express -->|"Serve_Assets"| Public
    View -->|"Return_HTML"| Client
    Public -->|"Static_Content"| Client

    %% Click Events
    click Express "https://github.com/hoaphamduc/jd-assistant/blob/main/server.js"
    click Routes "https://github.com/hoaphamduc/jd-assistant/blob/main/routes/jdRoutes.js"
    click Controller "https://github.com/hoaphamduc/jd-assistant/blob/main/controllers/JDController.js"
    click View "https://github.com/hoaphamduc/jd-assistant/blob/main/views/jd.ejs"
    click Config "https://github.com/hoaphamduc/jd-assistant/blob/main/.env"
    click Public "https://github.com/hoaphamduc/jd-assistant/tree/main/public"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
```
