How leonardo2020-col/business-map-app works
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: server.js API server · App.jsx Root app · ProtectedRoute.jsx Route guards · users.js Admin users
Components 22
Frontend
React/Vite single-page application
- App shell · Bootstraps the browser SPA and top-level routing
frontend/src/main.jsx - Root app · Hosts global layout and application composition
frontend/src/App.jsx - Auth context · Centralizes login state and auth-aware UI data
frontend/src/contexts/AuthContext.jsx - Route guards · Separates public and protected client routes
frontend/src/components/ProtectedRoute.jsx - Login flow · Unauthenticated entry and password reset screens
frontend/src/components/Login/Login.jsx - Business UI · Business listing, editing, and dashboard views
frontend/src/pages/BusinessesPage.jsx - User admin · User management and permission editing console
frontend/src/pages/UserManagement.jsx - Map tools · Map display and location picking workflow
frontend/src/pages/MapPage.jsx - Status screens · Profile, service status, and reporting views
frontend/src/components/ServicesStatus/ServicesStatus.jsx - API client · Central frontend boundary for backend requests
frontend/src/services/api.js - Feature hooks · Encapsulate business, filter, permission, and admin state
frontend/src/hooks/useBusinesses.js - Geo utils · Shared geospatial calculations and formatting
frontend/src/utils/geospatialUtils.js
Backend
Node.js API and data layer
- API server · Wires config, middleware, routes, and server startup
backend/src/server.js - DB config · Connection and database initialization logic
backend/src/config/database.js - Auth route · Handles login and session-related requests
backend/src/routes/auth.js - Business route · Serves business record operations
backend/src/routes/businesses.js - User route · Serves general user operations
backend/src/routes/users.js - Admin users · Admin-only user management endpoints
backend/src/routes/admin/users.js - Auth middleware · Protects authenticated backend endpoints
backend/src/middleware/auth.js - Permission guard · Enforces elevated access for privileged actions
backend/src/middleware/permissions.js - Domain models · User and business persistence objects
backend/src/models/User.js - DB scripts · Setup, reset, and seed routines for the database
backend/scripts/setupDatabase.js
Connections 27
- 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