# rohatin/backoffice-fe architecture

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

- Interactive diagram: https://gitdiagram.com/rohatin/backoffice-fe
- Repository: https://github.com/rohatin/backoffice-fe

## Overview

##### Main Components

A. Frontend Layer:
- Client Application (React)
- Core Components (/src/components)
- Protected Routes (/src/routes/(protected))
- Public Routes (/src/routes/login)
- State Management (Context API - /src/store)
- Custom Hooks (/src/hooks)

B. API Layer:
- Authentication Service (Auth.js + Hono)
- API Routes (/api)
- SDK Integration Layer

C. External Services:
- Transaction Processing System
- User Management System

**[Frontend Layer]**
- ↓↑
**[API Gateway/SDK Layer]**
- ↓↑
**[Backend Services]**

##### Component Relationships to Highlight

a. Authentication Flow:
- LoginForm → Auth.js → Protected Routes
- Token Refresh Mechanism (useTokenRefresh)
- Role-based Access Control (usePermissions)

b. Data Flow:
- User Management (UserTable → API → Database)
- Transaction Processing (TransactionHistory → API → Transaction System)
- Role Management (CreateRoleForm/EditRole → API → User System)

##### Specific Implementation Details

- Rectangle: UI Components
- Hexagon: API Endpoints
- Diamond: Authentication Services

- Blue: Frontend Components
- Green: API Services
- Yellow: Authentication
- Purple: External Services
- Red: Critical Security Boundaries

##### Key Architectural Patterns to Emphasize

a. Component Architecture:
- Custom Components (/src/components/custom)
- UI Components (/src/components/ui)
- Protected Routes Pattern

b. State Management:
- Context API Implementation
- Server State (TanStack Query)
- Custom Hooks Pattern

##### Technical Stack Integration

Clear connections between:
- React + TypeScript
- TanStack Router
- TanStack Query
- Auth.js
- Shadcn UI Components

##### Security Layer

Highlight:
- Protected Routes
- Role-based Access
- Token Management
- API Key Implementation

Key Considerations:
##### State management flow using Context API

For this specific project, focus on showing how the frontend components interact with the API layer through the custom SDK, and how the authentication system protects various routes and functionalities.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[UI Components]:::frontend
        click UI "https://github.com/rohatin/backoffice-fe/tree/main/src/components/ui"
        
        subgraph Auth["Authentication Components"]
            LF[LoginForm]:::frontend
            click LF "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/LoginForm.tsx"
            PR[ProtectedRoute]:::frontend
            click PR "https://github.com/rohatin/backoffice-fe/blob/main/src/components/ProtectedRoute.tsx"
        end

        subgraph UserMgmt["User Management"]
            UT[UserTable]:::frontend
            click UT "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/(admin)/user/UserTable.tsx"
            EUD[EditUserDialog]:::frontend
            click EUD "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/(admin)/user/EditUserDialog.tsx"
            NUB[NewUserButton]:::frontend
            click NUB "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/(admin)/user/NewUserButton.tsx"
        end

        subgraph RoleMgmt["Role Management"]
            CRF[CreateRoleForm]:::frontend
            click CRF "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/(admin)/roles/CreateRoleForm.tsx"
            ER[EditRole]:::frontend
            click ER "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/(admin)/roles/EditRole.tsx"
        end

        subgraph TransSystem["Transaction Components"]
            TH[TransactionHistory]:::frontend
            click TH "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/TransactionHistory.tsx"
            AT[AddTransaction]:::frontend
            click AT "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/AddTransaction.tsx"
            TS[TransactionSummary]:::frontend
            click TS "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/(admin)/user/TransactionSummary.tsx"
        end

        subgraph Navigation
            AS[AppSidebar]:::frontend
            click AS "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/sidebar/AppSidebar.tsx"
            MN[MobileNav]:::frontend
            click MN "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/sidebar/MobileNav.tsx"
            UP[UserProfile]:::frontend
            click UP "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/sidebar/UserProfile.tsx"
        end
    end

    subgraph Hooks["Custom Hooks"]
        TR[useTokenRefresh]:::hook
        click TR "https://github.com/rohatin/backoffice-fe/blob/main/src/hooks/useTokenRefresh.ts"
        PM[usePermissions]:::hook
        click PM "https://github.com/rohatin/backoffice-fe/blob/main/src/hooks/usePermissions.ts"
        AU[useAllUsers]:::hook
        click AU "https://github.com/rohatin/backoffice-fe/blob/main/src/hooks/useAllUsers.ts"
        RH[useRoles]:::hook
        click RH "https://github.com/rohatin/backoffice-fe/blob/main/src/hooks/useRoles.ts"
        TRX[useTransaction]:::hook
        click TRX "https://github.com/rohatin/backoffice-fe/blob/main/src/hooks/useTransaction.ts"
    end

    subgraph State["State Management"]
        TC[TransactionContext]:::state
        click TC "https://github.com/rohatin/backoffice-fe/blob/main/src/store/TransactionContext.tsx"
        UTC[useTransactionContext]:::state
        click UTC "https://github.com/rohatin/backoffice-fe/blob/main/src/hooks/useTransactionContext.ts"
    end

    subgraph Routes["Protected Routes"]
        PL[ProtectedLayout]:::route
        click PL "https://github.com/rohatin/backoffice-fe/blob/main/src/components/custom/ProtectedLayout.tsx"
        AL["Admin Layout"]:::route
        click AL "https://github.com/rohatin/backoffice-fe/tree/main/src/routes/(protected)/_layout/(admin)/*"
        ML["Main Layout"]:::route
        click ML "https://github.com/rohatin/backoffice-fe/blob/main/src/routes/(protected)/_layout.tsx"
    end

    subgraph API["API Layer"]
        API[API Gateway]:::api
        click API "https://github.com/rohatin/backoffice-fe/blob/main/src/api/index.ts"
        AR["API Routes"]:::api
        click AR "https://github.com/rohatin/backoffice-fe/blob/main/src/api/[[...route]].ts"
    end

    %% Connections
    LF --> PR
    PR --> PL
    PL --> AL
    PL --> ML
    
    UT --> API
    EUD --> API
    NUB --> API
    
    CRF --> API
    ER --> API
    
    TH --> API
    AT --> API
    TS --> API
    
    API --> TC
    TC --> UTC
    
    TR --> API
    PM --> API
    AU --> API
    RH --> API
    TRX --> API

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef hook fill:#e74c3c,stroke:#c0392b,color:white
    classDef state fill:#2ecc71,stroke:#27ae60,color:white
    classDef route fill:#f1c40f,stroke:#f39c12,color:white
    classDef api fill:#9b59b6,stroke:#8e44ad,color:white
```
