# thedarkking01/farm-bridge-app architecture

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

- Interactive diagram: https://gitdiagram.com/thedarkking01/farm-bridge-app
- Repository: https://github.com/thedarkking01/farm-bridge-app

## Overview

1. A React Native–based mobile frontend (located in the Farm-Bridge-Frontend directory) that handles user interaction, navigation, and presentation.
2. A backend (in the Backend directory) built with Node.js that orchestrates business logic, handles authentication, and manages data persistence.

##### Main Components
- Mobile Frontend: Represent the entire React Native application. Break this down further into:
- Screens (e.g., Login, Home, ProductDetails, Cart, Profile, etc.)
- Navigation Layer (React Navigation) for transitions between screens.
- Reusable UI Components and Hooks (to manage state, styling, etc.)
- API Gateway/Communication Layer: Illustrate how the mobile app interacts with the backend through HTTP (or RESTful) API calls.
- Controllers (e.g., authController, cartController, orderController, productController, userController) – these manage incoming requests.
- Routes (grouped by functionality) – which map URL endpoints to controllers.
- Middlewares (e.g., authentication middleware using JWT defined in token utilities).
- Models – representing database entities (e.g., User, Product, Order, Cart, etc.).
- Database Connection/Configuration – present in the db folder along with potential migration scripts.

##### Relationships and Interactions
- Within the Backend, show interactions:
- API endpoints handled by Routes that call the respective Controllers.
- Controllers use Models to read/write data in the database.
- Middleware is interjected in the API flow for authentication and other cross-cutting concerns.

##### Architectural Patterns and Technologies
- Full-stack separation – clear distinction between frontend mobile presentation and backend business logic.
- RESTful API/HTTP communication between frontend and backend.
- MVC patterns in the backend, with:
- Models representing database entities.
- Views are not explicitly present since this is an API-driven backend, but Controllers play the role of processing and responding to client requests.
- Use of JWT-based authentication (as per the ‘utils/token.js’ file and authMiddleware).
- Planned technologies (React Native with React Navigation for the frontend and an Express.js/Fastify-based backend for future integration).
- Migration and configuration files as part of the backend setup.

 Frontend sending API requests to the backend.
 Backend receiving requests through routes, passing them to controllers, and then interacting with models and the database.
- Annotations:
- Middleware intercepting requests in the API flow.
- Optionally, note how migration scripts manage the database state.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Mobile Frontend Subgraph
    subgraph "Mobile Frontend"
        FE_Screens["Screens: Login, Home, ProductDetails, Cart, Profile"] 
        FE_Nav["Navigation Layer"]
        FE_UI["Reusable UI Components"]
        FE_Hooks["Hooks"]
    end
    click FE_Screens "https://github.com/thedarkking01/farm-bridge-app/tree/main/Farm-Bridge-Frontend/app/Screens/"
    click FE_Nav "https://github.com/thedarkking01/farm-bridge-app/blob/main/Farm-Bridge-Frontend/app/(tabs)/navigation/AppNavigator.tsx"
    click FE_UI "https://github.com/thedarkking01/farm-bridge-app/tree/main/Farm-Bridge-Frontend/components/"
    click FE_Hooks "https://github.com/thedarkking01/farm-bridge-app/tree/main/Farm-Bridge-Frontend/hooks/"

    %% Backend Server Subgraph
    subgraph "Backend Server"
        BE_Routes["Routes\n(authRoutes, cartRoutes, orderRoutes, productRoutes, userRoutes)"]
        BE_Controllers["Controllers\n(authController, cartController, orderController, productController, userController)"]
        BE_Middlewares["Middlewares\n(authMiddleware)"]
        BE_Models["Models\n(User, Product, Order, Cart, etc.)"]
        BE_DBConn["DB Connection\n(db.js)"]
        BE_Config["Configuration\n(config.json)"]
        BE_Migrations["Migration Scripts"]
        BE_Token["JWT Token Utilities\n(token.js)"]
    end
    click BE_Routes "https://github.com/thedarkking01/farm-bridge-app/tree/main/Backend/routes/"
    click BE_Controllers "https://github.com/thedarkking01/farm-bridge-app/tree/main/Backend/controllers/"
    click BE_Middlewares "https://github.com/thedarkking01/farm-bridge-app/blob/main/Backend/middlewares/authMiddleware.js"
    click BE_Models "https://github.com/thedarkking01/farm-bridge-app/tree/main/Backend/models/"
    click BE_DBConn "https://github.com/thedarkking01/farm-bridge-app/blob/main/Backend/db/db.js"
    click BE_Config "https://github.com/thedarkking01/farm-bridge-app/blob/main/Backend/config/config.json"
    click BE_Migrations "https://github.com/thedarkking01/farm-bridge-app/tree/main/Backend/migrations/"
    click BE_Token "https://github.com/thedarkking01/farm-bridge-app/blob/main/Backend/utils/token.js"

    %% Database Component
    DB["Database (Planned: MongoDB/PostgreSQL)"]
    
    %% Connections from Mobile Frontend to Backend
    FE_Screens -->|"HTTP_Request"| BE_Routes
    FE_Nav -->|"API_Call"| BE_Routes

    %% Internal Backend Flows
    BE_Routes -->|"Forwards_Request"| BE_Controllers
    BE_Middlewares ---|"Intercepts"| BE_Routes
    BE_Controllers -->|"Uses_Model"| BE_Models
    BE_Controllers -->|"Queries"| BE_DBConn
    BE_Models -->|"Data_Persistence"| DB
    BE_DBConn -->|"DB_Operations"| DB
    BE_Migrations --> BE_DBConn
    BE_Token -->|"Authenticates"| BE_Middlewares

    %% Styling
    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef database fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    
    class FE_Screens,FE_Nav,FE_UI,FE_Hooks frontend;
    class BE_Routes,BE_Controllers,BE_Middlewares,BE_Models,BE_DBConn,BE_Config,BE_Migrations,BE_Token backend;
    class DB database;
```
