# programmingnotjustcoding/jiva architecture

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

- Interactive diagram: https://gitdiagram.com/programmingnotjustcoding/jiva
- Repository: https://github.com/programmingnotjustcoding/jiva

## Overview

##### Project Type & Purpose
- This is a full‑stack, microservices‑based application (“Jiva”) for coal‑mine operations.
- It comprises:
- Multiple backend services (auth, shift, incident, SMP, workplan, ERP, notification)
- A Next.js web frontend
- A Flutter mobile frontend
- Infrastructure definitions (Docker Compose, Terraform, init scripts)
- Goal: digital shift logs, safety‑management plan (SMP) tracking, incident/hazard reporting, notifications, dashboards.

##### File Structure Analysis
- Top‑level “apps” folder:
- apps/backend – one folder per microservice, each with:
– “bruno” definitions (API specs/tests)
– Drizzle migrations & schema (Postgres)
– src/api (controllers, routes, middlewares)
– src/services (business logic)
– src/config, src/database, src/utils
- apps/web – Next.js app (pages, components, layouts)
- apps/mobile – Flutter app (lib/components, services, models)
- “docker/compose” and “docker/docker-compose.yml” define local services: Postgres, MinIO, Nginx.
- “infra/main.tf” – Terraform for cloud infrastructure.
- “scripts/init-dbs.sh” – database initialization.

##### Key README Insights
- Shift logging/handover, SMP tasks, hazard/incident reporting, alerts, dashboards.
- Indicates domain: mining safety & productivity.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    subgraph "Clients"
        WebApp["Web App"]:::client
        MobileApp["Mobile App"]:::client
    end

    %% API Gateway
    Nginx["API Gateway (Nginx)"]:::gateway

    %% Backend Microservices
    subgraph "Microservices"
        AuthService["Auth Service"]:::service
        ShiftService["Shift Service"]:::service
        IncidentService["Incident Service"]:::service
        SMPService["SMP Service"]:::service
        WorkplanService["Workplan Service"]:::service
        ERPService["ERP Service"]:::service
        NotificationService["Notification Service"]:::service
    end

    %% Databases & Storage
    subgraph "Databases & Storage"
        Postgres["Postgres DB"]:::db
        MinIO["MinIO Storage"]:::db
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Terraform["Terraform (IaC)"]:::infra
        InitDB["DB Init Script"]:::script
    end

    %% Client to Gateway
    WebApp -->|HTTPS| Nginx
    MobileApp -->|HTTPS| Nginx

    %% Gateway to Services
    Nginx -->|HTTP| AuthService
    Nginx -->|HTTP| ShiftService
    Nginx -->|HTTP| IncidentService
    Nginx -->|HTTP| SMPService
    Nginx -->|HTTP| WorkplanService
    Nginx -->|HTTP| ERPService
    Nginx -->|HTTP| NotificationService

    %% Services to Postgres
    AuthService -->|SQL| Postgres
    ShiftService -->|SQL| Postgres
    IncidentService -->|SQL| Postgres
    SMPService -->|SQL| Postgres
    WorkplanService -->|SQL| Postgres
    ERPService -->|SQL| Postgres
    NotificationService -->|SQL| Postgres

    %% Services to MinIO
    IncidentService -->|Object Storage| MinIO
    SMPService -->|Object Storage| MinIO

    %% Auth JWT Flow
    AuthService -->|issues JWT| ShiftService
    AuthService -->|issues JWT| IncidentService
    AuthService -->|issues JWT| SMPService
    AuthService -->|issues JWT| WorkplanService
    AuthService -->|issues JWT| ERPService
    AuthService -->|issues JWT| NotificationService

    %% Infrastructure provisioning
    Terraform -->|provisions| Postgres
    Terraform -->|provisions| MinIO
    InitDB -->|initializes| Postgres

    %% Click Events
    click WebApp "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/web"
    click MobileApp "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/mobile"
    click Nginx "https://github.com/programmingnotjustcoding/jiva/blob/main/docker/compose/nginx/service.yml"
    click AuthService "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/backend/auth-service"
    click ShiftService "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/backend/shift-service"
    click IncidentService "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/backend/incident-service"
    click SMPService "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/backend/smp-service"
    click WorkplanService "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/backend/workplan-service"
    click ERPService "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/backend/erp-service"
    click NotificationService "https://github.com/programmingnotjustcoding/jiva/tree/main/apps/backend/notification-service"
    click Postgres "https://github.com/programmingnotjustcoding/jiva/blob/main/docker/compose/postgres/service.yml"
    click MinIO "https://github.com/programmingnotjustcoding/jiva/blob/main/docker/compose/minio/service.yml"
    click Terraform "https://github.com/programmingnotjustcoding/jiva/blob/main/infra/main.tf"
    click InitDB "https://github.com/programmingnotjustcoding/jiva/blob/main/scripts/init-dbs.sh"

    %% Styles
    classDef client fill:#add8e6,stroke:#000
    classDef service fill:#90ee90,stroke:#000
    classDef db fill:#ffa500,stroke:#000
    classDef gateway fill:#d3d3d3,stroke:#000
    classDef infra fill:#dda0dd,stroke:#000
    classDef script fill:#cccccc,stroke:#000
```
