# 1mlm/aui-map architecture

> Architecture diagram of the GitHub repository 1mlm/aui-map, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1mlm/aui-map
- Repository: https://github.com/1mlm/aui-map

## Overview

#### Purpose and Entry Points
AUI Map is a public, interactive campus-map PWA for Al Akhawayn University. The primary public route is `src/app/page.tsx`; global document/UI setup is in `src/app/layout.tsx`. It also exposes an authenticated admin surface under `src/app/admin/(dashboard)/page.tsx` and a share-target endpoint at `src/app/share-target/route.ts`.

#### Public Map Experience
The map is a client-side interactive composition centered on `src/map/MapExperience.tsx` and `src/map/MapCanvas.tsx`. It renders campus pins, supports pan/zoom, search, tag filtering, responsive detail views, directions, and attachment display through components such as `src/map/MapDetailPanel.tsx` and `src/map/AttachmentCarousel.tsx`. Browser-only capabilities—geolocation, compass, wake lock, and install prompts—are isolated in map hooks/components including `src/map/useUserLocation.ts` and `src/map/useCompassHeading.ts`.

#### Map Data Boundary
Server-side map data is assembled by `src/map/getMapData.ts`, transformed into UI map entities by `src/map/mapItemFromDb.ts`, and typed in `src/map/types.ts`. Prisma models and relational constraints are the durable source of truth in `prisma/schema.prisma`, with schema evolution captured under `prisma/migrations/`. This boundary separates database-shaped pins, tags, attachments, links, suggestions, contributions, QR tracking, and panoramas from interactive map state.

#### Community Contributions
Unauthenticated visitors can submit pin suggestions and upload contributed media. Client interactions originate in `src/map/SuggestionForm.tsx`, `src/map/suggestionActions.ts`, and `src/map/contributeActions.ts`; uploads enter via `src/app/api/contribute/upload/route.ts`. These flows persist reviewable records rather than directly changing published map content, creating a moderation boundary before admin approval.

#### Administration and Moderation
The admin App Router area uses dashboard layout and server actions to manage published content and incoming work. Key domains are pins (`src/app/admin/(dashboard)/pins/actions.ts`), tags (`src/app/admin/(dashboard)/tags/actions.ts`), submissions (`src/app/admin/(dashboard)/submissions/actions.ts`), and suggestions (`src/app/admin/(dashboard)/suggestions/actions.ts`). Authentication begins at `src/app/admin/login/actions.ts` and is enforced through `src/utils/requireAuth.ts`.

#### Media and Panorama Pipeline
Admin attachment uploads are handled separately at `src/app/api/admin/attachments/upload/route.ts`; cloud storage integration is encapsulated in `src/utils/cloudinaryUpload.ts` and `src/utils/cloudinary.ts`. The repository also supports placement and viewing/capture of panoramas via `src/app/admin/(dashboard)/panoramas/PanoramaPlacer.tsx`, `src/map/PanoramaLayer.tsx`, and `src/map/panoramaCapture/PanoramaCapture.tsx`.

#### Runtime, Infrastructure, and Offline Delivery
This is a Next.js 16 App Router application running React 19 and TypeScript. PostgreSQL on Neon is accessed through Prisma (`src/utils/prisma.ts`); media infrastructure includes Vercel Blob per the project stack and Cloudinary-oriented utility modules present in the codebase. PWA/offline behavior is delivered by Serwist through `src/app/sw.ts`, `src/app/serwist/[path]/route.ts`, and the offline fallback `src/app/~offline/page.tsx`. Deployment-facing behavior is configured in `next.config.ts` and request mediation is likely centralized in `src/proxy.ts`.

Main entry points: [`src/map/MapExperience.tsx`](https://github.com/1mlm/aui-map/blob/main/src/map/MapExperience.tsx) (Map experience), [`prisma/schema.prisma`](https://github.com/1mlm/aui-map/blob/main/prisma/schema.prisma) (PostgreSQL schema), [`src/app/page.tsx`](https://github.com/1mlm/aui-map/blob/main/src/app/page.tsx) (Public route), [`src/app/admin/(dashboard)/page.tsx`](https://github.com/1mlm/aui-map/blob/main/src/app/admin/(dashboard)/page.tsx) (Admin dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public map"]
  node_public_page["Public route<br/>Next page<br/>[page.tsx]"]
  node_app_layout["Global layout<br/>App shell<br/>[layout.tsx]"]
  node_map_experience["Map experience<br/>Client composition<br/>[MapExperience.tsx]"]
  node_map_canvas["Map canvas<br/>Interactive renderer<br/>[MapCanvas.tsx]"]
  node_map_details["Details &amp; attachments<br/>Map UI<br/>[MapDetailPanel.tsx]"]
  node_browser_capabilities["Location &amp; compass<br/>Browser hooks<br/>[useUserLocation.ts]"]
  node_share_target["Share target<br/>Route handler<br/>[route.ts]"]
end

subgraph group_community["Contributions"]
  node_suggestion_ui["Suggestion form<br/>Client form<br/>[SuggestionForm.tsx]"]
  node_contribution_actions["Contribution actions<br/>Server actions"]
  node_contribution_upload["Contribution upload API<br/>Route handler<br/>[route.ts]"]
end

subgraph group_admin["Admin &amp; media"]
  node_admin_login["Admin login<br/>Auth action<br/>[actions.ts]"]
  node_admin_dashboard["Admin dashboard<br/>Protected page<br/>[page.tsx]"]
  node_admin_actions["Content moderation<br/>Server actions<br/>[actions.ts]"]
  node_admin_upload["Admin attachment API<br/>Route handler<br/>[route.ts]"]
  node_panorama_tools["Panorama tools<br/>Admin &amp; map UI<br/>[PanoramaPlacer.tsx]"]
end

subgraph group_platform["Data &amp; delivery"]
  node_map_data["Map data assembly<br/>Server data boundary<br/>[getMapData.ts]"]
  node_prisma["Prisma access<br/>Database client<br/>[prisma.ts]"]
  node_database[("PostgreSQL schema<br/>Durable data model<br/>[schema.prisma]")]
  node_media_storage["Cloud media<br/>Storage integration"]
  node_offline_delivery["Offline service worker<br/>PWA delivery<br/>[sw.ts]"]
  node_request_proxy["Request proxy<br/>Request mediation<br/>[proxy.ts]"]
end

node_app_layout -->|"wraps"| node_public_page
node_public_page -->|"renders"| node_map_experience
node_map_experience -->|"drives"| node_map_canvas
node_map_experience -->|"shows selected item"| node_map_details
node_map_experience -->|"uses"| node_browser_capabilities
node_map_experience -->|"receives map entities"| node_map_data
node_map_data -->|"queries"| node_prisma
node_prisma -->|"persists"| node_database
node_suggestion_ui -->|"submits"| node_contribution_actions
node_contribution_actions -->|"creates review records"| node_database
node_contribution_upload -->|"uploads media"| node_media_storage
node_contribution_upload -->|"records contribution"| node_database
node_admin_login -->|"authenticates access"| node_admin_dashboard
node_admin_dashboard -->|"manages content"| node_admin_actions
node_admin_actions -->|"moderates and publishes"| node_database
node_admin_upload -->|"uploads attachments"| node_media_storage
node_panorama_tools -->|"stores panorama placement"| node_database
node_panorama_tools -->|"provides panorama view"| node_map_experience
node_offline_delivery -.->|"caches and falls back"| node_public_page
node_request_proxy -.->|"mediates requests"| node_admin_dashboard
node_share_target -->|"shares into map flow"| node_map_experience

click node_public_page "https://github.com/1mlm/aui-map/blob/main/src/app/page.tsx"
click node_app_layout "https://github.com/1mlm/aui-map/blob/main/src/app/layout.tsx"
click node_map_experience "https://github.com/1mlm/aui-map/blob/main/src/map/MapExperience.tsx"
click node_map_canvas "https://github.com/1mlm/aui-map/blob/main/src/map/MapCanvas.tsx"
click node_map_details "https://github.com/1mlm/aui-map/blob/main/src/map/MapDetailPanel.tsx"
click node_browser_capabilities "https://github.com/1mlm/aui-map/blob/main/src/map/useUserLocation.ts"
click node_suggestion_ui "https://github.com/1mlm/aui-map/blob/main/src/map/SuggestionForm.tsx"
click node_contribution_actions "https://github.com/1mlm/aui-map/blob/main/src/map/suggestionActions.ts"
click node_contribution_upload "https://github.com/1mlm/aui-map/blob/main/src/app/api/contribute/upload/route.ts"
click node_admin_login "https://github.com/1mlm/aui-map/blob/main/src/app/admin/login/actions.ts"
click node_admin_dashboard "https://github.com/1mlm/aui-map/blob/main/src/app/admin/(dashboard)/page.tsx"
click node_admin_actions "https://github.com/1mlm/aui-map/blob/main/src/app/admin/(dashboard)/pins/actions.ts"
click node_admin_upload "https://github.com/1mlm/aui-map/blob/main/src/app/api/admin/attachments/upload/route.ts"
click node_panorama_tools "https://github.com/1mlm/aui-map/blob/main/src/app/admin/(dashboard)/panoramas/PanoramaPlacer.tsx"
click node_map_data "https://github.com/1mlm/aui-map/blob/main/src/map/getMapData.ts"
click node_prisma "https://github.com/1mlm/aui-map/blob/main/src/utils/prisma.ts"
click node_database "https://github.com/1mlm/aui-map/blob/main/prisma/schema.prisma"
click node_media_storage "https://github.com/1mlm/aui-map/blob/main/src/utils/cloudinaryUpload.ts"
click node_offline_delivery "https://github.com/1mlm/aui-map/blob/main/src/app/sw.ts"
click node_request_proxy "https://github.com/1mlm/aui-map/blob/main/src/proxy.ts"
click node_share_target "https://github.com/1mlm/aui-map/blob/main/src/app/share-target/route.ts"

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_public_page,node_app_layout,node_map_experience,node_map_canvas,node_map_details,node_browser_capabilities,node_share_target toneBlue
class node_suggestion_ui,node_contribution_actions,node_contribution_upload toneAmber
class node_admin_login,node_admin_dashboard,node_admin_actions,node_admin_upload,node_panorama_tools toneMint
class node_map_data,node_prisma,node_database,node_media_storage,node_offline_delivery,node_request_proxy toneRose
```

## Components

### Public map

- [Public route](https://github.com/1mlm/aui-map/blob/main/src/app/page.tsx): Next page · `src/app/page.tsx`
- [Global layout](https://github.com/1mlm/aui-map/blob/main/src/app/layout.tsx): App shell · `src/app/layout.tsx`
- [Map experience](https://github.com/1mlm/aui-map/blob/main/src/map/MapExperience.tsx): Client composition · Owns interactive map state and responsive views. · `src/map/MapExperience.tsx`
- [Map canvas](https://github.com/1mlm/aui-map/blob/main/src/map/MapCanvas.tsx): Interactive renderer · Renders pins with pan, zoom, search, filters, and directions. · `src/map/MapCanvas.tsx`
- [Details & attachments](https://github.com/1mlm/aui-map/blob/main/src/map/MapDetailPanel.tsx): Map UI · `src/map/MapDetailPanel.tsx`
- [Location & compass](https://github.com/1mlm/aui-map/blob/main/src/map/useUserLocation.ts): Browser hooks · Isolates browser-only location, heading, wake-lock, and install behavior. · `src/map/useUserLocation.ts`
- [Share target](https://github.com/1mlm/aui-map/blob/main/src/app/share-target/route.ts): Route handler · `src/app/share-target/route.ts`

### Contributions

- [Suggestion form](https://github.com/1mlm/aui-map/blob/main/src/map/SuggestionForm.tsx): Client form · `src/map/SuggestionForm.tsx`
- [Contribution actions](https://github.com/1mlm/aui-map/blob/main/src/map/suggestionActions.ts): Server actions · Creates reviewable suggestions and contributed-media records. · `src/map/suggestionActions.ts`
- [Contribution upload API](https://github.com/1mlm/aui-map/blob/main/src/app/api/contribute/upload/route.ts): Route handler · `src/app/api/contribute/upload/route.ts`

### Admin & media

- [Admin login](https://github.com/1mlm/aui-map/blob/main/src/app/admin/login/actions.ts): Auth action · `src/app/admin/login/actions.ts`
- [Admin dashboard](https://github.com/1mlm/aui-map/blob/main/src/app/admin/(dashboard)/page.tsx): Protected page · Moderates incoming work and manages published content. · `src/app/admin/(dashboard)/page.tsx`
- [Content moderation](https://github.com/1mlm/aui-map/blob/main/src/app/admin/(dashboard)/pins/actions.ts): Server actions · Manages pins, tags, submissions, and suggestions. · `src/app/admin/(dashboard)/pins/actions.ts`
- [Admin attachment API](https://github.com/1mlm/aui-map/blob/main/src/app/api/admin/attachments/upload/route.ts): Route handler · `src/app/api/admin/attachments/upload/route.ts`
- [Panorama tools](https://github.com/1mlm/aui-map/blob/main/src/app/admin/(dashboard)/panoramas/PanoramaPlacer.tsx): Admin & map UI · Places, captures, and displays panoramas. · `src/app/admin/(dashboard)/panoramas/PanoramaPlacer.tsx`

### Data & delivery

- [Map data assembly](https://github.com/1mlm/aui-map/blob/main/src/map/getMapData.ts): Server data boundary · Loads database records and maps them to UI entities. · `src/map/getMapData.ts`
- [Prisma access](https://github.com/1mlm/aui-map/blob/main/src/utils/prisma.ts): Database client · `src/utils/prisma.ts`
- [PostgreSQL schema](https://github.com/1mlm/aui-map/blob/main/prisma/schema.prisma): Durable data model · Source of truth for map content, moderation records, media, QR tracking, and panoramas. · `prisma/schema.prisma`
- [Cloud media](https://github.com/1mlm/aui-map/blob/main/src/utils/cloudinaryUpload.ts): Storage integration · `src/utils/cloudinaryUpload.ts`
- [Offline service worker](https://github.com/1mlm/aui-map/blob/main/src/app/sw.ts): PWA delivery · Serves cached PWA behavior and offline fallback. · `src/app/sw.ts`
- [Request proxy](https://github.com/1mlm/aui-map/blob/main/src/proxy.ts): Request mediation · `src/proxy.ts`

## Connections

- Global layout → Public route: wraps
- Public route → Map experience: renders
- Map experience → Map canvas: drives
- Map experience → Details & attachments: shows selected item
- Map experience → Location & compass: uses
- Map experience → Map data assembly: receives map entities
- Map data assembly → Prisma access: queries
- Prisma access → PostgreSQL schema: persists
- Suggestion form → Contribution actions: submits
- Contribution actions → PostgreSQL schema: creates review records
- Contribution upload API → Cloud media: uploads media
- Contribution upload API → PostgreSQL schema: records contribution
- Admin login → Admin dashboard: authenticates access
- Admin dashboard → Content moderation: manages content
- Content moderation → PostgreSQL schema: moderates and publishes
- Admin attachment API → Cloud media: uploads attachments
- Panorama tools → PostgreSQL schema: stores panorama placement
- Panorama tools → Map experience: provides panorama view
- Offline service worker → Public route: caches and falls back
- Request proxy → Admin dashboard: mediates requests
- Share target → Map experience: shares into map flow
