# amr-radwan1/ecofind architecture

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

- Interactive diagram: https://gitdiagram.com/amr-radwan1/ecofind
- Repository: https://github.com/amr-radwan1/ecofind

## Overview

##### Project type and purpose
- Ecofind is a full-stack, serverless web application.
- Frontend: Next.js 13 (App Router) with React/TypeScript and Tailwind CSS.
- Backend services: AWS Amplify (for authentication and any custom Lambdas) and Supabase (Postgres) for data storage.
- External integration: Google Maps JavaScript API for mapping recycling facilities.

##### File structure
- Top-level: configuration files (Dockerfile, buildspec.yaml, next.config.mjs, tsconfig.json, etc.)
- amplify/…: TypeScript definitions for Auth (Cognito) and Data (Lambda/API Gateway) resources.
- src/app/…: React components and page routes (map, sign-in, sign-up, homepage).
- public/: static assets.
- populateDb.js: script to seed Supabase with facility data.

##### README
- Confirms required technologies: Node.js, AWS CLI, Supabase, Google Maps API.

a. Main components
- Client Browser (React UI)
- Next.js Serverless Application
- AWS Amplify –
– Authentication (Cognito)
– Custom Data Lambdas (API Gateway + Lambda)
- Supabase (Postgres Database)
- Google Maps API

b. Relationships & interactions
- User ↔ Browser: interacts with React components (Sign-in, Map, FAQ, etc.)
- Browser → Next.js: fetches pages and invokes any server-side functions in getServerSideProps or app routes.
- Next.js ⇄ Amplify Auth: uses Amplify SDK to authenticate users via Cognito.
- Next.js (or direct client-side) → Supabase: queries facility data, saves user preferences.
- Browser → Google Maps API: renders map, markers, geocoding.
- populateDb.js → Supabase: one-time data seeding.

c. Architectural patterns & design principles
- Serverless: no always-on servers, just functions (Amplify Lambdas).
- Separation of concerns:
– UI Layer (React/Next.js)
– Auth layer (Cognito)
– Data layer (Supabase, custom Lambda)
- SSR/SSG via Next.js for performance and SEO.
- Component-based React design.

d. Key technologies & frameworks
- Next.js 13 (App Router)
- React + TypeScript + Tailwind CSS
- AWS Amplify (Auth + Lambda + hosting)
- Supabase (Postgres, REST/Realtime)
- Google Maps JavaScript API
- CI/CD: AWS CodeBuild (buildspec.yaml) or Vercel

##### Detail
- Data flows clearly with arrowheads.
- Build/deploy pipeline: highlight buildspec.yaml feeding into AWS CodeBuild or Vercel.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Browser / React UI"]:::frontend
    end

    %% Frontend Layer
    subgraph "Frontend (Next.js)" 
        direction TB
        NextJS["Next.js App Router (TSX)"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services" 
        direction TB
        AmplifyAuth["AWS Amplify Auth (Cognito)"]:::backend
        AmplifyLambda["AWS Amplify Lambdas (API GW + Lambda)"]:::backend
    end

    %% Data & External
    subgraph "Data Stores & External"
        direction TB
        Supabase[(Supabase Postgres)]:::data
        GoogleMaps["Google Maps JavaScript API"]:::external
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        CodeBuild["AWS CodeBuild / Vercel"]:::backend
    end

    %% Connections
    Browser -->|"Fetch pages / SSR/SSG"| NextJS
    Browser -->|"JS SDK"| Supabase
    Browser -->|"REST/JS API calls"| GoogleMaps

    NextJS -->|"Cognito SDK"| AmplifyAuth
    NextJS -->|"HTTP(S)/GraphQL"| AmplifyLambda
    NextJS -->|"HTTP(S)/GraphQL"| Supabase

    AmplifyLambda -->|"DB queries"| Supabase
    populateDb(["populateDb.js"]):::data -->|"Seed data"| Supabase

    CodeBuild -->|"Deploy"| NextJS
    CodeBuild -->|"Deploy Amplify"| AmplifyAuth
    CodeBuild -->|"Deploy Amplify"| AmplifyLambda

    %% Click Events
    click Browser "https://github.com/amr-radwan1/ecofind/tree/main/src/app/"
    click NextJS "https://github.com/amr-radwan1/ecofind/blob/main/src/app/layout.tsx"
    click NextJS "https://github.com/amr-radwan1/ecofind/blob/main/src/app/page.tsx"
    click NextJS "https://github.com/amr-radwan1/ecofind/blob/main/src/app/map/page.tsx"
    click NextJS "https://github.com/amr-radwan1/ecofind/blob/main/src/app/sign-in/page.tsx"
    click NextJS "https://github.com/amr-radwan1/ecofind/blob/main/src/app/sign-up/page.tsx"
    click NextJS "https://github.com/amr-radwan1/ecofind/blob/main/next.config.mjs"
    click AmplifyAuth "https://github.com/amr-radwan1/ecofind/blob/main/amplify/auth/resource.ts"
    click AmplifyAuth "https://github.com/amr-radwan1/ecofind/blob/main/amplify/tsconfig.json"
    click AmplifyAuth "https://github.com/amr-radwan1/ecofind/blob/main/amplify/package.json"
    click AmplifyLambda "https://github.com/amr-radwan1/ecofind/blob/main/amplify/data/resource.ts"
    click AmplifyLambda "https://github.com/amr-radwan1/ecofind/blob/main/amplify/backend.ts"
    click Supabase "https://github.com/amr-radwan1/ecofind/blob/main/populateDb.js"
    click GoogleMaps "https://github.com/amr-radwan1/ecofind/blob/main/src/app/components/map.tsx"
    click CodeBuild "https://github.com/amr-radwan1/ecofind/blob/main/buildspec.yaml"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20;
    classDef data fill:#FFECB3,stroke:#FF6F00,color:#E65100;
    classDef external fill:#FFE0B2,stroke:#E65100,color:#E65100;
```
