# equalifyeverything/equalify-api architecture

> Architecture diagram of the GitHub repository equalifyeverything/equalify-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/equalifyeverything/equalify-api
- Repository: https://github.com/equalifyeverything/equalify-api

## Overview

##### Main Components

a) Client Layer
- External clients (Web applications, API consumers)
- Postman collection integration point

b) AWS Lambda Environment
- Fastify Server Instance
- Main application container

c) Core Service Groups
- Authentication Services (Cognito integration)
- Route Handlers
- Internal Processors
- Scheduled Tasks
- Utility Services

d) External Services Integration
- OpenAI Integration (noted from utils/openai.ts)
- GraphQL Services (noted from utils/graphql.ts)
- Database Layer (from utils/db.ts)

##### Component Relationships and Structure

**[Client Layer]**
- ↓
**[API Gateway/Lambda]**
- ↓
**[Fastify Server]**
- ↓
**[Core Services]**

##### Detailed Component Breakdown

a) Route Handlers (src/routes/):
- Property Management
- Report Management
- Scan Management
- Results Management
- User Management
- Analytics (Charts)

b) Cognito Integration (src/cognito/):
- Authentication flows
- Custom message handling
- Token generation
- User confirmation processes

c) Internal Processors (src/internal/):
- Message and tag migration
- Scan processing

d) Scheduled Tasks (src/scheduled/):
- Minute-based tasks
- Fifteen-minute interval tasks

##### Flow Patterns to Highlight

- Authentication flows
- API request/response paths
- Scheduled task triggers
- Internal processing workflows

##### Additional Elements

- Environment indicators (Production/Staging/Local)
- Security boundaries
- Scaling points
- Monitoring/logging points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        Client["External Clients"]
        Postman["Postman Collection"]
    end

    subgraph "AWS Lambda Environment"
        AppEntry["Application Entry"]:::main
        Server["Fastify Server"]:::server
    end

    subgraph "Core Services"
        direction TB
        subgraph "Route Handlers"
            direction TB
            PropMgmt["Property Management"]:::route
            ReportMgmt["Report Management"]:::route
            ScanMgmt["Scan Management"]:::route
            ResultsMgmt["Results Management"]:::route
            Analytics["Analytics/Charts"]:::route
        end

        subgraph "Authentication Services"
            direction TB
            TokenGen["Token Generation"]:::auth
            SignUpFlow["Sign Up Flow"]:::auth
            PassReset["Password Reset"]:::auth
        end

        subgraph "Internal Processors"
            direction TB
            MsgMigration["Message Migration"]:::processor
            ScanProc["Scan Processing"]:::processor
        end

        subgraph "Scheduled Tasks"
            direction TB
            MinuteTasks["Minute Tasks"]:::scheduled
            FifteenMinTasks["Fifteen-Minute Tasks"]:::scheduled
        end

        subgraph "Utility Services"
            direction TB
            URLValid["URL Validation"]:::util
            EmailFormat["Email Formatting"]:::util
            EnvDetect["Environment Detection"]:::util
        end
    end

    subgraph "External Services"
        direction TB
        OpenAI["OpenAI Service"]:::external
        GraphQL["GraphQL Service"]:::external
        DB["Database Layer"]:::external
    end

    %% Relationships
    Client --> Server
    Postman --> Server
    Server --> AppEntry
    AppEntry --> PropMgmt & ReportMgmt & ScanMgmt & ResultsMgmt & Analytics
    PropMgmt & ReportMgmt & ScanMgmt & ResultsMgmt --> TokenGen
    TokenGen --> SignUpFlow
    TokenGen --> PassReset
    ScanMgmt --> ScanProc
    ScanProc --> MsgMigration
    MinuteTasks & FifteenMinTasks --> ScanProc
    PropMgmt & ReportMgmt & ScanMgmt & ResultsMgmt --> DB
    ScanProc --> OpenAI
    PropMgmt & ReportMgmt --> GraphQL

    %% Click Events
    click AppEntry "https://github.com/equalifyeverything/equalify-api/blob/main/src/app.ts"
    click TokenGen "https://github.com/equalifyeverything/equalify-api/blob/main/src/cognito/tokenGeneration.ts"
    click SignUpFlow "https://github.com/equalifyeverything/equalify-api/blob/main/src/cognito/customMessageSignUp.ts"
    click PassReset "https://github.com/equalifyeverything/equalify-api/blob/main/src/cognito/customMessageForgotPassword.ts"
    click PropMgmt "https://github.com/equalifyeverything/equalify-api/blob/main/src/routes/addProperties.ts"
    click ReportMgmt "https://github.com/equalifyeverything/equalify-api/blob/main/src/routes/addReports.ts"
    click ScanMgmt "https://github.com/equalifyeverything/equalify-api/blob/main/src/routes/addScans.ts"
    click ResultsMgmt "https://github.com/equalifyeverything/equalify-api/blob/main/src/routes/addResults.ts"
    click Analytics "https://github.com/equalifyeverything/equalify-api/blob/main/src/routes/getCharts.ts"
    click MsgMigration "https://github.com/equalifyeverything/equalify-api/blob/main/src/internal/migrateMessagesAndTags.ts"
    click ScanProc "https://github.com/equalifyeverything/equalify-api/blob/main/src/internal/processScans.ts"
    click MinuteTasks "https://github.com/equalifyeverything/equalify-api/blob/main/src/scheduled/runEveryMinute.ts"
    click FifteenMinTasks "https://github.com/equalifyeverything/equalify-api/blob/main/src/scheduled/runEveryFifteenMinutes.ts"
    click OpenAI "https://github.com/equalifyeverything/equalify-api/blob/main/src/utils/openai.ts"
    click GraphQL "https://github.com/equalifyeverything/equalify-api/blob/main/src/utils/graphql.ts"
    click DB "https://github.com/equalifyeverything/equalify-api/blob/main/src/utils/db.ts"
    click URLValid "https://github.com/equalifyeverything/equalify-api/blob/main/src/utils/validateUrl.ts"
    click EmailFormat "https://github.com/equalifyeverything/equalify-api/blob/main/src/utils/formatEmail.ts"
    click EnvDetect "https://github.com/equalifyeverything/equalify-api/blob/main/src/utils/isStaging.ts"

    %% Styles
    classDef main fill:#f9f,stroke:#333
    classDef server fill:#aaf,stroke:#333
    classDef route fill:#9f9,stroke:#333
    classDef auth fill:#ff9,stroke:#333
    classDef processor fill:#f99,stroke:#333
    classDef scheduled fill:#c9f,stroke:#333
    classDef util fill:#ccc,stroke:#333
    classDef external fill:#f66,stroke:#333

    %% Legend
    subgraph Legend
        Main["Main Components"]:::main
        ServerComp["Server Components"]:::server
        RouteComp["Route Handlers"]:::route
        AuthComp["Authentication"]:::auth
        ProcComp["Processors"]:::processor
        SchedComp["Scheduled Tasks"]:::scheduled
        UtilComp["Utilities"]:::util
        ExtComp["External Services"]:::external
    end
```
