# leonardo2020-col/business-map-app architecture

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

- Interactive diagram: https://gitdiagram.com/leonardo2020-col/business-map-app
- Repository: https://github.com/leonardo2020-col/business-map-app

## Overview

1. This repository is a two-part application: a Node.js backend in `backend/` and a React/Vite frontend in `frontend/`. The frontend is the user-facing shell; the backend provides the data and authorization API.

2. The backend entrypoint is `backend/src/server.js`. It wires together configuration, middleware, and route modules, then starts the API server. The structure is layered in the usual API shape: config → middleware → routes → models.

3. The backend data layer is centered on `backend/src/models/User.js` and `backend/src/models/Business.js`, with connection/setup logic in `backend/src/config/database.js`. The presence of `scripts/setupDatabase.js`, `resetDatabase.js`, and `createUsers.js` indicates database bootstrap and admin-seeding are part of the operational model.

4. Authentication and authorization are explicit backend boundaries. `backend/src/routes/auth.js` handles login/session-related API traffic, `backend/src/middleware/auth.js` protects authenticated endpoints, and `backend/src/middleware/permissions.js` enforces role/permission checks for higher-privilege actions.

5. The main backend domain APIs are split by concern: `routes/businesses.js` for business records, `routes/users.js` for general user operations, and `routes/admin/users.js` for admin-only user management. That separation suggests the API distinguishes normal user workflows from privileged administration workflows.

6. The frontend is a SPA built with React and Vite. `frontend/src/main.jsx` and `frontend/src/App.jsx` are the root application entry points, with styling organized through component-level CSS plus shared styles under `src/styles/` and `src/index.css`.

7. Frontend authentication state is managed in `frontend/src/contexts/AuthContext.jsx`, with route guards in `ProtectedRoute.jsx` and `PublicRoute.jsx`. Login and password reset are separate UI flows (`components/Login`, `components/PasswordReset`), indicating the app has both authenticated and unauthenticated surface areas.

8. Business management is a major frontend feature. `pages/BusinessesPage.jsx` and components like `BusinessForm`, `BusinessTable`, and `Dashboard` point to a CRUD-oriented workflow around business records, likely including listing, editing, filtering, and summary views.

9. User administration is another first-class subsystem. `pages/UserManagement.jsx`, `components/UserManagement`, and `UserPermissionsEditor.jsx` map to the backend’s admin/user routes and permission middleware, forming the admin console path for managing users and access.

10. Map and geospatial functionality are isolated into their own frontend subtree: `components/GoogleMapComponent`, `components/Map`, `pages/MapPage.jsx`, and utilities in `utils/geospatialUtils.js`. This likely integrates an external Google Maps-style service and supports location picking/display for business data.

11. The frontend’s server boundary is centralized through `frontend/src/config/api.js` and `frontend/src/services/api.js`. Feature hooks such as `useBusinesses`, `useFilters`, `usePermissions`, and `useUserManagement` sit above that service layer and encapsulate API calls plus UI state.

12. Additional operational/status screens exist for internal visibility: `ServicesStatus`, `SystemReports`, and `Profile`. These components suggest the app includes health/status reporting and account self-service beyond the core CRUD flows.

13. The repository also includes several developer-only scripts (`check-*.js`, `debug-*.js`, `test-login.js`, `migrate-services.js`) used to verify imports, relationships, auth behavior, and structural consistency. These are tooling/support artifacts, not runtime architecture.

14. For an architecture diagram, the key boundaries are: browser SPA → frontend service layer → backend REST API → database/models, with auth/permissions gating most protected operations and map/geospatial calls isolated to the location-related UI.

Main entry points: [`backend/src/server.js`](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/server.js) (API server), [`frontend/src/App.jsx`](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/App.jsx) (Root app), [`frontend/src/components/ProtectedRoute.jsx`](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/components/ProtectedRoute.jsx) (Route guards), [`backend/src/routes/admin/users.js`](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/admin/users.js) (Admin users)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_entry["App shell<br/>React/Vite entry<br/>[main.jsx]"]
  node_frontend_root["Root app<br/>React composition<br/>[App.jsx]"]
  node_frontend_auth(("Auth context<br/>session state<br/>[AuthContext.jsx]"))
  node_frontend_routes["Route guards<br/>access control<br/>[ProtectedRoute.jsx]"]
  node_frontend_login["Login flow<br/>auth UI<br/>[Login.jsx]"]
  node_frontend_businesses["Business UI<br/>CRUD screens<br/>[BusinessesPage.jsx]"]
  node_frontend_user_admin["User admin<br/>admin UI<br/>[UserManagement.jsx]"]
  node_frontend_map["Map tools<br/>geo UI<br/>[MapPage.jsx]"]
  node_frontend_ops["Status screens<br/>support UI<br/>[ServicesStatus.jsx]"]
  node_frontend_api["API client<br/>service layer<br/>[api.js]"]
  node_frontend_hooks["Feature hooks<br/>ui data hooks<br/>[useBusinesses.js]"]
  node_frontend_geo_utils["Geo utils<br/>location helpers<br/>[geospatialUtils.js]"]
end

subgraph group_backend["Backend"]
  node_backend_server["API server<br/>Node entrypoint<br/>[server.js]"]
  node_backend_config[("DB config<br/>database setup<br/>[database.js]")]
  node_backend_auth["Auth route<br/>login API<br/>[auth.js]"]
  node_backend_businesses["Business route<br/>business API<br/>[businesses.js]"]
  node_backend_users["User route<br/>user API<br/>[users.js]"]
  node_backend_admin_users["Admin users<br/>admin API<br/>[users.js]"]
  node_backend_auth_mw["Auth middleware<br/>request guard<br/>[auth.js]"]
  node_backend_perm_mw["Permission guard<br/>role checks<br/>[permissions.js]"]
  node_backend_models[("Domain models<br/>data models<br/>[User.js]")]
  node_backend_scripts["DB scripts<br/>ops tooling<br/>[setupDatabase.js]"]
end

node_frontend_entry -->|"renders"| node_frontend_root
node_frontend_root -->|"uses"| node_frontend_auth
node_frontend_root -->|"wraps"| node_frontend_routes
node_frontend_routes -->|"allows"| node_frontend_login
node_frontend_routes -->|"protects"| node_frontend_businesses
node_frontend_routes -->|"protects"| node_frontend_user_admin
node_frontend_root -->|"includes"| node_frontend_map
node_frontend_root -->|"includes"| node_frontend_ops
node_frontend_businesses -->|"loads"| node_frontend_hooks
node_frontend_user_admin -->|"loads"| node_frontend_hooks
node_frontend_map -->|"uses"| node_frontend_geo_utils
node_frontend_hooks -->|"calls"| node_frontend_api
node_frontend_api -->|"requests"| node_backend_server
node_backend_server -->|"connects"| node_backend_config
node_backend_server -->|"routes"| node_backend_auth
node_backend_server -->|"routes"| node_backend_businesses
node_backend_server -->|"routes"| node_backend_users
node_backend_server -->|"routes"| node_backend_admin_users
node_backend_businesses -->|"guards"| node_backend_auth_mw
node_backend_users -->|"guards"| node_backend_auth_mw
node_backend_admin_users -->|"guards"| node_backend_auth_mw
node_backend_admin_users -->|"guards"| node_backend_perm_mw
node_backend_auth -->|"reads"| node_backend_models
node_backend_businesses -->|"reads"| node_backend_models
node_backend_users -->|"reads"| node_backend_models
node_backend_admin_users -->|"reads"| node_backend_models
node_backend_scripts -->|"initializes"| node_backend_config

click node_frontend_entry "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/main.jsx"
click node_frontend_root "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/App.jsx"
click node_frontend_auth "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/contexts/AuthContext.jsx"
click node_frontend_routes "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/components/ProtectedRoute.jsx"
click node_frontend_login "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/components/Login/Login.jsx"
click node_frontend_businesses "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/pages/BusinessesPage.jsx"
click node_frontend_user_admin "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/pages/UserManagement.jsx"
click node_frontend_map "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/pages/MapPage.jsx"
click node_frontend_ops "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/components/ServicesStatus/ServicesStatus.jsx"
click node_frontend_api "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/services/api.js"
click node_frontend_hooks "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/hooks/useBusinesses.js"
click node_frontend_geo_utils "https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/utils/geospatialUtils.js"
click node_backend_server "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/server.js"
click node_backend_config "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/config/database.js"
click node_backend_auth "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/auth.js"
click node_backend_businesses "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/businesses.js"
click node_backend_users "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/users.js"
click node_backend_admin_users "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/admin/users.js"
click node_backend_auth_mw "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/middleware/auth.js"
click node_backend_perm_mw "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/middleware/permissions.js"
click node_backend_models "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/models/User.js"
click node_backend_scripts "https://github.com/leonardo2020-col/business-map-app/blob/main/backend/scripts/setupDatabase.js"

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_entry,node_frontend_root,node_frontend_auth,node_frontend_routes,node_frontend_login,node_frontend_businesses,node_frontend_user_admin,node_frontend_map,node_frontend_ops,node_frontend_api,node_frontend_hooks,node_frontend_geo_utils toneBlue
class node_backend_server,node_backend_config,node_backend_auth,node_backend_businesses,node_backend_users,node_backend_admin_users,node_backend_auth_mw,node_backend_perm_mw,node_backend_models,node_backend_scripts toneAmber
```

## Components

### Frontend

React/Vite single-page application

- [App shell](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/main.jsx): React/Vite entry · Bootstraps the browser SPA and top-level routing · `frontend/src/main.jsx`
- [Root app](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/App.jsx): React composition · Hosts global layout and application composition · `frontend/src/App.jsx`
- [Auth context](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/contexts/AuthContext.jsx): session state · Centralizes login state and auth-aware UI data · `frontend/src/contexts/AuthContext.jsx`
- [Route guards](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/components/ProtectedRoute.jsx): access control · Separates public and protected client routes · `frontend/src/components/ProtectedRoute.jsx`
- [Login flow](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/components/Login/Login.jsx): auth UI · Unauthenticated entry and password reset screens · `frontend/src/components/Login/Login.jsx`
- [Business UI](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/pages/BusinessesPage.jsx): CRUD screens · Business listing, editing, and dashboard views · `frontend/src/pages/BusinessesPage.jsx`
- [User admin](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/pages/UserManagement.jsx): admin UI · User management and permission editing console · `frontend/src/pages/UserManagement.jsx`
- [Map tools](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/pages/MapPage.jsx): geo UI · Map display and location picking workflow · `frontend/src/pages/MapPage.jsx`
- [Status screens](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/components/ServicesStatus/ServicesStatus.jsx): support UI · Profile, service status, and reporting views · `frontend/src/components/ServicesStatus/ServicesStatus.jsx`
- [API client](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/services/api.js): service layer · Central frontend boundary for backend requests · `frontend/src/services/api.js`
- [Feature hooks](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/hooks/useBusinesses.js): ui data hooks · Encapsulate business, filter, permission, and admin state · `frontend/src/hooks/useBusinesses.js`
- [Geo utils](https://github.com/leonardo2020-col/business-map-app/blob/main/frontend/src/utils/geospatialUtils.js): location helpers · Shared geospatial calculations and formatting · `frontend/src/utils/geospatialUtils.js`

### Backend

Node.js API and data layer

- [API server](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/server.js): Node entrypoint · Wires config, middleware, routes, and server startup · `backend/src/server.js`
- [DB config](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/config/database.js): database setup · Connection and database initialization logic · `backend/src/config/database.js`
- [Auth route](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/auth.js): login API · Handles login and session-related requests · `backend/src/routes/auth.js`
- [Business route](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/businesses.js): business API · Serves business record operations · `backend/src/routes/businesses.js`
- [User route](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/users.js): user API · Serves general user operations · `backend/src/routes/users.js`
- [Admin users](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/routes/admin/users.js): admin API · Admin-only user management endpoints · `backend/src/routes/admin/users.js`
- [Auth middleware](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/middleware/auth.js): request guard · Protects authenticated backend endpoints · `backend/src/middleware/auth.js`
- [Permission guard](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/middleware/permissions.js): role checks · Enforces elevated access for privileged actions · `backend/src/middleware/permissions.js`
- [Domain models](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/src/models/User.js): data models · User and business persistence objects · `backend/src/models/User.js`
- [DB scripts](https://github.com/leonardo2020-col/business-map-app/blob/main/backend/scripts/setupDatabase.js): ops tooling · Setup, reset, and seed routines for the database · `backend/scripts/setupDatabase.js`

## Connections

- App shell → Root app: renders · Application bootstrap mounts the root app
- Root app → Auth context: uses · Root app consumes auth session state
- Root app → Route guards: wraps · Route composition applies public/protected gating
- Route guards → Login flow: allows · Public surface exposes login and reset flows
- Route guards → Business UI: protects · Authenticated surface includes business management
- Route guards → User admin: protects · Authenticated surface includes user administration
- Root app → Map tools: includes · Application shell exposes map workflow
- Root app → Status screens: includes · Application shell exposes status and profile views
- Business UI → Feature hooks: loads · Business screens use feature hooks for data and UI state
- User admin → Feature hooks: loads · Admin screens use user-management hooks
- Map tools → Geo utils: uses · Map UI relies on geospatial helpers
- Feature hooks → API client: calls · Feature hooks delegate network access to the API client
- API client → API server: requests · Frontend service layer talks to the backend REST API
- API server → DB config: connects · Server initializes database access through config
- API server → Auth route: routes · Server exposes authentication endpoints
- API server → Business route: routes · Server exposes business endpoints
- API server → User route: routes · Server exposes general user endpoints
- API server → Admin users: routes · Server exposes admin-only user endpoints
- Business route → Auth middleware: guards · Protected business operations require authentication
- User route → Auth middleware: guards · User operations require authentication
- Admin users → Auth middleware: guards · Admin endpoints require authenticated callers
- Admin users → Permission guard: guards · Admin endpoints add permission checks
- Auth route → Domain models: reads · Auth flow uses user persistence data
- Business route → Domain models: reads · Business API uses business and user models
- User route → Domain models: reads · User API uses user model data
- Admin users → Domain models: reads · Admin user management updates user records
- DB scripts → DB config: initializes · Database scripts bootstrap and reset schema state
