# andresz74/react-photogram architecture

> Architecture diagram of the GitHub repository andresz74/react-photogram, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andresz74/react-photogram
- Repository: https://github.com/andresz74/react-photogram

## Overview

##### Main System Components
a. Frontend (Browser/Client)
- React App (src/index.tsx → AppInitializer)
- UI Components (components/Layout, Gallery, Login, Common, etc.)
- State Management (Redux store in src/state; actionCreators, reducers, middleware)
- API Client Layer (src/api/*.ts[x])
b. Backend Service (External Node.js image-API)
- Node.js service managed by PM2
- Exposes endpoints: POST /image-api/upload, POST /image-api/delete-image
- Hosted behind Nginx proxy on port 3003
c. Cloud Services (Firebase)
- Authentication (Firebase Auth)
- Firestore Database (metadata storage)
- Firebase Storage (image file storage)

##### Relationships & Data Flows
a. Authentication flow:
Browser → Firebase Auth ← AuthProvider & AuthContext
b. Data retrieval & state updates:
React components → Redux actions → Redux reducers → Redux store → UI
c. API interactions:
API client (src/api) → Node.js backend →
- Store files in Firebase Storage
- Persist metadata in Firestore
d. Direct Firestore reads (e.g., listing images) can be done either via backend or directly through Firebase SDK in src/api.

##### Architectural Patterns
- Single-Page Application (SPA) with React Router
- Container/Presenter split:
– “Container” components dispatch Redux actions
– “Presenter” components render UI based on props/state
- Centralized State Management with Redux
- Feature-based folder structure (components/Gallery, components/Layout, state/, api/)
- API abstraction layer (src/api) decouples UI from backend implementation
- Environment configuration (config.ts, .env) isolates secrets

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend (Browser/Client)"
        direction TB
        AI["AppInitializer"]:::frontend
        APP["App"]:::frontend

        subgraph "UI Components"
            direction TB
            LAYOUT["Layout"]:::frontend
            GALLERY["Gallery UI"]:::frontend
            LOGIN["Login"]:::frontend
            COMMON["Common"]:::frontend
        end

        subgraph "Redux Store"
            direction TB
            STORE["Store"]:::frontend
            REDUCERS["Reducers"]:::frontend
            ACTION_CREATORS["Action Creators"]:::frontend
            ACTIONS["Actions"]:::frontend
            ACTION_TYPES["Action Types"]:::frontend
        end

        subgraph "API Client Layer"
            direction TB
            BASE_CLIENT["Base Client"]:::frontend
            IMAGES_API["Images Endpoints"]:::frontend
            USERS_API["User Endpoints"]:::frontend
        end

        subgraph "Config"
            direction TB
            CONFIG["App Configuration"]:::frontend
            FIREBASE_CONF["Firebase Setup"]:::frontend
        end

        AI -->|"renders"| APP
        APP -->|"renders"| LAYOUT
        APP -->|"renders"| GALLERY
        APP -->|"renders"| LOGIN
        APP -->|"renders"| COMMON

        LAYOUT -->|dispatches| ACTION_CREATORS
        GALLERY -->|dispatches| ACTION_CREATORS
        LOGIN -->|uses| COMMON

        ACTION_CREATORS -->|"invoke"| REDUCERS
        REDUCERS -->|"update"| STORE
        STORE -->|"state"| APP

        LAYOUT -->|"API calls"| BASE_CLIENT
        GALLERY -->|"API calls"| BASE_CLIENT
        LOGIN -->|"API calls"| BASE_CLIENT

        BASE_CLIENT -->|"calls upload/delete"| IMAGES_API
        BASE_CLIENT -->|"calls user endpoints"| USERS_API

        CONFIG --> APP
        FIREBASE_CONF --> APP
    end

    %% Backend Layer
    subgraph "Backend Service (Photogram-backend)"
        direction TB
        NGINX["Nginx + PM2"]:::backend
        NODE["Node.js Service"]:::backend
        NODE -->|"POST /upload, /delete"| NGINX
    end

    %% Firebase Services
    subgraph "Firebase Cloud Services"
        direction TB
        AUTH["Firebase Auth"]:::cloud
        FIRESTORE["Firestore (images collection)"]:::database
        STORAGE["Firebase Storage"]:::cloud
    end

    %% Data Flows
    APP -->|"authenticate via Firebase SDK"| AUTH
    BASE_CLIENT -->|"REST API over HTTPS"| NGINX
    NGINX -->|"proxies to"| NODE
    NODE -->|"Admin SDK"| FIRESTORE
    NODE -->|"Admin SDK"| STORAGE
    AUTH -->|"token"| NODE

    %% Click Events
    click AI "https://github.com/andresz74/react-photogram/blob/master/src/components/App/AppInitializer.tsx"
    click APP "https://github.com/andresz74/react-photogram/blob/master/src/components/App/App.tsx"
    click LAYOUT "https://github.com/andresz74/react-photogram/tree/master/src/components/Layout"
    click GALLERY "https://github.com/andresz74/react-photogram/tree/master/src/components/Gallery"
    click LOGIN "https://github.com/andresz74/react-photogram/blob/master/src/components/Login/Login.tsx"
    click COMMON "https://github.com/andresz74/react-photogram/tree/master/src/components/Common"
    click STORE "https://github.com/andresz74/react-photogram/blob/master/src/state/store.tsx"
    click REDUCERS "https://github.com/andresz74/react-photogram/tree/master/src/state/reducers"
    click ACTION_CREATORS "https://github.com/andresz74/react-photogram/blob/master/src/state/actionCreators/index.tsx"
    click ACTIONS "https://github.com/andresz74/react-photogram/blob/master/src/state/actions/index.ts"
    click ACTION_TYPES "https://github.com/andresz74/react-photogram/blob/master/src/state/actionTypes/index.ts"
    click BASE_CLIENT "https://github.com/andresz74/react-photogram/blob/master/src/api/index.tsx"
    click IMAGES_API "https://github.com/andresz74/react-photogram/blob/master/src/api/images.ts"
    click USERS_API "https://github.com/andresz74/react-photogram/blob/master/src/api/users.ts"
    click CONFIG "https://github.com/andresz74/react-photogram/blob/master/src/config.ts"
    click FIREBASE_CONF "https://github.com/andresz74/react-photogram/blob/master/src/firebase.configuration.ts"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#006064
    classDef backend fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
    classDef cloud fill:#fff3e0,stroke:#ef6c00,color:#ef6c00
    classDef database fill:#f3e5f5,stroke:#6a1b9a,color:#6a1b9a
```
