# impradp/lease-pixie-frontend architecture

> Architecture diagram of the GitHub repository impradp/lease-pixie-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/impradp/lease-pixie-frontend
- Repository: https://github.com/impradp/lease-pixie-frontend

## Overview

##### Project type and purpose
- This is a full-stack TypeScript web application built on Next.js (App Router).
- It provides a client-side UI (React) with server-side rendering and edge middleware, integrates with multiple backend microservices (account, auth, portfolio, property, vendor, Plaid, etc.), and is deployed via CI/CD (Azure/Vercel).

##### File structure
- Top level:
- `app/`—Next.js pages and layouts (client & server components).
- `components/`—reusable UI building blocks.
- `lib/`—API wrappers, middleware, shared services and utilities.
- `config/` & `data/`—static configuration and reference data.
- `middleware.ts`—global edge middleware (auth gating).
- CI/CD: `.github/workflows/azure-ci-cd.yml`.
- Patterns:
- Layered architecture: UI → page → component → service → external API.
- Next.js App Router for SSR/SSG and client/server boundary.
- Clear separation of concerns: UI, data services, middleware.

##### README for additional insights
- Confirms use of create-next-app, Next.js App Router, optimized fonts, Vercel deployment.
- No built-in database—backend concerns are delegated to external services.

a. Main components
1. Browser (end user).
2. CDN / Edge (Vercel, static assets, SSR edge functions).
3. Next.js Application
- Client Components (charts, forms, navigation).
- Server Components (data fetching, page rendering).
- Global Middleware (auth guard).
4. API Layer (`lib/api.ts`, `lib/services/*`)
5. External Backend Microservices (account, auth, depositAccount, email, login, portfolio, property, user, vendor).
6. Third-Party Services (Plaid).

b. Relationships and interactions
- Browser ↔ CDN/Edge ↔ Next.js:
– Static asset requests served by CDN.
– Page requests are routed to SSR/Edge functions.
- Next.js Server Components + Middleware → API Layer:
– `middleware.ts` enforces authentication.
– Server Components call `lib/services/*` wrappers.
- API Layer → External Microservices:
– HTTP/REST calls (endpoints defined in `lib/constants/endpoints.ts`).
- Some Client Components call API Layer directly via fetch or next/link transitions.
- Next.js may also proxy certain API calls through its own API Routes (if implemented).
- Plaid Integration: Service wrapper in `lib/services/plaid.ts` interacts with Plaid’s API.

c. Architectural patterns/design principles
- Layered/hexagonal architecture—UI, application (pages), domain (services), infrastructure (external APIs).
- Next.js App Router separates client vs server.
- Centralized service layer abstracts external APIs.
- DRY UI components in `components/ui/*`.
- Middleware-based auth ensures secure server rendering.

d. Key technologies/frameworks/libraries
- Next.js (App Router) for SSR/SSG and routing.
- React + TypeScript for UI.
- Tailwind CSS (via `tailwind.config.ts`) for styling.
- Husky + lint/jest for Git hooks and testing.
- GitHub Actions for CI/CD to Azure/Vercel.
- Plaid SDK for financial integrations.

##### Elements
- Clear labels: Browser, CDN/Edge, Next.js App, Middleware, API Layer, Microservices, Plaid.
- UX flows (Browser → Next.js → Services).
- Data flows (Services → Microservices → DB or third party).
- Blue rectangles for Next.js components (Pages, Middleware).

##### Recommended breakdown of components
- Layer 1 (Client):
- Pages (`src/app/*`), UI Components (`components/*`).
- Layer 2 (Server):
- Middleware (`middleware.ts`), Server Components (`page.tsx` with server code).
- Layer 3 (Service/Integration):
- API wrappers (`lib/services/*`), Endpoint definitions (`lib/constants/endpoints.ts`).
- Layer 4 (External Systems):
- Auth Service, Account Service, Portfolio Service, Property Service, Vendor Service, Plaid API.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser(["Browser"]):::infra
        CDN(["CDN / Edge (Vercel)"]):::infra
        Pages(["Next.js Pages & Layouts"]):::frontend
        Components(["UI Components"]):::frontend
        PlaidClient(["PlaidLinkInitializer"]):::frontend
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        MiddlewareGlobal(["Global Edge Middleware"]):::middleware
        AuthMiddleware(["Auth Guard"]):::middleware
        ApiMiddleware(["API Middleware"]):::middleware
        ServerComponents(["Server Components (page.tsx)"]):::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        ApiEntry(["API Layer Entry Point"]):::service
        Endpoints(["API Endpoint Definitions"]):::service
        Utils(["Utility Functions"]):::service
        Types(["Type Definitions"]):::service
    end

    %% Service Wrappers
    subgraph "Service Wrappers"
        direction TB
        AccountService(["Account Service"]):::service
        AuthService(["Auth Service"]):::service
        DepositService(["DepositAccount Service"]):::service
        EmailService(["Email Service"]):::service
        LoginService(["Login Service"]):::service
        PortfolioService(["Portfolio Service"]):::service
        PropertyService(["Property Service"]):::service
        UserService(["User Service"]):::service
        VendorService(["Vendor Service"]):::service
        PlaidService(["Plaid Integration Service"]):::service
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        AccountMicro(["Account Microservice"]):::external
        AuthMicro(["Auth Microservice"]):::external
        DepositMicro(["DepositAccount Microservice"]):::external
        EmailMicro(["Email Microservice"]):::external
        LoginMicro(["Login Microservice"]):::external
        PortfolioMicro(["Portfolio Microservice"]):::external
        PropertyMicro(["Property Microservice"]):::external
        UserMicro(["User Microservice"]):::external
        VendorMicro(["Vendor Microservice"]):::external
        PlaidAPI(["Plaid API"]):::external
    end

    CI_CD(["CI/CD Pipeline"]):::infra

    %% Connections
    Browser -->|"request"| CDN
    CDN -->|"serve pages/assets"| Pages
    Pages -->|"use"| Components
    Components -->|"initiate"| PlaidClient
    CDN -->|"invoke edge"| MiddlewareGlobal
    MiddlewareGlobal --> AuthMiddleware
    MiddlewareGlobal --> ApiMiddleware
    MiddlewareGlobal --> ServerComponents

    ServerComponents -->|"fetch data"| ApiEntry
    ApiEntry --> Endpoints
    ApiEntry --> Utils
    ApiEntry --> Types

    Endpoints --> AccountService
    Endpoints --> AuthService
    Endpoints --> DepositService
    Endpoints --> EmailService
    Endpoints --> LoginService
    Endpoints --> PortfolioService
    Endpoints --> PropertyService
    Endpoints --> UserService
    Endpoints --> VendorService
    Endpoints --> PlaidService

    AccountService -->|"HTTP calls"| AccountMicro
    AuthService -->|"HTTP calls"| AuthMicro
    DepositService -->|"HTTP calls"| DepositMicro
    EmailService -->|"HTTP calls"| EmailMicro
    LoginService -->|"HTTP calls"| LoginMicro
    PortfolioService -->|"HTTP calls"| PortfolioMicro
    PropertyService -->|"HTTP calls"| PropertyMicro
    UserService -->|"HTTP calls"| UserMicro
    VendorService -->|"HTTP calls"| VendorMicro
    PlaidService -->|"SDK/API calls"| PlaidAPI

    CI_CD --> CDN

    %% Click Events
    click Pages "https://github.com/impradp/lease-pixie-frontend/tree/master/src/app/"
    click Components "https://github.com/impradp/lease-pixie-frontend/tree/master/src/components/"
    click PlaidClient "https://github.com/impradp/lease-pixie-frontend/blob/master/src/components/plaid/PlaidLinkInitializer.tsx"
    click MiddlewareGlobal "https://github.com/impradp/lease-pixie-frontend/blob/master/middleware.ts"
    click AuthMiddleware "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/middleware/auth.ts"
    click ApiMiddleware "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/middleware/api.ts"
    click ApiEntry "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/api.ts"
    click Endpoints "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/constants/endpoints.ts"
    click AccountService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/account.ts"
    click AuthService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/auth.ts"
    click DepositService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/depositAccount.ts"
    click EmailService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/email.ts"
    click LoginService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/login.ts"
    click PortfolioService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/portfolio.ts"
    click PropertyService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/property.ts"
    click UserService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/user.ts"
    click VendorService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/vendor.ts"
    click PlaidService "https://github.com/impradp/lease-pixie-frontend/blob/master/src/lib/services/plaid.ts"
    click CI_CD "https://github.com/impradp/lease-pixie-frontend/blob/master/.github/workflows/azure-ci-cd.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef middleware fill:#FFA500,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef infra fill:#F0E68C,stroke:#333,stroke-width:1px
```
