# dhanush0959/fyndly architecture

> Architecture diagram of the GitHub repository dhanush0959/fyndly, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhanush0959/fyndly
- Repository: https://github.com/dhanush0959/fyndly

## Overview

1. **Overall shape**
   Fyndly is a Next.js App Router application with a clear split between **UI pages/components**, **serverless API routes**, and a **MongoDB persistence layer**. The browser talks to local API endpoints; those routes own authentication, item CRUD, chat, and AI-assisted enrichment.

2. **Presentation layer**
   The user-facing routes live in `src/app`: landing page, dashboard, gallery, chat, register, report-lost, and report-found. These pages are mostly thin containers that render reusable components from `src/components` such as `Login`, `Register`, `Dashboard`, `Gallery`, `FoundForm`, `LostForm`, and `Chat`.

3. **Design system and styling**
   Styling is intentionally centralized through `src/app/globals.css` plus component-specific CSS files in `src/components/styles`. The repo leans on custom CSS rather than a component library, which makes the visual system a first-class architectural concern, especially for the dark glassmorphism UI described in the README.

4. **Authentication boundary**
   Authentication is handled through API routes under `src/app/api/auth`, including NextAuth integration at `[...nextauth]` and explicit `login` / `register` endpoints. `middleware.js` suggests route-level protection or session gating for private areas such as dashboard and chat. This makes auth a cross-cutting boundary around both UI and API access.

5. **Core domain data model**
   The main persisted entities are defined in `src/models`: `User`, `LostItem`, `FoundItem`, and `Message`. These models represent the two-sided lost-and-found workflow plus the messaging layer between matched parties. The architecture is centered on these records rather than on a single generic “post” abstraction.

6. **Lost/found item workflow**
   The item-reporting flow is exposed through `src/app/api/lost`, `src/app/api/found`, and the more specific `api/items/lost` and `api/items/found` routes. The UI pages `report-lost` and `report-found` collect submissions, which are then stored as domain records and later surfaced in the gallery/dashboard. This creates a two-entry ingestion path for lost vs. found reports.

7. **AI enrichment and matching**
   `src/lib/ai-service.js` is the AI integration boundary. Based on the README, it likely analyzes uploaded images to extract item keywords, colors, and descriptive text, then helps compare found items against existing lost items. Architecturally, this is a server-side enrichment step that sits between item submission and persistence/matching logic.

8. **Chat subsystem**
   Real-time communication is modeled as a separate subsystem with API endpoints for conversations, message history by user ID, and sending messages. `src/models/Message.js` supports that backend. The `Chat` component and chat page are the UI counterpart, likely used after a match is identified or manually initiated.

9. **Dashboard and gallery as aggregation views**
   `Dashboard` and `Gallery` are read-heavy surfaces that combine multiple domain records into user-friendly summaries. They likely consume the lost/found collections, match status, and possibly chat activity through API calls rather than direct database access, keeping the UI decoupled from storage details.

10. **Server-side infrastructure**
   `src/lib/db.js` is the database connection boundary, likely encapsulating MongoDB/Mongoose connection reuse for serverless execution. This is important in a Next.js deployment because API routes may spin up independently and need a shared connection strategy. The app is therefore designed around stateless route handlers backed by a managed database.

11. **Request flow at a high level**
   A typical flow is: user authenticates, submits a lost/found report through a page component, the request hits an API route, the server may call the AI service, then the corresponding Mongoose model persists data in MongoDB. Matching results can then surface in dashboard/gallery and lead into the chat subsystem for coordination.

12. **Deployment/runtime implications**
   The repo is built for Next.js serverless-style deployment rather than a custom long-running backend. That means the key architectural boundaries are the App Router page layer, API route layer, and MongoDB-backed model layer, with middleware handling access control before requests reach protected surfaces.

Main entry points: [`src/app/api/lost/route.js`](https://github.com/dhanush0959/fyndly/blob/main/src/app/api/lost/route.js) (Item API), [`src/app/layout.js`](https://github.com/dhanush0959/fyndly/blob/main/src/app/layout.js) (App Shell), [`src/app/api/auth/[...nextauth]/route.js`](https://github.com/dhanush0959/fyndly/blob/main/src/app/api/auth/[...nextauth]/route.js) (Auth API), [`src/app/api/chat/conversations/route.js`](https://github.com/dhanush0959/fyndly/blob/main/src/app/api/chat/conversations/route.js) (Chat API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_app_root["Home<br/>page<br/>[page.js]"]
  node_app_dashboard["Dashboard<br/>page<br/>[page.js]"]
  node_app_gallery["Gallery<br/>page<br/>[page.js]"]
  node_app_chat["Chat<br/>page<br/>[page.js]"]
  node_app_register["Register<br/>page<br/>[page.js]"]
  node_app_report_lost["Report Lost<br/>page<br/>[page.js]"]
  node_app_report_found["Report Found<br/>page<br/>[page.js]"]
  node_ui_auth["Auth Forms<br/>[Login.js]"]
  node_ui_items["Item Forms<br/>[LostForm.js]"]
  node_ui_views["Views<br/>[Dashboard.js]"]
  node_ui_chat["Chat UI<br/>[Chat.js]"]
end

subgraph group_api["API Layer"]
  node_auth_api["Auth API<br/>route handlers<br/>[route.js]"]
  node_items_api["Item API<br/>route handlers<br/>[route.js]"]
  node_chat_api["Chat API<br/>route handlers<br/>[route.js]"]
end

subgraph group_data["Data Layer"]
  node_user_model["User<br/>mongoose model<br/>[User.js]"]
  node_lost_model["LostItem<br/>mongoose model<br/>[LostItem.js]"]
  node_found_model["FoundItem<br/>mongoose model<br/>[FoundItem.js]"]
  node_message_model["Message<br/>mongoose model<br/>[Message.js]"]
end

subgraph group_infra["Infra"]
  node_app_shell["App Shell<br/>layout<br/>[layout.js]"]
  node_middleware{{"Middleware<br/>access control<br/>[middleware.js]"}}
  node_db[("Mongo Connect<br/>database connector<br/>[db.js]")]
  node_ai_service{{"AI Service<br/>enrichment<br/>[ai-service.js]"}}
end

node_app_root -->|"login entry"| node_ui_auth
node_app_register -->|"register form"| node_ui_auth
node_app_report_lost -->|"lost form"| node_ui_items
node_app_report_found -->|"found form"| node_ui_items
node_app_dashboard -->|"summary UI"| node_ui_views
node_app_gallery -->|"browse UI"| node_ui_views
node_app_chat -->|"messaging UI"| node_ui_chat
node_app_shell -->|"wraps"| node_app_root
node_app_shell -->|"wraps"| node_app_dashboard
node_app_shell -->|"wraps"| node_app_gallery
node_app_shell -->|"wraps"| node_app_chat
node_middleware -.->|"protects"| node_app_dashboard
node_middleware -.->|"protects"| node_app_chat
node_auth_api -->|"accounts"| node_user_model
node_auth_api -->|"connects"| node_db
node_items_api -->|"stores lost"| node_lost_model
node_items_api -->|"stores found"| node_found_model
node_items_api -->|"connects"| node_db
node_items_api -.->|"enriches"| node_ai_service
node_chat_api -->|"stores messages"| node_message_model
node_chat_api -->|"connects"| node_db
node_ui_auth -->|"credentials"| node_auth_api
node_ui_items -->|"submits items"| node_items_api
node_ui_views -->|"loads items"| node_items_api
node_ui_chat -->|"messages"| node_chat_api
node_items_api -.->|"owner link"| node_user_model

click node_app_root "https://github.com/dhanush0959/fyndly/blob/main/src/app/page.js"
click node_app_dashboard "https://github.com/dhanush0959/fyndly/blob/main/src/app/dashboard/page.js"
click node_app_gallery "https://github.com/dhanush0959/fyndly/blob/main/src/app/gallery/page.js"
click node_app_chat "https://github.com/dhanush0959/fyndly/blob/main/src/app/chat/page.js"
click node_app_register "https://github.com/dhanush0959/fyndly/blob/main/src/app/register/page.js"
click node_app_report_lost "https://github.com/dhanush0959/fyndly/blob/main/src/app/report-lost/page.js"
click node_app_report_found "https://github.com/dhanush0959/fyndly/blob/main/src/app/report-found/page.js"
click node_ui_auth "https://github.com/dhanush0959/fyndly/blob/main/src/components/Login.js"
click node_ui_items "https://github.com/dhanush0959/fyndly/blob/main/src/components/LostForm.js"
click node_ui_views "https://github.com/dhanush0959/fyndly/blob/main/src/components/Dashboard.js"
click node_ui_chat "https://github.com/dhanush0959/fyndly/blob/main/src/components/Chat.js"
click node_app_shell "https://github.com/dhanush0959/fyndly/blob/main/src/app/layout.js"
click node_middleware "https://github.com/dhanush0959/fyndly/blob/main/middleware.js"
click node_db "https://github.com/dhanush0959/fyndly/blob/main/src/lib/db.js"
click node_ai_service "https://github.com/dhanush0959/fyndly/blob/main/src/lib/ai-service.js"
click node_auth_api "https://github.com/dhanush0959/fyndly/blob/main/src/app/api/auth/[...nextauth]/route.js"
click node_items_api "https://github.com/dhanush0959/fyndly/blob/main/src/app/api/lost/route.js"
click node_chat_api "https://github.com/dhanush0959/fyndly/blob/main/src/app/api/chat/conversations/route.js"
click node_user_model "https://github.com/dhanush0959/fyndly/blob/main/src/models/User.js"
click node_lost_model "https://github.com/dhanush0959/fyndly/blob/main/src/models/LostItem.js"
click node_found_model "https://github.com/dhanush0959/fyndly/blob/main/src/models/FoundItem.js"
click node_message_model "https://github.com/dhanush0959/fyndly/blob/main/src/models/Message.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_app_root,node_app_dashboard,node_app_gallery,node_app_chat,node_app_register,node_app_report_lost,node_app_report_found,node_ui_auth,node_ui_items,node_ui_views,node_ui_chat toneBlue
class node_auth_api,node_items_api,node_chat_api toneAmber
class node_user_model,node_lost_model,node_found_model,node_message_model toneMint
class node_app_shell,node_middleware,node_db,node_ai_service toneRose
```

## Components

### Presentation

App Router pages and reusable UI components.

- [Home](https://github.com/dhanush0959/fyndly/blob/main/src/app/page.js): page · Landing page route. · `src/app/page.js`
- [Dashboard](https://github.com/dhanush0959/fyndly/blob/main/src/app/dashboard/page.js): page · Authenticated dashboard route. · `src/app/dashboard/page.js`
- [Gallery](https://github.com/dhanush0959/fyndly/blob/main/src/app/gallery/page.js): page · Public browse/search route. · `src/app/gallery/page.js`
- [Chat](https://github.com/dhanush0959/fyndly/blob/main/src/app/chat/page.js): page · Messaging route. · `src/app/chat/page.js`
- [Register](https://github.com/dhanush0959/fyndly/blob/main/src/app/register/page.js): page · Account creation route. · `src/app/register/page.js`
- [Report Lost](https://github.com/dhanush0959/fyndly/blob/main/src/app/report-lost/page.js): page · Lost item submission route. · `src/app/report-lost/page.js`
- [Report Found](https://github.com/dhanush0959/fyndly/blob/main/src/app/report-found/page.js): page · Found item submission route. · `src/app/report-found/page.js`
- [Auth Forms](https://github.com/dhanush0959/fyndly/blob/main/src/components/Login.js): Login and registration UI. · `src/components/Login.js`
- [Item Forms](https://github.com/dhanush0959/fyndly/blob/main/src/components/LostForm.js): Lost and found reporting forms. · `src/components/LostForm.js`
- [Views](https://github.com/dhanush0959/fyndly/blob/main/src/components/Dashboard.js): Dashboard and gallery UI. · `src/components/Dashboard.js`
- [Chat UI](https://github.com/dhanush0959/fyndly/blob/main/src/components/Chat.js): Messaging interface component. · `src/components/Chat.js`

### API Layer

Route handlers for auth, items, chat, and AI-assisted workflows.

- [Auth API](https://github.com/dhanush0959/fyndly/blob/main/src/app/api/auth/[...nextauth]/route.js): route handlers · NextAuth plus login/register endpoints. · `src/app/api/auth/[...nextauth]/route.js`
- [Item API](https://github.com/dhanush0959/fyndly/blob/main/src/app/api/lost/route.js): route handlers · Lost and found item ingestion routes. · `src/app/api/lost/route.js`
- [Chat API](https://github.com/dhanush0959/fyndly/blob/main/src/app/api/chat/conversations/route.js): route handlers · Conversation, history, and send-message routes. · `src/app/api/chat/conversations/route.js`

### Data Layer

MongoDB models for users, items, and messages.

- [User](https://github.com/dhanush0959/fyndly/blob/main/src/models/User.js): mongoose model · Account and session-related user record. · `src/models/User.js`
- [LostItem](https://github.com/dhanush0959/fyndly/blob/main/src/models/LostItem.js): mongoose model · Lost item record. · `src/models/LostItem.js`
- [FoundItem](https://github.com/dhanush0959/fyndly/blob/main/src/models/FoundItem.js): mongoose model · Found item record. · `src/models/FoundItem.js`
- [Message](https://github.com/dhanush0959/fyndly/blob/main/src/models/Message.js): mongoose model · Conversation message record. · `src/models/Message.js`

### Infra

Cross-cutting app shell, middleware, and service boundaries.

- [App Shell](https://github.com/dhanush0959/fyndly/blob/main/src/app/layout.js): layout · Global layout and client providers. · `src/app/layout.js`
- [Middleware](https://github.com/dhanush0959/fyndly/blob/main/middleware.js): access control · Route-level request gating. · `middleware.js`
- [Mongo Connect](https://github.com/dhanush0959/fyndly/blob/main/src/lib/db.js): database connector · Shared database connection helper. · `src/lib/db.js`
- [AI Service](https://github.com/dhanush0959/fyndly/blob/main/src/lib/ai-service.js): enrichment · Server-side image/text enrichment boundary. · `src/lib/ai-service.js`

## Connections

- Home → Auth Forms: login entry · Home routes users into authentication.
- Register → Auth Forms: register form · Registration page renders the auth UI.
- Report Lost → Item Forms: lost form · Lost report page renders the submission form.
- Report Found → Item Forms: found form · Found report page renders the submission form.
- Dashboard → Views: summary UI · Dashboard page renders aggregated views.
- Gallery → Views: browse UI · Gallery page renders item browsing views.
- Chat → Chat UI: messaging UI · Chat page renders the chat interface.
- App Shell → Home: wraps · App shell wraps application routes.
- App Shell → Dashboard: wraps · App shell wraps application routes.
- App Shell → Gallery: wraps · App shell wraps application routes.
- App Shell → Chat: wraps · App shell wraps application routes.
- Middleware → Dashboard: protects · Middleware guards private surfaces.
- Middleware → Chat: protects · Middleware guards private surfaces.
- Auth API → User: accounts · Auth routes create and validate users.
- Auth API → Mongo Connect: connects · Auth handlers use the shared database connection.
- Item API → LostItem: stores lost · Lost item routes persist lost reports.
- Item API → FoundItem: stores found · Found item routes persist found reports.
- Item API → Mongo Connect: connects · Item routes use the shared database connection.
- Item API → AI Service: enriches · Item submission can be analyzed by the AI boundary.
- Chat API → Message: stores messages · Chat routes persist and fetch messages.
- Chat API → Mongo Connect: connects · Chat handlers use the shared database connection.
- Auth Forms → Auth API: credentials · Auth UI submits login and registration requests.
- Item Forms → Item API: submits items · Item forms send lost/found reports to APIs.
- Views → Item API: loads items · Dashboard and gallery read item data from APIs.
- Chat UI → Chat API: messages · Chat UI loads conversations and sends messages.
- Item API → User: owner link · Item records may reference the reporting user.
