# tanmaybajpai/nexpave architecture

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

- Interactive diagram: https://gitdiagram.com/tanmaybajpai/nexpave
- Repository: https://github.com/tanmaybajpai/nexpave

## Overview

1. **Overall shape**
   NexPave is a three-part monorepo: a **React/Vite frontend**, a **Spring Boot backend**, and a **FastAPI ML service**. The backend appears to be the system of record and orchestration layer, while the FastAPI service handles pothole image analysis.

2. **Frontend boundary**
   The `Frontend/` app is a TypeScript React SPA built with Vite and Tailwind/PostCSS. Its main screens are `HomePage`, `ReportPage`, `Admin`, `ContractorPortalPage`, and `NotFoundPage`, which suggests separate user flows for citizens, administrators, and contractors.

3. **Frontend UI components and data entry**
   Reusable components like `ImageUpload`, `MapView`, `PotholeCard`, `Layout`, and `Logo` indicate the UI centers on **capturing a report with an image and location**, then presenting report/repair status. The presence of a map component implies GPS coordinates are part of the reporting payload, consistent with the README.

4. **Backend application role**
   `Backend/` is a Spring Boot application that exposes the main business and security endpoints. It is the core integration layer between the SPA, authentication, persistence, and the ML/traffic-related services.

5. **Backend web and auth surface**
   `Controllers/AuthController`, `MainController`, and `API` define the HTTP entry points. The backend also includes `SecurityConfiguration`, `AuthSuccessHandler`, `CustomUserDetailsService`, and `CreateUserService`, so authentication is a first-class concern and likely includes login/register flows plus role-based redirects or access control.

6. **Backend domain model**
   The persistence layer is organized around `Report`, `ReportRequest`, `Contractor`, `PaymentOrder`, and `Status`. That suggests the core lifecycle is: a report is created, assigned or claimed by a contractor, status changes over time, and payment/bounty records are tracked separately.

7. **Persistence boundary**
   The repositories `ReportRepository`, `PaymentOrderRepository`, and `UserRepository` indicate the backend uses a database-backed repository pattern. The README says H2, so the diagram should show the Spring Boot service persisting application state into an embedded relational database rather than calling an external datastore.

8. **Business services**
   The main service layer includes `CreateReportService`, `CreateUserService`, and `GetTrafficService`. This points to three key business functions: report creation, user onboarding, and retrieving traffic-density data used in bounty calculation. These services are where orchestration and domain logic likely live.

9. **ML/analysis boundary**
   The `FastAPI/` service contains `main.py` and Python dependencies, and the README explicitly says it runs YOLOv8-based pothole detection. This service is likely called by the backend with uploaded images, returning detection results such as pothole count/severity that feed report scoring and bounty calculation.

10. **End-to-end data flow**
   The main flow is: **user uploads image + address + coordinates in the frontend → backend receives report request → backend forwards image to FastAPI for detection → detection results plus traffic data influence the bounty → report and payment state are stored in the backend DB**.

11. **Repair and verification flow**
   A second lifecycle exists for contractors: **claim report/bounty → upload “after” image → backend verifies repair**, likely using the same ML-oriented pipeline or a comparison step, then updates the report/payment status. The `PaymentOrder` entity and `Status` enum support this escrow/release workflow.

12. **Presentation vs. API separation**
   The backend contains `templates/login.html` and `templates/register.html` plus static CSS, so it still serves some server-rendered auth pages in addition to API endpoints. That means the architecture is not a pure SPA: the React frontend handles the main application experience, while Spring Boot also owns legacy or dedicated login/register rendering.

13. **What to show in an architecture diagram**
   A useful diagram would show:
   - **React SPA** as the user-facing client
   - **Spring Boot backend** as the central orchestrator/API layer
   - **H2 database** behind the backend
   - **FastAPI YOLOv8 service** as a separate ML microservice
   - External data source or logic for **traffic density** if `GetTrafficService` reaches outside the repo
   - Distinct user paths for **citizen reporting**, **contractor repair/claiming**, and **admin oversight**

Main entry points: [`Frontend/src/App.tsx`](https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/App.tsx) (React App), [`Backend/src/main/java/com/example/nexpave/Controllers/API.java`](https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Controllers/API.java) (HTTP API), [`Backend/src/main/java/com/example/nexpave/Services`](https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Services) (Business Services), [`Backend/src/main/java/com/example/nexpave/Repositories`](https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Repositories) (Repositories)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_frontend_app["React App<br/>Vite SPA<br/>[App.tsx]"]
  node_frontend_home["Home<br/>landing page<br/>[HomePage.tsx]"]
  node_frontend_report["Report<br/>submission page<br/>[ReportPage.tsx]"]
  node_frontend_admin["Admin<br/>[Admin.tsx]"]
  node_frontend_contractor["Contractor<br/>portal page"]
  node_frontend_components["UI Components<br/>shared UI"]
end

subgraph group_backend["Spring Backend"]
  node_backend_api["HTTP API<br/>controllers<br/>[API.java]"]
  node_backend_auth["Auth Controller<br/>web auth"]
  node_backend_main["Main Controller<br/>web controller"]
  node_backend_security["Security"]
  node_backend_services["Business Services<br/>service layer"]
  node_backend_domain["Domain Models<br/>entities"]
  node_backend_repos["Repositories<br/>persistence"]
  node_backend_db[("H2 DB<br/>embedded database")]
  node_backend_templates["Auth Views<br/>server templates"]
  node_traffic_source(("Traffic Data<br/>external data"))
end

subgraph group_ml["ML Service"]
  node_ml_api["YOLO Service<br/>FastAPI ML<br/>[main.py]"]
end

node_frontend_app -->|"routes to"| node_frontend_home
node_frontend_app -->|"routes to"| node_frontend_report
node_frontend_app -->|"routes to"| node_frontend_admin
node_frontend_app -->|"routes to"| node_frontend_contractor
node_frontend_app -->|"uses"| node_frontend_components
node_frontend_report -->|"submits report"| node_backend_api
node_frontend_contractor -->|"updates repair"| node_backend_api
node_frontend_admin -->|"manages"| node_backend_api
node_frontend_app -->|"authenticates"| node_backend_auth
node_backend_api -->|"delegates"| node_backend_services
node_backend_auth -->|"protected by"| node_backend_security
node_backend_main -->|"renders"| node_backend_templates
node_backend_services -->|"reads/writes"| node_backend_domain
node_backend_services -->|"analyzes image"| node_ml_api
node_backend_services -->|"looks up"| node_traffic_source
node_backend_domain -->|"persisted via"| node_backend_repos
node_backend_repos -->|"stores in"| node_backend_db
node_backend_security -->|"loads users"| node_backend_repos
node_backend_api -->|"shares entry points"| node_backend_main

click node_frontend_app "https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/App.tsx"
click node_frontend_home "https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/HomePage.tsx"
click node_frontend_report "https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/ReportPage.tsx"
click node_frontend_admin "https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/Admin.tsx"
click node_frontend_contractor "https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/ContractorPortalPage.tsx"
click node_frontend_components "https://github.com/tanmaybajpai/nexpave/tree/main/Frontend/src/components"
click node_backend_api "https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Controllers/API.java"
click node_backend_auth "https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Controllers/AuthController.java"
click node_backend_main "https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Controllers/MainController.java"
click node_backend_security "https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Security/SecurityConfiguration.java"
click node_backend_services "https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Services"
click node_backend_domain "https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Entities"
click node_backend_repos "https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Repositories"
click node_backend_templates "https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/resources/templates"
click node_ml_api "https://github.com/tanmaybajpai/nexpave/blob/main/FastAPI/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_home,node_frontend_report,node_frontend_admin,node_frontend_contractor,node_frontend_components toneBlue
class node_backend_api,node_backend_auth,node_backend_main,node_backend_security,node_backend_services,node_backend_domain,node_backend_repos,node_backend_db,node_backend_templates,node_traffic_source toneAmber
class node_ml_api toneMint
```

## Components

### Frontend SPA

React/Vite client for citizens, contractors, and admins.

- [React App](https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/App.tsx): Vite SPA · Main browser client and routed user experience. · `Frontend/src/App.tsx`
- [Home](https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/HomePage.tsx): landing page · Public entry page for the application. · `Frontend/src/pages/HomePage.tsx`
- [Report](https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/ReportPage.tsx): submission page · Citizen workflow for creating a pothole report. · `Frontend/src/pages/ReportPage.tsx`
- [Admin](https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/Admin.tsx): admin page · Administrative oversight and management screen. · `Frontend/src/pages/Admin.tsx`
- [Contractor](https://github.com/tanmaybajpai/nexpave/blob/main/Frontend/src/pages/ContractorPortalPage.tsx): portal page · Contractor workflow for claiming and completing repairs. · `Frontend/src/pages/ContractorPortalPage.tsx`
- [UI Components](https://github.com/tanmaybajpai/nexpave/tree/main/Frontend/src/components): shared UI · Reusable upload, map, layout, logo, and card components. · `Frontend/src/components`

### Spring Backend

Core API, auth, domain logic, and persistence.

- [HTTP API](https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Controllers/API.java): controllers · Main REST and web entry points for the application. · `Backend/src/main/java/com/example/nexpave/Controllers/API.java`
- [Auth Controller](https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Controllers/AuthController.java): web auth · Login, registration, and authentication endpoints. · `Backend/src/main/java/com/example/nexpave/Controllers/AuthController.java`
- [Main Controller](https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Controllers/MainController.java): web controller · Server-side page and routing controller. · `Backend/src/main/java/com/example/nexpave/Controllers/MainController.java`
- [Security](https://github.com/tanmaybajpai/nexpave/blob/main/Backend/src/main/java/com/example/nexpave/Security/SecurityConfiguration.java): spring security · Authentication and access-control configuration. · `Backend/src/main/java/com/example/nexpave/Security/SecurityConfiguration.java`
- [Business Services](https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Services): service layer · Report creation, user onboarding, and traffic lookup orchestration. · `Backend/src/main/java/com/example/nexpave/Services`
- [Domain Models](https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Entities): entities · Report, contractor, payment, request, and status state. · `Backend/src/main/java/com/example/nexpave/Entities`
- [Repositories](https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/java/com/example/nexpave/Repositories): persistence · Database access layer for reports, payments, and users. · `Backend/src/main/java/com/example/nexpave/Repositories`
- **H2 DB**: embedded database · Embedded relational store for application state.
- [Auth Views](https://github.com/tanmaybajpai/nexpave/tree/main/Backend/src/main/resources/templates): server templates · Rendered login and register pages with static styling. · `Backend/src/main/resources/templates`
- **Traffic Data**: external data · External or derived traffic-density input used for bounty logic.

### ML Service

FastAPI pothole detection service.

- [YOLO Service](https://github.com/tanmaybajpai/nexpave/blob/main/FastAPI/main.py): FastAPI ML · Image analysis microservice for pothole detection. · `FastAPI/main.py`

## Connections

- React App → Home: routes to · SPA includes the main landing experience.
- React App → Report: routes to · Citizen reporting flow.
- React App → Admin: routes to · Admin workflow.
- React App → Contractor: routes to · Contractor workflow.
- React App → UI Components: uses · Shared UI building blocks.
- Report → HTTP API: submits report · Sends image, location, and report payload.
- Contractor → HTTP API: updates repair · Claims reports and submits after-image verification.
- Admin → HTTP API: manages · Admin-facing application actions.
- React App → Auth Controller: authenticates · Login and registration interactions.
- HTTP API → Business Services: delegates · Business operations are handled in services.
- Auth Controller → Security: protected by · Security configuration guards auth flows.
- Main Controller → Auth Views: renders · Server-side auth pages.
- Business Services → Domain Models: reads/writes · Operates on core domain objects.
- Business Services → YOLO Service: analyzes image · Forwards report images for pothole detection.
- Business Services → Traffic Data: looks up · Uses traffic density in bounty calculation.
- Domain Models → Repositories: persisted via · Domain state is stored through repositories.
- Repositories → H2 DB: stores in · Persistent application data in embedded H2.
- Security → Repositories: loads users · User details and access control depend on persistence.
- HTTP API → Main Controller: shares entry points · Application has both API and rendered web routes.
