# yorkie-team/codepair architecture

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

- Interactive diagram: https://gitdiagram.com/yorkie-team/codepair
- Repository: https://github.com/yorkie-team/codepair

## Overview

##### Main System Components

The system architecture should be divided into these primary components:

a. Frontend Layer (React Application)
- User Interface Components
- State Management (Redux)
- Real-time Collaboration Client
- Authentication Flow
- Document Editor
- AI Intelligence Interface

b. Backend Layer (NestJS Application)
- API Gateway
- Authentication Service
- Document Management
- Workspace Management
- AI Intelligence Service
- File Storage Service
- User Management

c. External Services & Dependencies
- GitHub OAuth
- MongoDB Database
- Yorkie Real-time Backend
- LangChain Integration
- File Storage System

##### Key Relationships to Highlight

Critical interactions:

**[Frontend Client] ←→ [API Gateway]**
- ←→ [Yorkie Real-time]
**[API Gateway] ←→ [Auth Service] ←→ [GitHub OAuth]**
- ←→ [Document Service] ←→ [MongoDB]
- ←→ [Workspace Service] ←→ [MongoDB]
- ←→ [Intelligence Service] ←→ [LangChain]

##### Detailed Component Breakdown

Frontend Components:
- Main modules: Editor, Workspace, Authentication, Settings
- Real-time collaboration integration
- State management flow

Backend Services:
- Auth Module: JWT, GitHub strategy
- Document Module: CRUD operations
- Workspace Module: User management, sharing
- Intelligence Module: AI features
- File Module: Storage operations

##### Technical Stack Callouts

- Frontend: React, Redux, TypeScript
- Backend: NestJS, Prisma
- Database: MongoDB
- Real-time: Yorkie
- AI: LangChain
- Authentication: JWT, GitHub OAuth

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI["UI Components"]:::frontend
        click UI "https://github.com/yorkie-team/codepair/tree/main/frontend/src/components/"
        Editor["Document Editor"]:::frontend
        click Editor "https://github.com/yorkie-team/codepair/tree/main/frontend/src/components/editor/"
        StateManagement["State Management"]:::frontend
        click StateManagement "https://github.com/yorkie-team/codepair/tree/main/frontend/src/store/"
        AIInterface["AI Intelligence Interface"]:::frontend
        click AIInterface "https://github.com/yorkie-team/codepair/blob/main/frontend/src/components/editor/YorkieIntelligence.tsx"
        RTClient["Real-time Client"]:::frontend
        click RTClient "https://github.com/yorkie-team/codepair/tree/main/frontend/src/utils/yorkie/"
        APILayer["API Integration"]:::frontend
        click APILayer "https://github.com/yorkie-team/codepair/tree/main/frontend/src/hooks/api/"
        
        UI --> StateManagement
        UI --> Editor
        Editor --> AIInterface
        Editor --> RTClient
        UI --> APILayer
    end

    subgraph Server
        Gateway["API Gateway"]:::backend
        
        AuthService["Authentication Service"]:::backend
        click AuthService "https://github.com/yorkie-team/codepair/tree/main/backend/src/auth/"
        
        DocService["Document Management"]:::backend
        click DocService "https://github.com/yorkie-team/codepair/tree/main/backend/src/documents/"
        
        WorkspaceService["Workspace Management"]:::backend
        click WorkspaceService "https://github.com/yorkie-team/codepair/tree/main/backend/src/workspaces/"
        
        AIService["AI Intelligence Service"]:::backend
        click AIService "https://github.com/yorkie-team/codepair/tree/main/backend/src/intelligence/"
        
        FileService["File Storage Service"]:::backend
        click FileService "https://github.com/yorkie-team/codepair/tree/main/backend/src/files/"
        
        UserService["User Management"]:::backend
        click UserService "https://github.com/yorkie-team/codepair/tree/main/backend/src/users/"
        
        DBInterface["Database Interface"]:::backend
        click DBInterface "https://github.com/yorkie-team/codepair/blob/main/backend/src/db/prisma.service.ts"

        Gateway --> AuthService
        Gateway --> DocService
        Gateway --> WorkspaceService
        Gateway --> AIService
        Gateway --> FileService
        Gateway --> UserService
        
        DocService --> DBInterface
        WorkspaceService --> DBInterface
        UserService --> DBInterface
    end

    subgraph External
        GitHub["GitHub OAuth"]:::external
        click GitHub "https://github.com/yorkie-team/codepair/blob/main/backend/src/auth/github.strategy.ts"
        
        MongoDB[(MongoDB)]:::database
        
        Yorkie["Yorkie Real-time"]:::external
        
        LangChain["LangChain"]:::external
        click LangChain "https://github.com/yorkie-team/codepair/blob/main/backend/src/langchain/langchain.module.ts"
        
        Storage["File Storage"]:::external
    end

    APILayer --> Gateway
    RTClient --> Yorkie
    AuthService --> GitHub
    DBInterface --> MongoDB
    AIService --> LangChain
    FileService --> Storage

    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef database fill:#FFC107,color:black
    classDef external fill:#9E9E9E,color:white

    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Service"]:::backend
        DB["Database"]:::database
        Ext["External Service"]:::external
    end
```
