# shseok/mztrees architecture

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

- Interactive diagram: https://gitdiagram.com/shseok/mztrees
- Repository: https://github.com/shseok/mztrees

## Overview

##### Main Components Identification

The system consists of three major parts:
- Frontend (mz-client): Next.js-based web application
- Backend (mz-server): Fastify-based API server
- Infrastructure: AWS-based cloud infrastructure

Use the following visual elements:
- Blue rectangles for frontend components
- Green rectangles for backend services
- Yellow diamonds for databases
- Red hexagons for external services
- Gray clouds for AWS infrastructure

##### Component Relationships

Following flows:
- User authentication flow
- Content creation and management flow
- Search and discovery flow
- Bookmark management flow
- Comment system flow

##### Additional Elements

Include:
- Load balancers
- Security groups
- VPC boundaries
- Caching layers
- External service integrations (Algolia)

##### Deployment Flow

Show:
- GitHub Actions workflow
- Terraform infrastructure provisioning
- Container deployment process
- Database migration flow

##### Notes

Annotations for:
- Scaling considerations
- Security implementations
- Performance optimizations
- Monitoring points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE[Next.js Frontend]
        Auth["Authentication System"]:::frontend
        Search["Search Functionality"]:::frontend
        Bookmark["Bookmarking System"]:::frontend
        ItemMgmt["Item Management"]:::frontend
        Comment["Comment System"]:::frontend
    end

    subgraph "API Layer"
        AuthAPI["/api/auth"]:::api
        ItemsAPI["/api/items"]:::api
        BookmarksAPI["/api/bookmarks"]:::api
        SearchAPI["/api/search"]:::api
        LinkAPI["/api/link"]:::api
        MeAPI["/api/me"]:::api
    end

    subgraph "Service Layer"
        UserSvc["User Service"]:::service
        ItemSvc["Item Service"]:::service
        BookmarkSvc["Bookmark Service"]:::service
        CommentSvc["Comment Service"]:::service
        LinkSvc["Link Service"]:::service
        ImageSvc["Image Service"]:::service
    end

    subgraph "Data Layer"
        DB[(PostgreSQL)]:::database
        PrismaORM["Prisma ORM"]:::orm
        Algolia["Algolia Search"]:::external
    end

    subgraph "AWS Infrastructure"
        ECS["ECS/ECR"]:::aws
        EC2["EC2"]:::aws
        LB["Load Balancer"]:::aws
    end

    %% Frontend to API connections
    Auth --> AuthAPI
    Search --> SearchAPI
    Bookmark --> BookmarksAPI
    ItemMgmt --> ItemsAPI
    Comment --> ItemsAPI

    %% API to Service connections
    AuthAPI --> UserSvc
    ItemsAPI --> ItemSvc
    BookmarksAPI --> BookmarkSvc
    SearchAPI --> Algolia
    LinkAPI --> LinkSvc
    MeAPI --> UserSvc

    %% Service to Data connections
    UserSvc --> PrismaORM
    ItemSvc --> PrismaORM
    BookmarkSvc --> PrismaORM
    CommentSvc --> PrismaORM
    LinkSvc --> PrismaORM
    ImageSvc --> PrismaORM

    PrismaORM --> DB
    
    %% AWS connections
    LB --> ECS
    ECS --> EC2
    EC2 --> DB

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e74c3c,stroke:#c0392b,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef aws fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef orm fill:#1abc9c,stroke:#16a085,color:white

    %% Click events
    click Auth "https://github.com/shseok/mztrees/tree/main/packages/mz-client/src/components/auth/"
    click Search "https://github.com/shseok/mztrees/tree/main/packages/mz-client/src/components/search/"
    click Bookmark "https://github.com/shseok/mztrees/tree/main/packages/mz-client/src/components/bookmark/"
    click ItemMgmt "https://github.com/shseok/mztrees/tree/main/packages/mz-client/src/components/items/"
    click Comment "https://github.com/shseok/mztrees/blob/main/packages/mz-client/src/components/items/CommentList.tsx"
    click AuthAPI "https://github.com/shseok/mztrees/tree/main/packages/mz-server/src/routes/api/auth/"
    click ItemsAPI "https://github.com/shseok/mztrees/tree/main/packages/mz-server/src/routes/api/items/"
    click BookmarksAPI "https://github.com/shseok/mztrees/tree/main/packages/mz-server/src/routes/api/bookmarks/"
    click SearchAPI "https://github.com/shseok/mztrees/tree/main/packages/mz-server/src/routes/api/search/"
    click LinkAPI "https://github.com/shseok/mztrees/tree/main/packages/mz-server/src/routes/api/link/"
    click UserSvc "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/services/user.service.ts"
    click ItemSvc "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/services/item.service.ts"
    click BookmarkSvc "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/services/bookmark.service.ts"
    click CommentSvc "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/services/comment.service.ts"
    click LinkSvc "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/services/link.service.ts"
    click ImageSvc "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/services/image.service.ts"
    click DB "https://github.com/shseok/mztrees/blob/main/packages/mz-server/prisma/schema.prisma"
    click PrismaORM "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/lib/db.ts"
    click Algolia "https://github.com/shseok/mztrees/blob/main/packages/mz-server/src/lib/algolia.ts"
```
