# crishenrique/be_thehero architecture

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

- Interactive diagram: https://gitdiagram.com/crishenrique/be_thehero
- Repository: https://github.com/crishenrique/be_thehero

## Overview

##### Project type and purpose
- This is a full-stack, tri-client application (“Be The Hero”) consisting of:
- A Node.js/Express backend with an SQLite database (via Knex).
- A React single-page web frontend.
- A React Native (Expo) mobile app.
- Purpose: Let NGOs register and manage “incidents” via web or mobile clients.

##### File structure
- Top-level directories:
- backend/ – Express server, controllers, routes, database (Knex + SQLite), tests.
- frontend/ – React app with pages, CSS, API service layer.
- mobile/ – Expo/React Native app mirroring the web’s services and pages.
- Patterns:
- Backend follows an MVC-ish structure: routes → controllers → database.
- Clients both import a shared api.js service for HTTP calls.
- Config files: knexfile.js, package.json in each client, Babel config for mobile.

##### README
- Confirms tech stack: Node.js, Express, React, Expo.

##### Detailed breakdown of the backend component
- Routes (routes.js)
- Controllers (ProfileController, SessionController, OngController, IncidentController)
- Database module (connection.js + migrations)
- That migrations define tables for “ongs” and “incidents” (Knex migrations).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        WebApp["Web Client\n(React SPA)"]:::frontend
        MobileApp["Mobile Client\n(Expo/React Native)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIServer["API Server\n(Node.js + Express)"]:::backend

        subgraph "Setup"
            direction TB
            ServerIndex["index.js"]:::backend
            ServerJS["server.js"]:::backend
            AppJS["app.js"]:::backend
        end

        subgraph "Routing"
            direction TB
            Routes["routes.js"]:::backend
        end

        subgraph "Controllers"
            direction TB
            OngCtrl["OngController.js"]:::backend
            IncidentCtrl["IncidentController.js"]:::backend
            ProfileCtrl["ProfileController.js"]:::backend
            SessionCtrl["SessionController.js"]:::backend
        end

        subgraph "Database Layer"
            direction TB
            Connection["connection.js"]:::backend
            subgraph "Migrations"
                direction TB
                MigOngs["20200324122534_create_ongs.js"]:::backend
                MigInc["20200324130510_create_incidents.js"]:::backend
            end
            subgraph "SQLite Files"
                direction TB
                DBSrc["db.sqlite"]:::database
                DBTest["test.sqlite"]:::database
            end
        end

        Utils["generateUniqueId.js"]:::backend
    end

    %% Relationships
    WebApp -->|HTTP/HTTPS| APIServer
    MobileApp -->|HTTP/HTTPS| APIServer
    APIServer -->|uses| ServerIndex
    APIServer -->|uses| ServerJS
    APIServer -->|uses| AppJS
    APIServer -->|routes defined in| Routes
    Routes -->|invoke| OngCtrl
    Routes -->|invoke| IncidentCtrl
    Routes -->|invoke| ProfileCtrl
    Routes -->|invoke| SessionCtrl
    Controllers -->|query| Connection
    Connection -->|runs migrations| MigOngs
    Connection -->|runs migrations| MigInc
    Connection -->|reads/writes| DBSrc
    Connection -->|reads/writes| DBTest
    Utils -->|utilized by| Controllers

    %% Presentation layer details
    subgraph "Web Client Details" 
        direction TB
        WebEntry["index.js"]:::frontend
        WebMain["App.js"]:::frontend
        WebRoutesFile["routes.js"]:::frontend
        WebPages["pages/Logon,\nRegister,Profile,NewIncident"]:::frontend
        WebStyles["styles.css,\nglobal.css"]:::frontend
        WebAPI["api.js"]:::frontend
    end

    subgraph "Mobile Client Details"
        direction TB
        MobileEntry["App.js"]:::frontend
        MobileRoutes["routes.js"]:::frontend
        MobilePages["pages/Incidents,\nDetail"]:::frontend
        MobileStyles["styles.js"]:::frontend
        MobileAPI["api.js"]:::frontend
    end

    WebApp --> WebEntry
    WebEntry --> WebMain
    WebMain --> WebRoutesFile
    WebMain --> WebPages
    WebPages --> WebStyles
    WebMain --> WebAPI

    MobileApp --> MobileEntry
    MobileEntry --> MobileRoutes
    MobileRoutes --> MobilePages
    MobilePages --> MobileStyles
    MobilePages --> MobileAPI

    WebAPI -->|HTTP calls| APIServer
    MobileAPI -->|HTTP calls| APIServer

    %% Click Events - Web Client
    click WebApp "https://github.com/crishenrique/be_thehero/tree/master/frontend/"
    click WebEntry "https://github.com/crishenrique/be_thehero/blob/master/frontend/src/index.js"
    click WebMain "https://github.com/crishenrique/be_thehero/blob/master/frontend/src/App.js"
    click WebRoutesFile "https://github.com/crishenrique/be_thehero/blob/master/frontend/src/routes.js"
    click WebPages "https://github.com/crishenrique/be_thehero/blob/master/frontend/src/pages/Logon/index.js"
    click WebAPI "https://github.com/crishenrique/be_thehero/blob/master/frontend/src/services/api.js"

    %% Click Events - Mobile Client
    click MobileApp "https://github.com/crishenrique/be_thehero/tree/master/mobile/"
    click MobileEntry "https://github.com/crishenrique/be_thehero/blob/master/mobile/App.js"
    click MobileRoutes "https://github.com/crishenrique/be_thehero/blob/master/mobile/src/routes.js"
    click MobilePages "https://github.com/crishenrique/be_thehero/blob/master/mobile/src/pages/Incidents/index.js"
    click MobileAPI "https://github.com/crishenrique/be_thehero/blob/master/mobile/src/services/api.js"

    %% Click Events - Backend
    click APIServer "https://github.com/crishenrique/be_thehero/tree/master/backend/src/"
    click ServerIndex "https://github.com/crishenrique/be_thehero/blob/master/backend/src/index.js"
    click ServerJS "https://github.com/crishenrique/be_thehero/blob/master/backend/src/server.js"
    click AppJS "https://github.com/crishenrique/be_thehero/blob/master/backend/src/app.js"
    click Routes "https://github.com/crishenrique/be_thehero/blob/master/backend/src/routes.js"
    click OngCtrl "https://github.com/crishenrique/be_thehero/blob/master/backend/src/controllers/OngController.js"
    click IncidentCtrl "https://github.com/crishenrique/be_thehero/blob/master/backend/src/controllers/IncidentController.js"
    click ProfileCtrl "https://github.com/crishenrique/be_thehero/blob/master/backend/src/controllers/ProfileController.js"
    click SessionCtrl "https://github.com/crishenrique/be_thehero/blob/master/backend/src/controllers/SessionController.js"
    click Connection "https://github.com/crishenrique/be_thehero/blob/master/backend/src/database/connection.js"
    click MigOngs "https://github.com/crishenrique/be_thehero/blob/master/backend/src/database/migrations/20200324122534_create_ongs.js"
    click MigInc "https://github.com/crishenrique/be_thehero/blob/master/backend/src/database/migrations/20200324130510_create_incidents.js"
    click DBSrc "https://github.com/crishenrique/be_thehero/blob/master/backend/src/database/db.sqlite"
    click DBTest "https://github.com/crishenrique/be_thehero/blob/master/backend/src/database/test.sqlite"
    click Utils "https://github.com/crishenrique/be_thehero/blob/master/backend/src/utils/generateUniqueId.js"
    click knexfile "https://github.com/crishenrique/be_thehero/blob/master/backend/knexfile.js"
    click pkg "https://github.com/crishenrique/be_thehero/blob/master/backend/package.json"
    click jest "https://github.com/crishenrique/be_thehero/blob/master/backend/jest.config.js"
    click testInt "https://github.com/crishenrique/be_thehero/blob/master/backend/tests/integration/ong.spec.js"
    click testUnit "https://github.com/crishenrique/be_thehero/blob/master/backend/tests/unit/generateUniqueId.spec.js"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:1px
    classDef backend fill:#90ee90,stroke:#333,stroke-width:1px
    classDef database fill:#ffcc99,stroke:#333,stroke-width:1px
```
