# muh-hamza-99/formify-api architecture

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

- Interactive diagram: https://gitdiagram.com/muh-hamza-99/formify-api
- Repository: https://github.com/muh-hamza-99/formify-api

## Overview

##### Main Components

A. API Layer
- Express.js Server (represented by app.js and server.js)
- Route Handlers (routes directory)
- Controllers (controllers directory)
- Middleware Components (middleware directory)

B. Database Layer
- PostgreSQL Database
- Prisma ORM Interface (prisma directory)

C. Utility Services
- Email Service (utilities/send-email.js)
- Authentication Services
- Error Handling
- Password Management

**[Client Applications] → [API Layer] → [Database Layer]**

##### Additional Elements

Containers to show:
- Docker containerization
- Environment separation
- External service connections (email)

##### Specific Implementation Details

Following key processes:
**[Form Submission] → [Route Validation] → [Controller Processing] → [Database Operation]**
- ↘ [Error Handling] ↗
- ↘ [Email Notification] ↗

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Applications]
    end

    subgraph API_Layer
        ES["Express Server"]:::server
        click ES "https://github.com/Muh-Hamza-99/formify-api/blob/master/app.js"

        subgraph Routes
            MR["Message Routes"]:::route
            RR["Route Routes"]:::route
            UR["User Routes"]:::route
            click MR "https://github.com/Muh-Hamza-99/formify-api/blob/master/routes/message-routes.js"
            click RR "https://github.com/Muh-Hamza-99/formify-api/blob/master/routes/route-routes.js"
            click UR "https://github.com/Muh-Hamza-99/formify-api/blob/master/routes/user-routes.js"
        end

        subgraph Controllers
            AC["Auth Controller"]:::controller
            MC["Message Controller"]:::controller
            RC["Route Controller"]:::controller
            UC["User Controller"]:::controller
            click AC "https://github.com/Muh-Hamza-99/formify-api/blob/master/controllers/auth-controllers.js"
            click MC "https://github.com/Muh-Hamza-99/formify-api/blob/master/controllers/message-controllers.js"
            click RC "https://github.com/Muh-Hamza-99/formify-api/blob/master/controllers/route-controllers.js"
            click UC "https://github.com/Muh-Hamza-99/formify-api/blob/master/controllers/user-controllers.js"
        end

        subgraph Middleware
            EH["Error Handler"]:::middleware
            P["Protect"]:::middleware
            RA["Restrict Admin"]:::middleware
            GM["Get Me"]:::middleware
            RO["Route Owner"]:::middleware
            click EH "https://github.com/Muh-Hamza-99/formify-api/blob/master/middleware/error-handler.js"
            click P "https://github.com/Muh-Hamza-99/formify-api/blob/master/middleware/protect.js"
            click RA "https://github.com/Muh-Hamza-99/formify-api/blob/master/middleware/restrict-to-admin.js"
            click GM "https://github.com/Muh-Hamza-99/formify-api/blob/master/middleware/get-me.js"
            click RO "https://github.com/Muh-Hamza-99/formify-api/blob/master/middleware/is-route-owner.js"
        end
    end

    subgraph Database_Layer
        DB[(PostgreSQL)]:::database
        PO["Prisma ORM"]:::database
        PM["Prisma Migrations"]:::database
        click PO "https://github.com/Muh-Hamza-99/formify-api/blob/master/database/prisma.js"
        click PM "https://github.com/Muh-Hamza-99/formify-api/tree/master/prisma/migrations/"
    end

    subgraph Utility_Services
        ES1["Email Service"]:::utility
        PM1["Password Management"]:::utility
        EH1["Error Handling"]:::utility
        MF["Message Formatter"]:::utility
        IV["Input Validator"]:::utility
        click ES1 "https://github.com/Muh-Hamza-99/formify-api/blob/master/utilities/send-email.js"
        click PM1 "https://github.com/Muh-Hamza-99/formify-api/blob/master/utilities/hash-password.js"
        click EH1 "https://github.com/Muh-Hamza-99/formify-api/blob/master/utilities/app-error.js"
        click MF "https://github.com/Muh-Hamza-99/formify-api/blob/master/utilities/format-message.js"
        click IV "https://github.com/Muh-Hamza-99/formify-api/blob/master/utilities/joi-validation.js"
    end

    subgraph Docker
        DC["Docker Container"]:::docker
        click DC "https://github.com/Muh-Hamza-99/formify-api/tree/master/Dockerfile"
    end

    %% Connections
    C -->|HTTP Requests| ES
    ES --> Routes
    Routes --> Controllers
    Controllers --> Middleware
    Controllers -.-> Utility_Services
    Controllers --> PO
    PO --> DB
    PO --> PM

    %% Styles
    classDef server fill:#3498db
    classDef route fill:#2ecc71
    classDef controller fill:#e74c3c
    classDef middleware fill:#f1c40f
    classDef database fill:#9b59b6
    classDef utility fill:#e67e22
    classDef docker fill:#34495e

    %% Legend
    subgraph Legend
        L1["Server Component"]:::server
        L2["Route Handler"]:::route
        L3["Controller"]:::controller
        L4["Middleware"]:::middleware
        L5["Database"]:::database
        L6["Utility"]:::utility
        L7["Docker"]:::docker
    end
```
