# khoaluongcode/hackathon-monday architecture

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

- Interactive diagram: https://gitdiagram.com/khoaluongcode/hackathon-monday
- Repository: https://github.com/khoaluongcode/hackathon-monday

## Overview

##### Main Components
- Frontend: Built using Next.js and React, the “src/app” and “src/components” directories contain the UI components (e.g., ArchiveButton, CalendarEventCard, TopNav) and pages. This layer also leverages Shadcn UI components and integrates state management via React Hook Form and Zod.
- Backend/Server: The “src/server” directory houses API endpoints, server-side actions (like email processing in ‘actions.ts’, Gmail integration in ‘gmail.ts’, Google Calendar actions, and chat handling). The “middleware.ts” in src plays a role in request processing.
- Database: Although the README lists Prisma and PostgreSQL as the ORM and database, the presence of “drizzle.config.ts” and “src/server/db” indicates that there is database management code, likely abstracting database queries, schema definitions, and connection functionalities.
- External Services:
- Authentication: Handled by Clerk.
- AI Integration: Using OpenAI GPT-4 for email and scheduling intelligence.
- APIs: Integration with Google Gmail and Google Calendar.

##### Component Relationships and Interactions
- The Frontend (Next.js UI) interacts with the Backend via API routes or server-side actions. The pages and UI components initiate requests (for example, to summarize emails or schedule events) that are processed in the server directory.
- The Backend communicates with third-party services. For instance, calls to Google’s APIs (Gmail and Calendar) are managed in the “src/server” directory, and AI-powered requests are routed to OpenAI.
- The Backend interacts with the Database to store and retrieve information such as email summaries and scheduled events.
- Authentication flows integrate with Clerk, ensuring that user sessions and secure access are maintained throughout the app.

##### Architectural Patterns and Key Elements
- Separation of Concerns: Clear division between client-side UI components (in “src/app” and “src/components”), server-side logic (in “src/server”), and external integrations.
- Modular Design: Use of dedicated directories for UI components, business logic, and integrations promotes easy maintenance and scalability.
- Data Flow: Clear, directional data flow from the front-end inputs to server actions, from server actions to external services, and responses returning through the frontend.

##### Final Recommendations
- Module is clearly labeled (e.g., “Next.js Frontend”, “Server API”, “Database (PostgreSQL)”, “External API: Gmail”, “External API: Google Calendar”, “Authentication: Clerk”, “AI Service: OpenAI GPT-4”).
- If possible, note key technology mentions (React, Next.js, TypeScript, Shadcn UI) next to the appropriate components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["Next.js Pages"]:::frontend
        FE2["UI Components"]:::frontend
        UICompA["Components Folder (_components)"]:::frontend
        UICompB["UI Components Folder (ui)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B2["Middleware"]:::backend
        B1["Server API"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB1["Database Config"]:::database
        DB2["Database Layer"]:::database
    end

    %% External Services
    subgraph "External Services"
        E3["Authentication: Clerk"]:::external
        E1["Gmail API Integration"]:::external
        E2["Google Calendar Integration"]:::external
        E4["AI Service: OpenAI GPT-4"]:::external
    end

    %% Data Flow Connections
    FE1 -->|"requests"| B2
    FE2 -->|"requests"| B2
    UICompA -->|"requests"| B2
    UICompB -->|"requests"| B2
    B2 -->|"processes"| B1

    B1 -->|"reads/writes"| DB2
    B1 -->|"uses"| E1
    B1 -->|"uses"| E2
    B1 -->|"calls"| E4

    %% Authentication Flow
    FE1 -.->|"authenticates via"| E3
    FE2 -.->|"authenticates via"| E3

    %% Response Flow
    B1 -->|"response"| FE1
    B1 -->|"response"| FE2

    %% Database Config linkage (for configuration reference)
    DB1 --- DB2

    %% Click Events
    click FE1 "https://github.com/khoaluongcode/hackathon-monday/tree/main/src/app"
    click FE2 "https://github.com/khoaluongcode/hackathon-monday/tree/main/src/components"
    click UICompA "https://github.com/khoaluongcode/hackathon-monday/tree/main/src/app/_components"
    click UICompB "https://github.com/khoaluongcode/hackathon-monday/tree/main/src/components/ui"
    click B1 "https://github.com/khoaluongcode/hackathon-monday/tree/main/src/server"
    click B2 "https://github.com/khoaluongcode/hackathon-monday/blob/main/src/middleware.ts"
    click DB1 "https://github.com/khoaluongcode/hackathon-monday/blob/main/drizzle.config.ts"
    click DB2 "https://github.com/khoaluongcode/hackathon-monday/tree/main/src/server/db"
    click E1 "https://github.com/khoaluongcode/hackathon-monday/blob/main/src/server/gmail.ts"
    click E2 "https://github.com/khoaluongcode/hackathon-monday/blob/main/src/server/googleCalendar.ts"

    %% Styles
    classDef frontend fill:#a3d8f4,stroke:#1b80c8,stroke-width:2px;
    classDef backend fill:#f4a3a3,stroke:#c81b1b,stroke-width:2px;
    classDef database fill:#d0f4c3,stroke:#3c8b3c,stroke-width:2px;
    classDef external fill:#fef3a4,stroke:#cfa600,stroke-width:2px;
```
