# 874wokiite/ai-secretary-zundamon architecture

> Architecture diagram of the GitHub repository 874wokiite/ai-secretary-zundamon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/874wokiite/ai-secretary-zundamon
- Repository: https://github.com/874wokiite/ai-secretary-zundamon

## Overview

##### Project Type and Purpose
- This is a Chrome extension built using Plasmo framework with React, TypeScript, and Tailwind CSS. Its purpose is to provide an AI-assisted secretary experience where "ずんだもん" supports users by reminding them of daily schedules (by integrating with Google Calendar), engaging in chat using OpenAI’s GPT-4o, and providing motivational “toast” messages.
- The README emphasizes three main features: schedule reminders, chat interactions, and supportive or motivational messages.

##### File Structure
- The top-level files include configuration files like .eslintrc.json, .prettierrc, package.json, tsconfig.json, and tailwind.config.js which set up the project’s coding style and build process.
- Assets and documents folders supply static resources such as images and sounds (including specialized assets for ずんだもん).
- The src directory is organized into clear subdirectories:
- “background”: Contains the background scripts and message handling logic (e.g., getMessage.ts, setPhraseReminder.ts, etc.) which interface with Plasmo’s messaging system.
- “components”: Contains reusable UI components like Button, IconButton, Popup, and the specific ZundamonImage component.
- “features”: Divided into feature-specific folders (Chat, Remainder, Title) that encapsulate components, hooks, and types for each main function.
- “contents”: Likely represents the popup or the primary UI content.
- “hooks”, “styles”, “types” and “utils” provide shared utilities across the project.

##### Key Architectural Components
a. Chrome Extension Shell:
- Content UI/Popup: Represented by “src/contents” and “src/components” that render the user interface.
- Background Scripts: Located in “src/background” with messaging logic to handle API calls and scheduled reminder setups.
- Messaging System: Utilizing Plasmo’s @plasmohq/messaging to bridge messages between the Content Scripts and Background Scripts (to circumnavigate CORS issues).

b. Feature Modules:
- Chat Feature: Managed in “src/features/Chat” where chat components, hooks (useGetMessage.tsx), and types define the chatting experience with GPT-4o.
- Reminder Feature: Handled in “src/features/Remainder”, with its own UI components and hooks (for fetching phrases, schedules, summary, and setting reminders). This module interfaces with Google Calendar API for scheduling.
- Title/Entrance Feature: In “src/features/Title” to welcome users and transition them into the experience.

c. External Integrations:
- OpenAI GPT-4o: For AI text generation used in both the chat and the reminder features.
- Google Calendar API: For fetching calendar events and schedules, integrated within the background or custom hooks.
- External Dependencies: Include utility libraries (e.g., react-spring for animations) as mentioned in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Chrome Extension Shell
    subgraph "Chrome Extension Shell"
        ContentUI["Content/UI Scripts\n(src/contents & src/components)"]:::frontend
        Messaging["Messaging Layer\n(Plasmo Messaging, src/background/messages)"]:::messaging
        Background["Background Scripts\n(src/background)"]:::backend
    end

    %% Feature Modules
    subgraph "Feature Modules"
        ChatModule["Chat Feature Module\n(src/features/Chat)"]:::module
        ReminderModule["Reminder Feature Module\n(src/features/Remainder)"]:::module
        TitleModule["Title/Entrance Module\n(src/features/Title)"]:::module
    end

    %% External Integrations
    subgraph "External Integrations"
        OpenAI["OpenAI GPT-4o Integration\n(src/utils/openai.ts)"]:::external
        GoogleCalendar["Google Calendar API Integration\n(src/background/messages/getSchedules.ts)"]:::external
    end

    %% Connections in Chrome Extension Shell
    ContentUI -->|"sendMessage"| Messaging
    Messaging -->|"forwardMessage"| Background

    %% UI triggers Feature Modules
    ContentUI -->|"loadChat"| ChatModule
    ContentUI -->|"loadReminder"| ReminderModule
    ContentUI -->|"loadTitle"| TitleModule

    %% Feature Modules call External Integrations
    ChatModule -->|"requestChat"| OpenAI
    ReminderModule -->|"fetchSchedules"| GoogleCalendar

    %% Background Scripts also interact with External Integrations
    Background -->|"callGPT"| OpenAI
    Background -->|"callCalendar"| GoogleCalendar

    %% External responses flow back
    OpenAI -->|"response"| Background
    GoogleCalendar -->|"data"| Background

    %% Responses propagate back to UI
    Background -->|"sendResponse"| Messaging
    Messaging -->|"deliverData"| ContentUI

    %% Click Events
    click ContentUI "https://github.com/874wokiite/ai-secretary-zundamon/tree/main/src/contents"
    click ContentUI "https://github.com/874wokiite/ai-secretary-zundamon/tree/main/src/components"
    click Messaging "https://github.com/874wokiite/ai-secretary-zundamon/tree/main/src/background/messages"
    click Background "https://github.com/874wokiite/ai-secretary-zundamon/tree/main/src/background"
    click ChatModule "https://github.com/874wokiite/ai-secretary-zundamon/tree/main/src/features/Chat"
    click ReminderModule "https://github.com/874wokiite/ai-secretary-zundamon/tree/main/src/features/Remainder"
    click TitleModule "https://github.com/874wokiite/ai-secretary-zundamon/tree/main/src/features/Title"
    click OpenAI "https://github.com/874wokiite/ai-secretary-zundamon/blob/main/src/utils/openai.ts"
    click GoogleCalendar "https://github.com/874wokiite/ai-secretary-zundamon/blob/main/src/background/messages/getSchedules.ts"

    %% Styles
    classDef frontend fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef messaging fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef backend fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
    classDef module fill:#d5f5e3,stroke:#239b56,stroke-width:2px;
    classDef external fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
```
