# mondrita/pharmasight architecture

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

- Interactive diagram: https://gitdiagram.com/mondrita/pharmasight
- Repository: https://github.com/mondrita/pharmasight

## Overview

##### Project type and purpose
- This is a full-stack web application (“Pharmasight”) for interactive sales data visualization in the pharmaceutical domain.
- The backend is a Spring Boot REST API with layered architecture (controllers → services → repositories) and Spring Security (JWT).
- The frontend is an Angular SPA that consumes the API, manages authentication, and renders tabular and map-based visualizations using OpenStreetMap.

##### File structure
- Top level:
- pharmasight-backend/pharmasight → Spring Boot project (build.gradle, src/main/java/... )
- pharmasight-frontend → Angular project (src/app/core, src/app/workspace, assets, environments, etc.)
- pharmasightDB.sql → initial schema for MySQL
- Backend layers:
- config (CorsConfig, SecurityConfig)
- filter (JwtFilter)
- controller (REST endpoints)
- service (business logic)
- repository (Spring Data JPA)
- model (JPA entities)
- dto (payloads)
- exceptions (error handling)
- Frontend modules:
- core/auth (login, JWT interceptor)
- core/layout (main container, routing)
- workspace/leaflet-map (map container, views, models, map routes)
- shared (guards, directives)
- services (auth.service, map.service, helper.service)

##### README for additional insights
- Live demo, prerequisites, setup steps
- Tech stack summary: Java11+, Spring Boot, Angular, MySQL, OpenStreetMap, Spring Security
- Key features: search with filters, table + map views, drill-down map interactions, market share & brand insights, Excel export

##### Elements
- Blue for frontend modules
- Green for backend layers
- Orange for external services
- Grey for database
- Rectangles for application components
- Clouds for external services

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend
    subgraph "User's Browser (Angular SPA)" 
        direction TB
        AuthCore["Core/Auth"]:::frontend
        LayoutCore["Core/Layout"]:::frontend
        Workspace["Workspace/Leaflet Map"]:::frontend
        Shared["Shared Module"]:::frontend
        FeServices["Services"]:::frontend
    end

    %% Backend
    subgraph "Backend API (Spring Boot Application)"
        direction TB
        subgraph "Config Layer"
            CorsConfig["CorsConfig"]:::backend
            SecurityConfig["SecurityConfig"]:::backend
        end
        subgraph "Filter Layer"
            JwtFilter["JwtFilter"]:::backend
        end
        subgraph "Controller Layer"
            UserController["UserController"]:::backend
            DivisionController["DivisionController"]:::backend
            SalesReportController["SalesReportController"]:::backend
            VendorController["VendorController"]:::backend
            ExportController["ExportController"]:::backend
            FileUploadController["FileUploadController"]:::backend
            GenericController["GenericController"]:::backend
        end
        subgraph "Service Layer"
            UserService["UserService"]:::backend
            DivisionService["DivisionService"]:::backend
            PrescriptionService["PrescriptionService"]:::backend
            VendorService["VendorService"]:::backend
            ExcelService["ExcelService"]:::backend
            JWTService["JWTService"]:::backend
            MyUserDetailsService["MyUserDetailsService"]:::backend
            GenericService["GenericService"]:::backend
        end
        subgraph "Repository Layer"
            UserRepo["UserRepo"]:::backend
            DivisionRepository["DivisionRepository"]:::backend
            DistrictRepository["DistrictRepository"]:::backend
            PrescriptionRepository["PrescriptionRepository"]:::backend
            VendorRepository["VendorRepository"]:::backend
            GenericRepository["GenericRepository"]:::backend
        end
        subgraph "Model & DTO"
            Entities["JPA Entities"]:::backend
            DTOs["DTOs"]:::backend
        end
        subgraph "Exception Handling"
            GlobalExceptionHandler["GlobalExceptionHandler"]:::backend
            ResourceNotFoundException["ResourceNotFoundException"]:::backend
            UserNotFoundException["UserNotFoundException"]:::backend
        end
    end

    %% Database and External
    Database["MySQL Database"]:::db
    External["OpenStreetMap Tile Server"]:::external

    %% Data Flows
    AuthCore -->|Login POST /login| BackendApplication["PharmasightApplication"]:::backend
    FeServices -->|API Calls with JWT| BackendApplication
    BackendApplication -->|pass through JwtFilter| JwtFilter
    JwtFilter --> UserController
    UserController --> UserService --> UserRepo --> Database
    DivisionController --> DivisionService --> DivisionRepository --> Database
    SalesReportController --> PrescriptionService --> PrescriptionRepository --> Database
    VendorController --> VendorService --> VendorRepository --> Database
    GenericController --> GenericService --> GenericRepository --> Database
    ExportController --> ExcelService -->|Generate Excel| ExportController
    ExportController --> FeServices
    Workspace -->|Fetch map tiles| External

    %% Click Events Frontend
    click AuthCore "https://github.com/mondrita/pharmasight/tree/main/pharmasight-frontend/src/app/core/auth"
    click LayoutCore "https://github.com/mondrita/pharmasight/blob/main/pharmasight-frontend/src/app/core/layout/main/main.component.ts"
    click Workspace "https://github.com/mondrita/pharmasight/blob/main/pharmasight-frontend/src/app/workspace/leaflet-map/containers/leaflet-map-container/leaflet-map-container.component.ts"
    click Shared "https://github.com/mondrita/pharmasight/blob/main/pharmasight-frontend/src/app/shared/guards/auth.guard.ts"
    click FeServices "https://github.com/mondrita/pharmasight/blob/main/pharmasight-frontend/src/app/service/auth.service.ts"

    %% Click Events Backend
    click BackendApplication "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/PharmasightApplication.java"
    click CorsConfig "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/config/CorsConfig.java"
    click SecurityConfig "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/config/SecurityConfig.java"
    click JwtFilter "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/filter/JwtFilter.java"
    click UserController "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/controller/UserController.java"
    click DivisionController "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/controller/DivisionController.java"
    click SalesReportController "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/controller/SalesReportController.java"
    click VendorController "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/controller/VendorController.java"
    click ExportController "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/controller/ExportController.java"
    click FileUploadController "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/controller/FileUploadController.java"
    click GenericController "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/controller/GenericController.java"
    click UserService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/UserService.java"
    click DivisionService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/DivisionService.java"
    click PrescriptionService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/PrescriptionService.java"
    click VendorService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/VendorService.java"
    click ExcelService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/ExcelService.java"
    click JWTService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/JWTService.java"
    click MyUserDetailsService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/MyUserDetailsService.java"
    click GenericService "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/service/GenericService.java"
    click UserRepo "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/repository/UserRepo.java"
    click DivisionRepository "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/repository/DivisionRepository.java"
    click DistrictRepository "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/repository/DistrictRepository.java"
    click PrescriptionRepository "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/repository/PrescriptionRepository.java"
    click VendorRepository "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/repository/VendorRepository.java"
    click GenericRepository "https://github.com/mondrita/pharmasight/blob/main/pharmasight-backend/pharmasight/src/main/java/com/pharmasight/repository/GenericRepository.java"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px;
    classDef backend fill:#E6FFE6,stroke:#333,stroke-width:1px;
    classDef external fill:#FFE6CC,stroke:#333,stroke-width:1px;
    classDef db fill:#EEEEEE,stroke:#333,stroke-width:1px;
```
