# amaghe/tenant-trakker-pro architecture

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

- Interactive diagram: https://gitdiagram.com/amaghe/tenant-trakker-pro
- Repository: https://github.com/amaghe/tenant-trakker-pro

## Overview

##### Project type and purpose
- This is a full-stack, single-page application for property and tenant management with integrated MTN Mobile Money (“MoMo”) payments.
- Frontend: Vite + React + TypeScript + shadcn-ui + Tailwind CSS.
- Backend: Supabase (Postgres DB, Auth, Serverless Functions) plus external MTN MoMo API.

##### File structure
- Top-level:
- src/ – React application source (pages, components, hooks, services, integrations, lib)
- public/ – static assets and redirect rules
- supabase/ – configuration, database migrations, and serverless functions
- Recognizable patterns:
- “src/pages” & “src/components” → component-based React UI (SPA)
- “src/integrations/supabase” → Supabase client SDK wrapper
- “supabase/functions” → grouped serverless endpoints handling payment requests, callbacks, logging
- “supabase/migrations” → SQL scripts for schema versioning

##### README for additional insights
- Tech stack confirmed: Vite, TS, React, shadcn-ui, Tailwind
- Deployment: Lovable platform publishes the static frontend and orchestrates Supabase
- Webhook details for MTN MoMo callbacks (URL, secret header, JSON payload fields)

a. Main components
1. Browser (Client SPA)
2. Supabase Auth & Postgres Database
3. Supabase Serverless Functions
4. External MTN MoMo API
5. CI/CD / Migrations pipeline
b. Relationships & interactions
- User → SPA: HTTP/HTTPS, React Router navigates pages (Auth, Dashboard, Payments, Tenants…)
- SPA ↔ Supabase Auth: sign-in/sign-up via Supabase client
- SPA ↔ Supabase Database: CRUD calls through Supabase client for tenants, properties, payments
- SPA → Supabase Function “mtn-momo-request-payment”: initiate MoMo payment
- Function → MTN MoMo API: REST call to request payment
- MTN MoMo API → Function “mtn-momo-callback” (webhook): payment status update
- Function writes status to Supabase DB → Real-time updates push to SPA via Supabase subscriptions
- Debug & logging functions: capture events, errors
c. Architectural patterns & design principles
- SPA client-server pattern
- Serverless microservices (one function per endpoint)
- Event-driven updates (webhooks + real-time DB subscriptions)
- Separation of concerns: UI, data layer, payment orchestration
d. Key technologies & libraries
- Frontend: React, shadcn-ui (UI primitives), Vite, Tailwind CSS
- Data & Auth: @supabase/supabase-js
- Serverless: Supabase Edge Functions (TypeScript)
- External Service: MTN MoMo REST API

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        Browser["User Browser"]:::frontend
        SPA["React SPA"]:::frontend
    end

    %% Supabase Services Layer
    subgraph "Supabase Services"
        direction TB
        Auth["Supabase Auth"]:::backend
        DB["Postgres Database"]:::db

        subgraph "Payment Functions"
            direction TB
            mtnRequest["mtn-momo-request-payment"]:::backend
            mtnCallback["mtn-momo-callback"]:::backend
            mtnStatus["mtn-momo-transaction-status"]:::backend
            mtnInvoice["mtn-momo-invoice"]:::backend
            mtnCreateInvoice["mtn-momo-invoice-CreateInvoice"]:::backend
            mtnInvoiceStatus["mtn-momo-invoice-status"]:::backend
            mtnCancelInvoice["mtn-momo-cancel-invoice"]:::backend
            mtnBalance["mtn-momo-balance"]:::backend
            debugLogger["debug-logger"]:::backend
        end
    end

    %% External API Layer
    subgraph "External MTN MoMo API"
        MTN["MTN MoMo REST API"]:::external
    end

    %% CI/CD & Migrations
    CICD["CI/CD & Migrations"]:::backend

    %% Connections
    Browser -->|"HTTP/HTTPS"| SPA
    SPA -->|"Sign-in/Sign-up"| Auth
    SPA -->|"CRUD via @supabase/supabase-js"| DB
    SPA -->|"POST /functions/v1/mtn-momo-request-payment"| mtnRequest
    mtnRequest -->|"REST call"| MTN
    MTN -.->|"Webhook POST /functions/v1/mtn-momo-callback"| mtnCallback
    mtnCallback -->|"Write status"| DB
    DB -->|"Real-time subscriptions"| SPA
    CICD -->|"Deploy migrations & functions"| Auth
    CICD -->|"Deploy migrations & functions"| DB
    CICD -->|"Deploy migrations & functions"| mtnRequest

    %% Click Events
    click SPA "https://github.com/amaghe/tenant-trakker-pro/blob/main/src/main.tsx"
    click SPA "https://github.com/amaghe/tenant-trakker-pro/blob/main/src/App.tsx"
    click mtnRequest "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-request-payment/index.ts"
    click mtnCallback "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-callback/index.ts"
    click mtnStatus "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-transaction-status/index.ts"
    click mtnInvoice "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-invoice/index.ts"
    click mtnCreateInvoice "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-invoice-CreateInvoice/index.ts"
    click mtnInvoiceStatus "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-invoice-status/index.ts"
    click mtnCancelInvoice "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-cancel-invoice/index.ts"
    click mtnBalance "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/mtn-momo-balance/index.ts"
    click debugLogger "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/functions/debug-logger/index.ts"
    click CICD "https://github.com/amaghe/tenant-trakker-pro/blob/main/supabase/config.toml"
    click CICD "https://github.com/amaghe/tenant-trakker-pro/tree/main/supabase/migrations/"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0366d6,color:#0366d6,stroke-width:1px;
    classDef backend fill:#d1e7dd,stroke:#198754,color:#0f5132,stroke-width:1px;
    classDef db fill:#d1e7dd,stroke:#198754,color:#0f5132,stroke-width:1px;
    classDef external fill:#ffe5b4,stroke:#d97706,color:#92400e,stroke-width:1px;
```
