# cristian-estevez/vulnerability_manager architecture

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

- Interactive diagram: https://gitdiagram.com/cristian-estevez/vulnerability_manager
- Repository: https://github.com/cristian-estevez/vulnerability_manager

## Overview

Based on your provided file tree and README, this project is a full-stack web application called “Vulnerability Manager” built with Next.js. Its purpose is to help manage vulnerability reports and customer data, and it includes API endpoints, a dashboard interface for admins, and database integration (with Postgres managed via Docker).

##### Project Type and Purpose
- This is a full-stack web application built using Next.js. It supports both a user-facing interface (for visualizing reports, charts, and customer data) and an administrative dashboard.
- The application manages vulnerabilities and customer data via API endpoints, integrates with a Postgres database, and leverages containerization (Docker) for database management.

##### Main Components of the System
a. Frontend (Client UI)
- Components located under “src/app” provide the client-facing UI.
- There are segmented directories like “src/app/_components” (e.g., AppAppBar, Hero, Footers, and charts) and a dedicated dashboard under “src/app/dashboard” (with its own subcomponents like AppNavbar, SideMenu, etc.).
- Additionally, common UI elements appear under “src/components” (for navigation, charts, modals, etc.).
- The Next.js routing (pages and layouts) structures the app’s different views (main page, dashboard, and customer/vulnerability pages).

b. API Layer
- The “src/app/api” directory encompasses various API endpoints including:
- criticality-percentage-chart,
- customers-reports-chart,
- customers,
- state-percentage-chart,
- vulnerability-manager.
- These endpoints are crucial for fetching and updating vulnerability and customer data and they interface with both server actions and the DB.

c. Server and Business Logic
- The “src/server” directory contains actions for customers and vulnerabilityReports. These server actions encapsulate the business logic required to perform operations like CRUD actions, data manipulation, and interfacing between the frontend and the database.

d. Database Layer
- The project uses a Postgres database configured via Docker (as outlined in docker-compose.yml and .env.example).
- The “src/db” folder contains the ORM configuration (drizzle.config.ts, schema.ts) and the database models (located in “src/db/schemas” and enums in “src/db/enums”).
- Initialization scripts under “init-scripts” (e.g., init.sql) set up the initial database state.

e. Configuration & Tooling
- Various configuration files are in place (e.g., next.config.ts, tailwind.config.ts, eslint.config.mjs, postcss.config.mjs, etc.) to manage building, styling, and code quality.
- Container orchestration (docker-compose) is used to manage the database and possibly other services.

##### Relationships and Interactions
- The Frontend communicates with the API endpoints to fetch data for rendering charts and populating data grids. This interaction is typically over HTTP (via Next.js API routes).
- API endpoints pass requests to the server actions (in “src/server/actions”), where business logic (such as data validation or transformations) is applied.
- Server actions interact with the database (using the configuration and schemas defined in “src/db”) to query, insert, update, or delete records.
- The database runs in a containerized environment, and connection details are managed via environment variables and the .env file.

##### Architectural Patterns and Design Principles
- Separation of concerns: The application cleanly separates the front-end (Next.js pages and components), API endpoints, and backend business logic.
- Modular design: With clearly segmented directories for components, API endpoints, dashboard features, and server actions, each module is well-isolated.
- Use of an ORM (Drizzle) provides an abstraction over the Postgres database.
- Responsive UI and theming: The “src/theme” directory indicates a set of customizations for UI styling and theming.

##### Final Reminder to the Principal Software Engineer
- Avoid oversimplification – include as much relevant detail as possible (for instance, annotate which directories or files represent each component).
- Remember to note that the architecture leverages Next.js routing, server actions for business logic, and containerized database management (Docker) to present a complete picture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer - General UI Components
    subgraph "Frontend (Client UI)"
        FE1["Frontend: src/app"] 
        FE2["Frontend: src/app/_components"]
        FE3["Frontend: src/components"]
    end

    %% Dashboard UI Components
    subgraph "Dashboard UI Components"
        DBUI1["Dashboard: src/app/dashboard"]
        DBUI2["Dashboard: src/app/dashboard/_components"]
        DBUI3["Dashboard: src/app/dashboard/customers/_components"]
        DBUI4["Dashboard: src/app/dashboard/vulnerabilities-report/_components"]
    end

    %% API Layer
    subgraph "API Endpoints"
        API1["API: /criticality-percentage-chart"]
        API2["API: /customers-reports-chart"]
        API3["API: /customers"]
        API4["API: /state-percentage-chart"]
        API5["API: /vulnerability-manager"]
    end

    %% Server Actions / Business Logic
    subgraph "Server Actions"
        SA1["Server: customers actions"]
        SA2["Server: vulnerabilityReports actions"]
    end

    %% Database Layer
    subgraph "Database Layer"
        DB1["ORM & Models: src/db"]
        DB2["DB Init Script: init-scripts/init.sql"]
        DB3["Postgres Database (Docker)"]
    end

    %% Configuration & Tooling
    subgraph "Configuration & Tooling"
        CT1["docker-compose.yml"]
        CT2[".env.example"]
        CT3["next.config.ts"]
        CT4["tailwind.config.ts"]
        CT5["postcss.config.mjs"]
        CT6["eslint.config.mjs"]
    end

    %% Theming & Styling
    subgraph "Theming & Styling"
        TH1["Theme: src/theme"]
        TH2["Customizations: src/theme/customizations"]
    end

    %% Interconnections
    %% Frontend to API
    FE1 -->|"HTTP Request"| API1
    FE1 -->|"HTTP Request"| API2
    FE1 -->|"HTTP Request"| API3
    FE1 -->|"HTTP Request"| API4
    FE1 -->|"HTTP Request"| API5

    DBUI1 -->|"HTTP Request"| API1
    DBUI1 -->|"HTTP Request"| API2
    DBUI1 -->|"HTTP Request"| API3
    DBUI1 -->|"HTTP Request"| API4
    DBUI1 -->|"HTTP Request"| API5

    %% API to Server Actions
    API3 -->|"calls"| SA1
    API2 -->|"calls"| SA1
    API4 -->|"calls"| SA1
    API5 -->|"calls"| SA2

    %% Server Actions to Database
    SA1 -->|"queries/updates"| DB1
    SA2 -->|"queries/updates"| DB1
    DB1 -->|"connects"| DB3

    %% Configuration influences Database and Frontend
    CT1 -->|"orchestrates"| DB3
    CT3 -->|"configures"| FE1

    %% Theming applied to Frontend
    TH1 -->|"styles"| FE1
    TH2 -->|"styles"| FE1

    %% Click Events for Frontend
    click FE1 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/app"
    click FE2 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/app/_components"
    click FE3 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/components"

    %% Click Events for Dashboard UI Components
    click DBUI1 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/app/dashboard"
    click DBUI2 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/app/dashboard/_components"
    click DBUI3 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/app/dashboard/customers/_components"
    click DBUI4 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/app/dashboard/vulnerabilities-report/_components"

    %% Click Events for API Endpoints
    click API1 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/src/app/api/criticality-percentage-chart/route.ts"
    click API2 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/src/app/api/customers-reports-chart/route.ts"
    click API3 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/src/app/api/customers/route.ts"
    click API4 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/src/app/api/state-percentage-chart/route.ts"
    click API5 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/src/app/api/vulnerability-manager/route.ts"

    %% Click Events for Server Actions
    click SA1 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/src/server/actions/customers/actions.ts"
    click SA2 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/src/server/actions/vulnerabilityReports/actions.ts"

    %% Click Events for Database Layer
    click DB1 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/db"
    click DB2 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/init-scripts/init.sql"

    %% Click Events for Configuration & Tooling
    click CT1 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/docker-compose.yml"
    click CT2 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/.env.example"
    click CT3 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/next.config.ts"
    click CT4 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/tailwind.config.ts"
    click CT5 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/postcss.config.mjs"
    click CT6 "https://github.com/cristian-estevez/vulnerability_manager/blob/main/eslint.config.mjs"

    %% Click Events for Theming & Styling
    click TH1 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/theme"
    click TH2 "https://github.com/cristian-estevez/vulnerability_manager/tree/main/src/theme/customizations"

    %% Style Classes
    class FE1,FE2,FE3,DBUI1,DBUI2,DBUI3,DBUI4,TH1,TH2 fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    class API1,API2,API3,API4,API5 fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    class SA1,SA2 fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    class DB1,DB2,DB3 fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
    class CT1,CT2,CT3,CT4,CT5,CT6 fill:#FADBD8,stroke:#CD6155,stroke-width:2px;
    class TH1,TH2 fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
