# aniket-gawande/mahafort-guide architecture

> Architecture diagram of the GitHub repository aniket-gawande/mahafort-guide, 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/aniket-gawande/mahafort-guide
- Repository: https://github.com/aniket-gawande/mahafort-guide

## Overview

1. **Overall shape**
   - MahaFort is a **two-part application**: a React frontend for the user experience and an optional Node/Express backend for dynamic services.
   - The repo is designed so the **frontend can run standalone** from static fort data, while the backend adds auth, chat, admin, and fort-data services.

2. **Frontend is the primary product surface**
   - `frontend/src/App.js` and the `pages/` directory define the main navigable app: Home, Fort listings, Fort detail pages, Trip Planner, About, Login/Register, Admin.
   - `react-router`-style page routing is implied by the page/component structure and `ProtectedRoute`.

3. **Content/data layer on the frontend**
   - The core fort catalog lives in `frontend/src/data/staticForts.js` and richer per-fort content in `frontend/src/data/fortDetailedData.js`.
   - There are also static JSON assets in `frontend/public/data/` and `frontend/src/data/sinhagad.json`, which suggests some pages can render from local content without backend calls.

4. **UI component layer**
   - Reusable UI is concentrated in `frontend/src/components/`: fort cards, navbar, download/emergency buttons, weather widgets, crowd badges, chatbot, and several fort-specific map components.
   - This is a **presentation-first architecture**: data is passed into these components, which handle the visuals and page-specific interactions.

5. **Fort detail subpages are specialized**
   - The repo includes dedicated detail pages for important forts such as Sinhagad, Lohagad, Murud-Janjira, Sindhudurg, Tung, and Vishalgad.
   - Some forts also have their own map components, which implies **per-destination UX customization** rather than a single generic detail template everywhere.

6. **Interactive experience layer**
   - The app includes widgets for **weather, trip forecasts, crowd status, downloads, and emergency actions**.
   - These are likely layered into detail pages and act as supporting services around the main fort content rather than forming separate subsystems.

7. **Auth and protected areas**
   - `frontend/src/context/AuthContext.js` plus `ProtectedRoute.jsx` indicate client-side authentication state management.
   - The user flows for login, registration, and admin access are isolated from the public browsing experience, with admin pages gated by route protection.

8. **Backend API boundary**
   - The backend is organized as an Express app with route groups for `auth`, `chat`, `forts`, `admin`, `agent`, and `emergency`.
   - `backend/server.js` is the central HTTP entrypoint, while controllers and middleware separate request handling, authorization, and domain logic.

9. **Backend data model and persistence**
   - The backend contains model abstractions for `User`, `FileUser`, and `Fort`, but the repository also ships a large set of JSON data files under `backend/data/forts/` and `backend/data/users.json`.
   - This suggests a **file-backed or hybrid persistence approach**, where fort content may be stored as structured JSON rather than only in a traditional database.

10. **AI/chat subsystem**
   - `backend/controllers/chatController.js`, `backend/services/fortDataAgent.js`, and the `listGeminiModels.js` / `testGemini*.js` files show a dedicated AI integration path.
   - The Bahirji chatbot in the frontend likely talks to this backend layer, which in turn appears to integrate with **Gemini-based model access** for fort guidance and Q&A.

11. **Operational and deployment boundaries**
   - The repo supports separate deployment targets: the frontend has `vercel.json`, while the root build artifacts and `static/` output indicate a prebuilt/static hosting path such as GitHub Pages.
   - In practice, the architecture splits into a **static client delivery layer** and a **runtime backend API layer**, with the chatbot/admin/auth features depending on the backend and the fort browsing experience usable from static data alone.

Main entry points: [`backend/server.js`](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/server.js) (Server), [`frontend/src/pages`](https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/pages) (Pages), [`frontend/src/App.js`](https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/App.js) (App shell), [`frontend/src/services/api.js`](https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/services/api.js) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_client_app["App shell<br/>React SPA<br/>[App.js]"]
  node_client_pages["Pages<br/>Route views"]
  node_client_components["UI components<br/>Reusable widgets"]
  node_client_auth(("Auth state<br/>Client auth<br/>[AuthContext.js]"))
  node_client_api["API client<br/>HTTP client<br/>[api.js]"]
  node_client_data[("Static forts<br/>Local content")]
  node_client_maps["Map views<br/>Fort maps"]
  node_client_chat(("Bahirji bot<br/>Chat UI<br/>[BahirjiChatbot.jsx]"))
  node_client_delivery["Static build<br/>Hosted client"]
end

subgraph group_backend["Backend"]
  node_server_entry["Server<br/>Express app<br/>[server.js]"]
  node_route_auth["Auth routes<br/>API routes<br/>[authRoutes.js]"]
  node_route_forts["Fort routes<br/>API routes<br/>[forts.js]"]
  node_route_chat["Chat routes<br/>API routes<br/>[chatRoutes.js]"]
  node_route_admin["Admin routes<br/>API routes<br/>[admin.js]"]
  node_route_emergency["Emergency routes<br/>API routes<br/>[emergencyRoutes.js]"]
  node_middleware_auth(("Auth guard<br/>Middleware<br/>[auth.js]"))
  node_service_agent["Fort agent<br/>AI service<br/>[fortDataAgent.js]"]
  node_backend_models[("Models")]
  node_backend_files[("File data<br/>JSON store")]
end

subgraph group_data["Data"]
end

node_client_app -->|"routes to"| node_client_pages
node_client_app -->|"composes"| node_client_components
node_client_app -->|"uses"| node_client_auth
node_client_pages -->|"renders from"| node_client_data
node_client_pages -->|"embeds"| node_client_maps
node_client_pages -->|"includes"| node_client_chat
node_client_components -->|"calls"| node_client_api
node_client_chat -->|"messages"| node_client_api
node_client_auth -->|"authenticates via"| node_client_api
node_client_delivery -.->|"hosts"| node_client_app
node_server_entry -->|"mounts"| node_route_auth
node_server_entry -->|"mounts"| node_route_forts
node_server_entry -->|"mounts"| node_route_chat
node_server_entry -->|"mounts"| node_route_admin
node_server_entry -->|"mounts"| node_route_emergency
node_route_auth -->|"protects"| node_middleware_auth
node_route_admin -->|"protects"| node_middleware_auth
node_route_chat -->|"delegates to"| node_service_agent
node_service_agent -->|"reads"| node_backend_files
node_route_forts -->|"reads"| node_backend_files
node_route_auth -->|"uses"| node_backend_models
node_route_admin -->|"uses"| node_backend_models
node_route_forts -->|"uses"| node_backend_models
node_client_api -->|"requests"| node_server_entry

click node_client_app "https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/App.js"
click node_client_pages "https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/pages"
click node_client_components "https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/components"
click node_client_auth "https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/context/AuthContext.js"
click node_client_api "https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/services/api.js"
click node_client_data "https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/data"
click node_client_maps "https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/components"
click node_client_chat "https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/components/BahirjiChatbot.jsx"
click node_client_delivery "https://github.com/aniket-gawande/mahafort-guide/tree/main/static"
click node_server_entry "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/server.js"
click node_route_auth "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/authRoutes.js"
click node_route_forts "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/forts.js"
click node_route_chat "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/chatRoutes.js"
click node_route_admin "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/admin.js"
click node_route_emergency "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/emergencyRoutes.js"
click node_middleware_auth "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/middleware/auth.js"
click node_service_agent "https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/services/fortDataAgent.js"
click node_backend_models "https://github.com/aniket-gawande/mahafort-guide/tree/main/backend/models"
click node_backend_files "https://github.com/aniket-gawande/mahafort-guide/tree/main/backend/data"

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_client_app,node_client_pages,node_client_components,node_client_auth,node_client_api,node_client_data,node_client_maps,node_client_chat,node_client_delivery toneBlue
class node_server_entry,node_route_auth,node_route_forts,node_route_chat,node_route_admin,node_route_emergency,node_middleware_auth,node_service_agent,node_backend_models,node_backend_files toneAmber
```

## Components

### Frontend

React app for browsing forts, planning trips, and user/admin flows.

- [App shell](https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/App.js): React SPA · Main frontend entry and routed application shell. · `frontend/src/App.js`
- [Pages](https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/pages): Route views · Top-level views for home, forts, details, planner, auth, and admin. · `frontend/src/pages`
- [UI components](https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/components): Reusable widgets · Shared presentation components for cards, maps, weather, chat, and actions. · `frontend/src/components`
- [Auth state](https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/context/AuthContext.js): Client auth · Client-side authentication context and protected routing. · `frontend/src/context/AuthContext.js`
- [API client](https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/services/api.js): HTTP client · Frontend service layer for calling backend endpoints. · `frontend/src/services/api.js`
- [Static forts](https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/data): Local content · Primary fort catalog and detailed frontend data used for standalone browsing. · `frontend/src/data`
- [Map views](https://github.com/aniket-gawande/mahafort-guide/tree/main/frontend/src/components): Fort maps · Specialized fort-specific map components embedded in detail pages. · `frontend/src/components`
- [Bahirji bot](https://github.com/aniket-gawande/mahafort-guide/blob/main/frontend/src/components/BahirjiChatbot.jsx): Chat UI · Frontend chatbot experience for fort guidance and assistance. · `frontend/src/components/BahirjiChatbot.jsx`
- [Static build](https://github.com/aniket-gawande/mahafort-guide/tree/main/static): Hosted client · Prebuilt static output used for file hosting or GitHub Pages style delivery. · `static`

### Backend

Express API for auth, chat, fort services, and admin operations.

- [Server](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/server.js): Express app · Backend HTTP entrypoint coordinating all API routes. · `backend/server.js`
- [Auth routes](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/authRoutes.js): API routes · Login, registration, and session-related endpoints. · `backend/routes/authRoutes.js`
- [Fort routes](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/forts.js): API routes · Endpoints for fort content and related lookups. · `backend/routes/forts.js`
- [Chat routes](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/chatRoutes.js): API routes · Chat and assistant endpoints used by the chatbot UI. · `backend/routes/chatRoutes.js`
- [Admin routes](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/admin.js): API routes · Protected admin and management endpoints. · `backend/routes/admin.js`
- [Emergency routes](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/routes/emergencyRoutes.js): API routes · Emergency/support actions exposed by the backend. · `backend/routes/emergencyRoutes.js`
- [Auth guard](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/middleware/auth.js): Middleware · Authorization middleware for protected backend operations. · `backend/middleware/auth.js`
- [Fort agent](https://github.com/aniket-gawande/mahafort-guide/blob/main/backend/services/fortDataAgent.js): AI service · Backend service that assembles fort data and drives model-assisted chat. · `backend/services/fortDataAgent.js`
- [Models](https://github.com/aniket-gawande/mahafort-guide/tree/main/backend/models): Persistence models · User and fort model abstractions used by backend logic. · `backend/models`
- [File data](https://github.com/aniket-gawande/mahafort-guide/tree/main/backend/data): JSON store · Large JSON-backed fort and user data set for hybrid persistence. · `backend/data`

## Connections

- App shell → Pages: routes to · The app shell mounts the main page views.
- App shell → UI components: composes · Pages rely on shared reusable UI.
- App shell → Auth state: uses · Routing and access control depend on client auth state.
- Pages → Static forts: renders from · Public browsing and detail pages can use local fort content.
- Pages → Map views: embeds · Select detail pages include fort-specific map experiences.
- Pages → Bahirji bot: includes · Some views surface the assistant UI.
- UI components → API client: calls · Interactive widgets fetch backend data when needed.
- Bahirji bot → API client: messages · Chat UI sends prompts and receives responses through the API layer.
- Auth state → API client: authenticates via · Login and protected routes depend on backend session or token flows.
- Static build → App shell: hosts · The static build serves the frontend application.
- Server → Auth routes: mounts · Express mounts authentication endpoints.
- Server → Fort routes: mounts · Express mounts fort content endpoints.
- Server → Chat routes: mounts · Express mounts chat endpoints.
- Server → Admin routes: mounts · Express mounts admin endpoints.
- Server → Emergency routes: mounts · Express mounts emergency endpoints.
- Auth routes → Auth guard: protects · Sensitive auth and admin flows are guarded by middleware.
- Admin routes → Auth guard: protects · Admin actions require authorization.
- Chat routes → Fort agent: delegates to · Chat requests flow through the fort data agent.
- Fort agent → File data: reads · AI and content services use JSON fort data.
- Fort routes → File data: reads · Fort endpoints serve file-backed content.
- Auth routes → Models: uses · Authentication logic maps to user models.
- Admin routes → Models: uses · Administrative operations act on backend models.
- Fort routes → Models: uses · Fort domain logic is represented through models.
- API client → Server: requests · Frontend calls the backend API when dynamic services are needed.
