# nouhaghram/binagreen architecture

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

- Interactive diagram: https://gitdiagram.com/nouhaghram/binagreen
- Repository: https://github.com/nouhaghram/binagreen

## Overview

BinaGreen is a Grand Tunis recycling-listing application: a user publishes recyclable material with a quantity, district, and pickup slot; collectors browse nearby listings on a map, reserve them, and listings move through reservation and collection statuses. The API validates and persists listings, while shared client state refreshes data from it. The map uses OpenStreetMap tiles. The README is a generic Next.js template, so it documents no additional product capabilities; unsampled page behavior and relationships are represented cautiously.

Main entry points: [`context/BinaContext.tsx`](https://github.com/nouhaghram/binagreen/blob/main/context/BinaContext.tsx) (Shared listing state), [`app/api/listings/route.ts`](https://github.com/nouhaghram/binagreen/blob/main/app/api/listings/route.ts) (Listings API), [`lib/listings.ts`](https://github.com/nouhaghram/binagreen/blob/main/lib/listings.ts) (Listing validation and mapping), [`app/pickups/page.tsx`](https://github.com/nouhaghram/binagreen/blob/main/app/pickups/page.tsx) (Browse pickups)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_home["Home<br/>[page.tsx]"]
  node_publish["Publish listing<br/>[page.tsx]"]
  node_pickups["Browse pickups<br/>[page.tsx]"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_materials_page["Materials guide<br/>[page.tsx]"]
  node_howto["How it works<br/>[page.tsx]"]
  node_help["Help<br/>[page.tsx]"]
  node_shell["App shell<br/>[layout.tsx]"]
  node_header["Header<br/>[Header.tsx]"]
  node_footer["Footer<br/>[Footer.tsx]"]
  node_map["Listings map<br/>[ListingsMap.tsx]"]
  node_status_badge["Status badge<br/>[StatusBadge.tsx]"]
end

subgraph group_workflow["Listing workflow"]
  node_client_state["Shared listing state<br/>[BinaContext.tsx]"]
  node_listings_api["Listings API<br/>[route.ts]"]
  node_listing_actions["Listing actions API<br/>[route.ts]"]
end

subgraph group_domain["Domain services"]
  node_listing_domain["Listing validation and mapping<br/>[listings.ts]"]
  node_material_rates["Material rates<br/>[materials.ts]"]
  node_geography["Geographic calculations<br/>[geo.ts]"]
  node_listing_types["Listing data types<br/>[types.ts]"]
end

subgraph group_persistence["Persistence"]
  node_db_pool["Database connection pool<br/>[db.ts]"]
  node_listing_store[("Listings database<br/>[schema.sql]")]
end

node_visitor(("User"))
node_tiles["OpenStreetMap tiles"]

node_visitor -->|"browses"| node_home
node_visitor -->|"publishes"| node_publish
node_visitor -->|"finds pickups"| node_pickups
node_visitor -->|"manages listings"| node_dashboard
node_shell -->|"renders"| node_header
node_shell -->|"renders"| node_footer
node_shell -->|"provides state"| node_client_state
node_dashboard -->|"uses state"| node_client_state
node_dashboard -->|"renders status"| node_status_badge
node_publish -->|"adds listing"| node_client_state
node_publish -->|"reads rates"| node_material_rates
node_pickups -->|"reads and books"| node_client_state
node_pickups -->|"reads materials"| node_material_rates
node_pickups -->|"renders filtered listings"| node_map
node_map -->|"loads tiles"| node_tiles
node_map -->|"uses reference point"| node_geography
node_client_state -->|"fetches listings"| node_listings_api
node_client_state -->|"sends actions"| node_listing_actions
node_client_state -->|"calculates distance"| node_geography
node_listings_api -->|"validates and maps"| node_listing_domain
node_listings_api -->|"calculates gain"| node_material_rates
node_listings_api -->|"jitter coordinates"| node_geography
node_listing_actions -->|"maps listing"| node_listing_domain
node_listings_api -->|"queries"| node_db_pool
node_listing_actions -->|"updates listings"| node_db_pool
node_listing_domain -->|"uses rates"| node_material_rates
node_listing_domain -->|"uses districts"| node_geography
node_listing_domain -->|"uses types"| node_listing_types
node_db_pool -.->|"connects to"| node_listing_store

click node_home "https://github.com/nouhaghram/binagreen/blob/main/app/page.tsx"
click node_publish "https://github.com/nouhaghram/binagreen/blob/main/app/publish/page.tsx"
click node_pickups "https://github.com/nouhaghram/binagreen/blob/main/app/pickups/page.tsx"
click node_dashboard "https://github.com/nouhaghram/binagreen/blob/main/app/dashboard/page.tsx"
click node_materials_page "https://github.com/nouhaghram/binagreen/blob/main/app/materials/page.tsx"
click node_howto "https://github.com/nouhaghram/binagreen/blob/main/app/how-it-works/page.tsx"
click node_help "https://github.com/nouhaghram/binagreen/blob/main/app/help/page.tsx"
click node_shell "https://github.com/nouhaghram/binagreen/blob/main/app/layout.tsx"
click node_header "https://github.com/nouhaghram/binagreen/blob/main/components/Header.tsx"
click node_footer "https://github.com/nouhaghram/binagreen/blob/main/components/Footer.tsx"
click node_map "https://github.com/nouhaghram/binagreen/blob/main/components/ListingsMap.tsx"
click node_status_badge "https://github.com/nouhaghram/binagreen/blob/main/components/StatusBadge.tsx"
click node_client_state "https://github.com/nouhaghram/binagreen/blob/main/context/BinaContext.tsx"
click node_listings_api "https://github.com/nouhaghram/binagreen/blob/main/app/api/listings/route.ts"
click node_listing_actions "https://github.com/nouhaghram/binagreen/blob/main/app/api/listings/%5Bid%5D/route.ts"
click node_listing_domain "https://github.com/nouhaghram/binagreen/blob/main/lib/listings.ts"
click node_material_rates "https://github.com/nouhaghram/binagreen/blob/main/lib/materials.ts"
click node_geography "https://github.com/nouhaghram/binagreen/blob/main/lib/geo.ts"
click node_listing_types "https://github.com/nouhaghram/binagreen/blob/main/lib/types.ts"
click node_db_pool "https://github.com/nouhaghram/binagreen/blob/main/lib/db.ts"
click node_listing_store "https://github.com/nouhaghram/binagreen/blob/main/db/schema.sql"

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_home,node_publish,node_pickups,node_dashboard,node_materials_page,node_howto,node_help,node_shell,node_header,node_footer,node_map,node_status_badge,node_visitor toneBlue
class node_client_state,node_listings_api,node_listing_actions toneAmber
class node_listing_domain,node_material_rates,node_geography,node_listing_types toneMint
class node_db_pool,node_listing_store toneRose
class node_tiles toneIndigo
```

## Components

### User experience

- [Home](https://github.com/nouhaghram/binagreen/blob/main/app/page.tsx): `app/page.tsx`
- [Publish listing](https://github.com/nouhaghram/binagreen/blob/main/app/publish/page.tsx): `app/publish/page.tsx`
- [Browse pickups](https://github.com/nouhaghram/binagreen/blob/main/app/pickups/page.tsx): `app/pickups/page.tsx`
- [Dashboard](https://github.com/nouhaghram/binagreen/blob/main/app/dashboard/page.tsx): `app/dashboard/page.tsx`
- [Materials guide](https://github.com/nouhaghram/binagreen/blob/main/app/materials/page.tsx): `app/materials/page.tsx`
- [How it works](https://github.com/nouhaghram/binagreen/blob/main/app/how-it-works/page.tsx): `app/how-it-works/page.tsx`
- [Help](https://github.com/nouhaghram/binagreen/blob/main/app/help/page.tsx): `app/help/page.tsx`
- [App shell](https://github.com/nouhaghram/binagreen/blob/main/app/layout.tsx): `app/layout.tsx`
- [Header](https://github.com/nouhaghram/binagreen/blob/main/components/Header.tsx): `components/Header.tsx`
- [Footer](https://github.com/nouhaghram/binagreen/blob/main/components/Footer.tsx): `components/Footer.tsx`
- [Listings map](https://github.com/nouhaghram/binagreen/blob/main/components/ListingsMap.tsx): `components/ListingsMap.tsx`
- [Status badge](https://github.com/nouhaghram/binagreen/blob/main/components/StatusBadge.tsx): `components/StatusBadge.tsx`

### Listing workflow

- [Shared listing state](https://github.com/nouhaghram/binagreen/blob/main/context/BinaContext.tsx): `context/BinaContext.tsx`
- [Listings API](https://github.com/nouhaghram/binagreen/blob/main/app/api/listings/route.ts): `app/api/listings/route.ts`
- [Listing actions API](https://github.com/nouhaghram/binagreen/blob/main/app/api/listings/%5Bid%5D/route.ts): `app/api/listings/[id]/route.ts`

### Domain services

- [Listing validation and mapping](https://github.com/nouhaghram/binagreen/blob/main/lib/listings.ts): `lib/listings.ts`
- [Material rates](https://github.com/nouhaghram/binagreen/blob/main/lib/materials.ts): `lib/materials.ts`
- [Geographic calculations](https://github.com/nouhaghram/binagreen/blob/main/lib/geo.ts): `lib/geo.ts`
- [Listing data types](https://github.com/nouhaghram/binagreen/blob/main/lib/types.ts): `lib/types.ts`

### Persistence

- [Database connection pool](https://github.com/nouhaghram/binagreen/blob/main/lib/db.ts): `lib/db.ts`
- [Listings database](https://github.com/nouhaghram/binagreen/blob/main/db/schema.sql): `db/schema.sql`

### Other components

- **User**
- **OpenStreetMap tiles**

## Connections

- User → Home: browses
- User → Publish listing: publishes
- User → Browse pickups: finds pickups
- User → Dashboard: manages listings
- App shell → Header: renders (evidence: `app/layout.tsx`)
- App shell → Footer: renders (evidence: `app/layout.tsx`)
- App shell → Shared listing state: provides state (evidence: `app/layout.tsx`)
- Dashboard → Shared listing state: uses state (evidence: `app/dashboard/page.tsx`)
- Dashboard → Status badge: renders status (evidence: `app/dashboard/page.tsx`)
- Publish listing → Shared listing state: adds listing (evidence: `app/publish/page.tsx`)
- Publish listing → Material rates: reads rates (evidence: `app/publish/page.tsx`)
- Browse pickups → Shared listing state: reads and books (evidence: `app/pickups/page.tsx`)
- Browse pickups → Material rates: reads materials (evidence: `app/pickups/page.tsx`)
- Browse pickups → Listings map: renders filtered listings (evidence: `app/pickups/page.tsx`)
- Listings map → OpenStreetMap tiles: loads tiles (evidence: `components/ListingsMap.tsx`)
- Listings map → Geographic calculations: uses reference point (evidence: `components/ListingsMap.tsx`)
- Shared listing state → Listings API: fetches listings (evidence: `context/BinaContext.tsx`)
- Shared listing state → Listing actions API: sends actions (evidence: `context/BinaContext.tsx`)
- Shared listing state → Geographic calculations: calculates distance (evidence: `context/BinaContext.tsx`)
- Listings API → Listing validation and mapping: validates and maps (evidence: `app/api/listings/route.ts`)
- Listings API → Material rates: calculates gain (evidence: `app/api/listings/route.ts`)
- Listings API → Geographic calculations: jitter coordinates (evidence: `app/api/listings/route.ts`)
- Listing actions API → Listing validation and mapping: maps listing (evidence: `app/api/listings/[id]/route.ts`)
- Listings API → Database connection pool: queries (evidence: `app/api/listings/route.ts`)
- Listing actions API → Database connection pool: updates listings (evidence: `app/api/listings/[id]/route.ts`)
- Listing validation and mapping → Material rates: uses rates (evidence: `lib/listings.ts`)
- Listing validation and mapping → Geographic calculations: uses districts (evidence: `lib/listings.ts`)
- Listing validation and mapping → Listing data types: uses types (evidence: `lib/listings.ts`)
- Database connection pool → Listings database: connects to
