# tegonhq/tegon architecture

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

- Interactive diagram: https://gitdiagram.com/tegonhq/tegon
- Repository: https://github.com/tegonhq/tegon

## Overview

##### High-Level Components
The system consists of several major components that should be represented as distinct sections:

a) Frontend Layer:
- Next.js Web Application (apps/webapp)
- React Components and Modules
- UI Component Library (packages/ui)

b) Backend Layer:
- NestJS Server (apps/server)
- Database (Prisma ORM)
- Authentication Services
- WebSocket Services

c) Integration Layer:
- Actions System
- External Service Connectors (GitHub, Slack, Discord, Email)
- Webhook Handlers

d) Storage Layer:
- Database (PostgreSQL)
- File Storage (for attachments)

##### Key Relationships and Data Flow

- Client-Server Communication
- WebSocket Real-time Updates
- External Integration Flows
- Authentication Flows
- Action Trigger Flows

##### Detailed Component Breakdown

Frontend Components:
**┌─ Web Application**
- Issue Management
- Project Management
- Team Collaboration
- Views & Filters
- Real-time Updates

Backend Services:
**┌─ API Server**
- Issue Service
- User Service
- Team Service
- Project Service
- Action Service
- Integration Service

Integration Layer:
**┌─ Actions System**
- Trigger Handlers
- Workflow Engine
- External Connectors

##### Important Technical Details

- REST API endpoints
- WebSocket connections
- Database relationships
- Authentication flow
- Action trigger points
- External service webhooks
- File storage integration

##### Architectural Patterns to Highlight

- Microservices Architecture
- Event-Driven System
- Real-time Updates
- Modular Component Structure
- Integration Patterns

##### Notes Section

Annotations for:
- Scaling considerations
- Security implementations
- Performance optimizations
- Integration requirements
- Deployment considerations

This system design should emphasize:
##### Scalability aspects

Remember to maintain clarity while showing complexity, and use appropriate abstraction levels depending on the audience's technical expertise.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        WebApp["Next.js Web Application"]:::frontend
        ReactComp["React Components"]:::frontend
        UILib["UI Component Library"]:::frontend
        WebApp --> ReactComp
        WebApp --> UILib
    end

    subgraph Backend
        NestServer["NestJS Server"]:::backend
        AuthService["Authentication Services"]:::backend
        WSService["WebSocket Services"]:::backend
        IssueService["Issue Service"]:::backend
        TeamService["Team Service"]:::backend
        ProjectService["Project Service"]:::backend
        IntegrationService["Integration Service"]:::backend
        
        NestServer --> AuthService
        NestServer --> WSService
        NestServer --> IssueService
        NestServer --> TeamService
        NestServer --> ProjectService
        NestServer --> IntegrationService
    end

    subgraph Integration
        ActionSystem["Actions System"]:::integration
        WebhookHandler["Webhook Handlers"]:::integration
        
        subgraph Connectors
            GitHub["GitHub Connector"]:::connector
            Slack["Slack Connector"]:::connector
            Discord["Discord Connector"]:::connector
            Email["Email Connector"]:::connector
        end
        
        ActionSystem --> GitHub
        ActionSystem --> Slack
        ActionSystem --> Discord
        ActionSystem --> Email
        WebhookHandler --> ActionSystem
    end

    subgraph Storage
        Database[(PostgreSQL)]:::storage
        FileStorage["File Storage"]:::storage
        PrismaORM["Prisma ORM"]:::storage
        
        PrismaORM --> Database
        FileStorage --> Database
    end

    %% Main connections
    WebApp <--> NestServer
    WebApp <--> WSService
    NestServer <--> PrismaORM
    IntegrationService <--> ActionSystem
    
    %% Click events
    click WebApp "https://github.com/tegonhq/tegon/tree/main/apps/webapp/"
    click ReactComp "https://github.com/tegonhq/tegon/tree/main/apps/webapp/src/components/"
    click UILib "https://github.com/tegonhq/tegon/tree/main/packages/ui/"
    click NestServer "https://github.com/tegonhq/tegon/tree/main/apps/server/"
    click PrismaORM "https://github.com/tegonhq/tegon/tree/main/apps/server/prisma/"
    click AuthService "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/auth/"
    click WSService "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/sync/"
    click ActionSystem "https://github.com/tegonhq/tegon/tree/main/actions/"
    click GitHub "https://github.com/tegonhq/tegon/tree/main/actions/github/"
    click Slack "https://github.com/tegonhq/tegon/tree/main/actions/slack/"
    click Discord "https://github.com/tegonhq/tegon/tree/main/actions/discord/"
    click Email "https://github.com/tegonhq/tegon/tree/main/actions/email/"
    click WebhookHandler "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/webhook/"
    click FileStorage "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/attachments/"
    click IssueService "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/issues/"
    click TeamService "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/teams/"
    click ProjectService "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/projects/"
    click IntegrationService "https://github.com/tegonhq/tegon/tree/main/apps/server/src/modules/integrations/"

    %% Styling
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef integration fill:#FF9800,stroke:#EF6C00,color:white
    classDef connector fill:#9E9E9E,stroke:#616161,color:white
    classDef storage fill:#FFC107,stroke:#FFA000,color:black

    %% Legend
    subgraph Legend
        Frontend_L[Frontend]:::frontend
        Backend_L[Backend]:::backend
        Integration_L[Integration]:::integration
        Connector_L[External Connector]:::connector
        Storage_L[Storage]:::storage
    end
```
