# deanco100/foobar-server-public architecture

> Architecture diagram of the GitHub repository deanco100/foobar-server-public, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deanco100/foobar-server-public
- Repository: https://github.com/deanco100/foobar-server-public

## Overview

##### Main Components

A. Client Layer (External)
- Web Client (React.js based on the build files in /public)
- Android Client (mentioned in README but not in this repo)

B. Server Layer (Node.js)
- API Gateway
- Routes (/routes)
- Login Routes
- Post Routes
- User Routes

- Middleware Layer
- Token Checker (Authentication)
- Bloom Filter Helper (Utils)

- Business Logic Layer
- Controllers
- User Controller
- Post Controller

- Services
- User Service
- Post Service

- Data Layer
- Models
- User Model
- Post Model
- MongoDB Database

##### Component Relationships

- Clients → API Gateway (REST APIs)
- API Gateway → Middleware → Controllers
- Controllers → Services
- Services → Models
- Models → MongoDB

##### Important Details

A. Authentication Flow:
- Token-based authentication flow
- TokenChecker middleware
- Login/register paths

B. Data Flow:
- Post creation/deletion/editing flow
- User management flow
- Friend request system

C. Special Features:
- Bloom Filter implementation (for optimization)
- Environment configuration handling
- Local/Test environment separation

##### Technical Specifications to Note

- Port: 8080 (from config)
- MongoDB Connection: localhost:27017/FooBar
- Environment Configurations (.env, .env.local, .env.test)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        WC[Web Client]:::client
        AC[Android Client]:::client
    end

    %% API Gateway Layer
    subgraph "API Gateway"
        AG[API Gateway]:::gateway
        subgraph "Routes"
            LR["Login Routes"]:::route
            PR["Post Routes"]:::route
            UR["User Routes"]:::route
        end
    end

    %% Middleware Layer
    subgraph "Middleware"
        TC["Token Checker"]:::middleware
        BF["Bloom Filter"]:::middleware
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        subgraph "Controllers"
            UC["User Controller"]:::controller
            PC["Post Controller"]:::controller
        end
        subgraph "Services"
            US["User Service"]:::service
            PS["Post Service"]:::service
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        UM["User Model"]:::model
        PM["Post Model"]:::model
        DB[(MongoDB)]:::database
    end

    %% Relationships
    WC --> AG
    AC --> AG
    AG --> LR & PR & UR
    LR & PR & UR --> TC
    TC --> BF
    BF --> UC & PC
    UC --> US
    PC --> PS
    US --> UM
    PS --> PM
    UM & PM --> DB

    %% Click Events
    click WC "https://github.com/DeanCo100/FooBar-Server-Public/tree/main/public"
    click LR "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/routes/login.js"
    click PR "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/routes/post.js"
    click UR "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/routes/user.js"
    click TC "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/middleware/tokenChecker.js"
    click BF "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/utils/BloomFilterHelper.js"
    click UC "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/controllers/user.js"
    click PC "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/controllers/post.js"
    click US "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/services/user.js"
    click PS "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/services/post.js"
    click UM "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/models/user.js"
    click PM "https://github.com/DeanCo100/FooBar-Server-Public/blob/main/models/post.js"

    %% Styles
    classDef client fill:#2374ab
    classDef gateway fill:#2a9d8f
    classDef route fill:#95d5b2,rx:10
    classDef middleware fill:#f4a261,shape:hexagon
    classDef controller fill:#e76f51
    classDef service fill:#e9c46a
    classDef model fill:#ef476f
    classDef database fill:#7209b7,shape:cylinder

    %% Legend
    subgraph Legend
        L1[Client]:::client
        L2[Gateway]:::gateway
        L3[Route]:::route
        L4[Middleware]:::middleware
        L5[Controller]:::controller
        L6[Service]:::service
        L7[Model]:::model
        L8[(Database)]:::database
    end
```
