# tanya-2004/biospotter architecture

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

- Interactive diagram: https://gitdiagram.com/tanya-2004/biospotter
- Repository: https://github.com/tanya-2004/biospotter

## Overview

##### Main Components
- User Interface (Frontend): Represented by static HTML, CSS, and JavaScript files (found in the frontend/public folder). Include pages such as index.html, chatbot.html, discussion.html, gallery.html, signin.html, and signup.html.
- Web Server / API Backend: The NodeJS/Express server located in the backend directory. This includes:
- Controllers (chatbot, discussion, gallery, user) handling specific business logic.
- Routes that map incoming HTTP requests to the appropriate controllers.
- Middleware (e.g., authentication, logging) for processing requests.
- Utility components (like jwt for token generation/validation).
- Database integration models (user, discussionPost, galleryItem) for MongoDB interactions.
- External Services:
- ChatBot API that provides real-time assistance.
- Possibly Socket.io (as mentioned in the readme) for handling real-time discussion board functionalities.
- Database: MongoDB is used to store user data, discussion posts, gallery items, etc.

##### Relationships and Interactions
- The user (via a web browser) accesses the static frontend pages which then communicate with the backend using HTTP requests (and potentially WebSocket via Socket.io for discussion features).
- The backend NodeJS server routes these requests:
- For user-related activities (login, registration, etc.), the user routes and controllers manage authentication and data access.
- For gallery operations, the gallery routes and controllers handle image file uploads, accessing corresponding models and the uploads folder.
- For chatbot interactions, the chatbot controller interfaces with an external Chatbot API.
- For discussion features, the discussion controller likely integrates real-time communication via Socket.io.
- The ML Microservice (Flask app) receives image inputs (possibly via backend request forwarding) and returns species identification data. The Python ML files (app.py and model.py) serve as the backbone of this service.
- Data flows from the backend to MongoDB and back, and also possibly to/from the ML service when image analysis is required.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project clearly segregates responsibilities via separate directories for controllers, models, routes, and middleware.
- Service-Oriented Approach: The ML model and chatbot API are externalized, reinforcing modular design.
- Client-Server Architecture: Distinguish frontend (client) from backend (server API) interactions.
- Real-Time Communication: Use Socket.io for the discussion section, demonstrating a decoupled approach for real-time data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client / Web Browser"]:::client
    FE["Frontend (Static Content)"]:::frontend
    BS["Backend Server (NodeJS/Express)"]:::backend
    ML["ML Microservice (Flask/Python CNN)"]:::ml
    EX["External Chatbot API"]:::external
    DB["MongoDB (Database)"]:::database

    Client -->|"HTTP/WebSocket"| FE
    FE -->|"REST_API"| BS
    BS -->|"Image_Processing"| ML
    BS -->|"Chatbot_Request"| EX
    BS -->|"Data_Persistence"| DB

    subgraph "NodeJS Backend Components"
        direction TB
        SS["Server Setup"]:::backend
        MW["Middlewares"]:::backend
        RT["Routes"]:::backend
        CT["Controllers"]:::backend
        MD["Models"]:::backend
        UT["Utilities"]:::backend

        SS --> MW
        MW --> RT
        RT --> CT
        CT --> MD
        CT --> UT
    end

    %% Click Events
    click FE "https://github.com/tanya-2004/biospotter/tree/main/frontend/public"
    click BS "https://github.com/tanya-2004/biospotter/tree/main/backend"
    click SS "https://github.com/tanya-2004/biospotter/blob/main/backend/index.js"
    click MW "https://github.com/tanya-2004/biospotter/tree/main/backend/middlewares"
    click RT "https://github.com/tanya-2004/biospotter/tree/main/backend/routes"
    click CT "https://github.com/tanya-2004/biospotter/tree/main/backend/controllers"
    click MD "https://github.com/tanya-2004/biospotter/tree/main/backend/models"
    click UT "https://github.com/tanya-2004/biospotter/tree/main/backend/utils"
    click ML "https://github.com/tanya-2004/biospotter/blob/main/frontend/public/app.py"
    click EX "https://github.com/tanya-2004/biospotter/blob/main/backend/routes/chatbotRoutes.js"
    click DB "https://github.com/tanya-2004/biospotter/tree/main/backend/models"

    %% Styles
    classDef client fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef frontend fill:#87CEEB,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef ml fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef external fill:#ffcc99,stroke:#000,stroke-width:2px;
    classDef database fill:#f4a460,stroke:#000,stroke-width:2px;
```
