# teamhavit/havit-server architecture

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

- Interactive diagram: https://gitdiagram.com/teamhavit/havit-server
- Repository: https://github.com/teamhavit/havit-server

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Client Layer:
- iOS App (with Share Extension)
- Android App (with Intent Filter)

b) API Gateway Layer:
- Firebase Functions as the serverless backend
- Express.js REST API routes

c) Core Service Layer:
- Authentication Service (auth routes)
- Content Management Service (content routes)
- Category Management Service (category routes)
- Community Service (community routes)
- Notification Service (FCM Push Server)

d) External Services:
- Kakao Auth
- Apple Auth
- Firebase Cloud Messaging (FCM)
- Slack Integration

e) Database Layer:
- PostgreSQL Database

**[Client Layer]**
- ↓
**[API Gateway Layer]**
- ↓
**[Core Services Layer]**
- ↓
**[External Services Layer]**
- ↓
**[Database Layer]**

##### Key Relationships to Highlight

- Authentication flow between clients, auth service, and external auth providers
- Content management flow showing how content is saved, categorized, and retrieved
- Push notification system integration with FCM
- Database interactions for each service
- Error handling and logging flow to Slack

##### Implementation Details

- Rectangles: Main services
- Hexagons: External services
- Diamonds: Decision points

##### Additional Elements

Supporting components:
- Swagger documentation integration
- Test coverage (Mocha)
- Environment configurations
- Security layers (JWT, middleware)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        IOS[iOS App]
        AND[Android App]
    end

    %% API Gateway Layer
    subgraph Gateway
        API["API Gateway"]:::gateway
    end

    %% Core Services Layer
    subgraph CoreServices
        AUTH["Authentication Service"]:::service
        CMS["Content Management Service"]:::service
        CAT["Category Management Service"]:::service
        COM["Community Service"]:::service
        NOTIF["Notification Service"]:::service
    end

    %% External Services Layer
    subgraph ExternalServices
        KAKAO["Kakao Auth"]:::external
        APPLE["Apple Auth"]:::external
        FCM["Firebase Cloud Messaging"]:::external
        SLACK["Slack Integration"]:::external
    end

    %% Database Layer
    subgraph Database
        DB[(PostgreSQL)]:::database
        subgraph Models
            UMOD["User Model"]:::model
            CMOD["Content Model"]:::model
            CATMOD["Category Model"]:::model
            COMMOD["Community Model"]:::model
        end
    end

    %% Middleware Layer
    subgraph Middleware
        AUTHMW["Auth Middleware"]:::middleware
        ERRMW["Error Handler"]:::middleware
        VALMW["Validation"]:::middleware
        SLACKMW["Slack API Middleware"]:::middleware
    end

    %% Relationships
    IOS & AND --> API
    API --> AUTH & CMS & CAT & COM & NOTIF
    AUTH --> KAKAO & APPLE
    NOTIF --> FCM
    ERRMW --> SLACK
    CoreServices --> Middleware
    Middleware --> DB
    DB --> Models

    %% Click Events
    click API "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/api/index.js"
    click AUTH "https://github.com/TeamHavit/Havit-Server/tree/develop/functions/api/routes/auth/"
    click CMS "https://github.com/TeamHavit/Havit-Server/tree/develop/functions/api/routes/content/"
    click CAT "https://github.com/TeamHavit/Havit-Server/tree/develop/functions/api/routes/category/"
    click COM "https://github.com/TeamHavit/Havit-Server/tree/develop/functions/api/routes/community/"
    click NOTIF "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/lib/pushServerHandlers.js"
    click KAKAO "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/lib/kakaoAuth.js"
    click APPLE "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/lib/appleAuth.js"
    click SLACK "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/lib/slackMessage.js"
    click DB "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/config/dbConfig.js"
    click UMOD "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/db/user.js"
    click CMOD "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/db/content.js"
    click CATMOD "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/db/category.js"
    click COMMOD "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/db/community.js"
    click AUTHMW "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/middlewares/auth.js"
    click ERRMW "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/middlewares/errorHandler.js"
    click VALMW "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/middlewares/validation.js"
    click SLACKMW "https://github.com/TeamHavit/Havit-Server/blob/develop/functions/middlewares/slackAPI.js"

    %% Styles
    classDef client fill:#2374ab
    classDef gateway fill:#57a773
    classDef service fill:#ffc857
    classDef external fill:#7b68ee
    classDef database fill:#ff8c42
    classDef middleware fill:#808080
    classDef model fill:#deb887

    class IOS,AND client
    class API gateway
    class AUTH,CMS,CAT,COM,NOTIF service
    class KAKAO,APPLE,FCM,SLACK external
    class DB database
    class AUTHMW,ERRMW,VALMW,SLACKMW middleware
    class UMOD,CMOD,CATMOD,COMMOD model
```
