How tanmaybajpai/nexpave works
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: App.tsx React App · API.java HTTP API · Services Business Services · Repositories Repositories
Components 17
Frontend SPA
React/Vite client for citizens, contractors, and admins.
- React App · Main browser client and routed user experience.
Frontend/src/App.tsx - Home · Public entry page for the application.
Frontend/src/pages/HomePage.tsx - Report · Citizen workflow for creating a pothole report.
Frontend/src/pages/ReportPage.tsx - Admin · Administrative oversight and management screen.
Frontend/src/pages/Admin.tsx - Contractor · Contractor workflow for claiming and completing repairs.
Frontend/src/pages/ContractorPortalPage.tsx - UI Components · Reusable upload, map, layout, logo, and card components.
Frontend/src/components
Spring Backend
Core API, auth, domain logic, and persistence.
- HTTP API · Main REST and web entry points for the application.
Backend/src/main/java/com/example/nexpave/Controllers/API.java - Auth Controller · Login, registration, and authentication endpoints.
Backend/src/main/java/com/example/nexpave/Controllers/AuthController.java - Main Controller · Server-side page and routing controller.
Backend/src/main/java/com/example/nexpave/Controllers/MainController.java - Security · Authentication and access-control configuration.
Backend/src/main/java/com/example/nexpave/Security/SecurityConfiguration.java - Business Services · Report creation, user onboarding, and traffic lookup orchestration.
Backend/src/main/java/com/example/nexpave/Services - Domain Models · Report, contractor, payment, request, and status state.
Backend/src/main/java/com/example/nexpave/Entities - Repositories · Database access layer for reports, payments, and users.
Backend/src/main/java/com/example/nexpave/Repositories - H2 DB · Embedded relational store for application state.
- Auth Views · Rendered login and register pages with static styling.
Backend/src/main/resources/templates - Traffic Data · External or derived traffic-density input used for bounty logic.
ML Service
FastAPI pothole detection service.
- YOLO Service · Image analysis microservice for pothole detection.
FastAPI/main.py
Connections 19
- 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.