# org-45/escrow-agent architecture

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

- Interactive diagram: https://gitdiagram.com/org-45/escrow-agent
- Repository: https://github.com/org-45/escrow-agent

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js application (shown in /frontend directory)
- Key pages: login, signup, home, upload
- API service integration

b) Backend Layer:
- Go-based REST API server
- Internal modules:
- Authentication system
- Admin management
- Escrow handling
- Transaction processing
- File upload service
- Logging system

c) Database Layer:
- PostgreSQL database (evident from db_init)

d) External Services:
- S3 bucket for document storage (mentioned in README)
- Payment gateway integration points
- BrowserStack for testing

**[Client Layer]**
- ↓ ↑
**[API Gateway/Load Balancer]**
- ↓ ↑
**[Application Layer]**
- ↓ ↑
**[Service Layer]**
- ↓ ↑
**[Database Layer]**

##### Component Relationships

Key interactions:
- User authentication flow
- Escrow transaction flow
- Document storage flow
- Payment processing flow
- Dispute resolution flow

##### Specific Implementation Details

Crucial elements:

a) Frontend Section:
- Next.js pages and components
- API service connector
- User interface flows

b) Backend Services (Go):
- Auth Service (/internal/auth)
- Admin Service (/internal/admin)
- Escrow Service (/internal/escrow)
- Transaction Service (/internal/transactions)
- File Upload Service (/internal/fileupload)
- Logging Service (/internal/logs)

c) Database:
- PostgreSQL instance
- Key tables (users, transactions, escrows, disputes)

d) Security Layer:
- JWT authentication
- Middleware components
- Authorization flows

##### Key Flows to Highlight

Critical paths:
##### Escrow Transaction Flow
- Buyer deposit
- Seller fulfillment
- Buyer confirmation
- Fund release

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
        Mobile["Mobile Device"]
    end

    subgraph Frontend["Frontend Layer"]
        NextApp["Next.js Application"]:::frontend
        Pages["Pages (Home/Login/Signup/Upload)"]:::frontend
        APIService["API Service Integration"]:::frontend
    end

    subgraph Gateway["API Gateway"]
        LoadBalancer["Load Balancer"]:::infra
        AuthMiddleware["Auth Middleware"]:::security
    end

    subgraph Backend["Backend Services"]
        direction TB
        AuthService["Authentication Service"]:::security
        AdminService["Admin Management"]:::backend
        EscrowService["Escrow Service"]:::backend
        TransactionService["Transaction Service"]:::backend
        FileUploadService["File Upload Service"]:::backend
        LoggingService["Logging Service"]:::backend
        ProfileService["Profile Service"]:::backend
    end

    subgraph Storage["Storage Layer"]
        PostgreSQL[(PostgreSQL Database)]:::database
        S3["S3 Storage"]:::external
    end

    subgraph External["External Services"]
        PaymentGateway["Payment Gateway"]:::external
        BrowserStack["BrowserStack Testing"]:::external
    end

    %% Relationships
    Browser --> NextApp
    Mobile --> NextApp
    NextApp --> Pages
    NextApp --> APIService
    APIService --> LoadBalancer
    LoadBalancer --> AuthMiddleware
    AuthMiddleware --> AuthService
    AuthMiddleware --> AdminService
    AuthMiddleware --> EscrowService
    AuthMiddleware --> TransactionService
    AuthMiddleware --> FileUploadService
    AuthMiddleware --> ProfileService

    AuthService --> PostgreSQL
    AdminService --> PostgreSQL
    EscrowService --> PostgreSQL
    TransactionService --> PostgreSQL
    ProfileService --> PostgreSQL
    
    FileUploadService --> S3
    TransactionService --> PaymentGateway
    LoggingService --> PostgreSQL

    %% Click Events
    click NextApp "https://github.com/org-45/escrow-agent/tree/main/frontend"
    click Pages "https://github.com/org-45/escrow-agent/tree/main/frontend/src/pages"
    click APIService "https://github.com/org-45/escrow-agent/blob/main/frontend/src/services/api.ts"
    click AuthMiddleware "https://github.com/org-45/escrow-agent/blob/main/internal/middleware/auth.go"
    click AuthService "https://github.com/org-45/escrow-agent/tree/main/internal/auth"
    click AdminService "https://github.com/org-45/escrow-agent/blob/main/internal/admin/admin.go"
    click EscrowService "https://github.com/org-45/escrow-agent/blob/main/internal/escrow/escrow.go"
    click TransactionService "https://github.com/org-45/escrow-agent/blob/main/internal/transactions/transactions.go"
    click FileUploadService "https://github.com/org-45/escrow-agent/blob/main/internal/fileupload/upload.go"
    click LoggingService "https://github.com/org-45/escrow-agent/blob/main/internal/logs/logs.go"
    click ProfileService "https://github.com/org-45/escrow-agent/blob/main/internal/profile/profile.go"
    click PostgreSQL "https://github.com/org-45/escrow-agent/blob/main/db_init/init-db.sql"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend"]:::backend
        Security_L["Security"]:::security
        Database_L["Database"]:::database
        External_L["External"]:::external
        Infrastructure_L["Infrastructure"]:::infra
    end
```
