# senqii/securejoin-server architecture

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

- Interactive diagram: https://gitdiagram.com/senqii/securejoin-server
- Repository: https://github.com/senqii/securejoin-server

## Overview

##### Project Type & Purpose
- This is a single-service backend (no frontend code).
- Its purpose is to provide secure, OTP-based joining and quiz data storage via a TypeScript API.
- It relies on Prisma migrations and a Supabase-hosted PostgreSQL database.

##### File Structure
- Top-level:
– package.json / pnpm-lock.yaml → Node.js/TypeScript service
– prisma/ → database schema + versioned migrations
– supabase/ → Supabase local config & migrations (remote schema)
– src/ → application code
- src/ layers:
– src/index.ts → HTTP server entry point
– src/auth/ → authentication & user models
– src/DB/ → Prisma client, OTP.ts, quizes.ts, index.ts
– src/words.ts → word-list utilities
– src/types/ → shared TypeScript types

##### README for Additional Insights
- Fully TypeScript for type safety
- Scalable architecture
- Assumes Node.js + npm/yarn

##### Main Components & Their Interactions
a. API Layer (src/index.ts)
- Listens for HTTP requests (e.g., Express/Fastify)
- Routes to controllers in auth/, DB/, words.ts
b. Auth Service (src/auth)
- Generates/validates one-time passwords (OTPs)
- Manages user registration/login
c. Quiz Service (src/DB/quizes.ts)
- CRUD operations for quiz data
- Tracks attempts & timestamps
d. ORM Layer (src/DB/index.ts & src/DB/client.ts)
- Exposes PrismaClient configured via prisma/schema.prisma
- Applies migrations (prisma/migrations)
e. Database (PostgreSQL via Supabase)
- Tables: User, OTP, Quiz, Attempts, etc.
- Supabase folder houses local config.toml and remote_schema migrations
f. Utility Layer (src/words.ts, src/types)
- Shared type definitions & word lists

##### Architectural Patterns & Design Principles
- Three-tier separation: API → Service/Business Logic → Data Access
- Modular code: each feature in its own directory (auth, DB, types)
- Infrastructure as code: Prisma migrations + Supabase migrations co-exist but serve the same PostgreSQL instance
- Type safety end-to-end: TS types in src/types reused across layers

## Diagram (Mermaid)

```mermaid
flowchart BT
    %% External Clients
    Clients["HTTP Clients (External)"]:::external

    %% API Server
    subgraph "API Server" 
        API["src/index.ts\n(HTTP Server)"]:::code
        subgraph "Auth Service"
            AuthIndex["index.ts"]:::code
            AuthUser["user.ts"]:::code
        end
        QuizService["quizes.ts\n(Quiz Service)"]:::code
        OTPService["OTP.ts\n(OTP Data Service)"]:::code
        Utilities["Utilities\n(src/words.ts, src/types)"]:::code
    end

    %% ORM Layer
    subgraph "ORM Layer\n(Prisma Client)" 
        ORMClient["client.ts"]:::code
        ORMIndex["index.ts"]:::code
    end

    %% Database
    DB["PostgreSQL Database\n(Supabase Postgres)"]:::db

    %% Dev Infrastructure
    subgraph "Dev Infrastructure" 
        Schema["schema.prisma"]:::dev
        Migrations["prisma/migrations/"]:::dev
        SupaConfig["supabase/config.toml"]:::dev
        SupaMigrations["supabase/migrations/"]:::dev
    end

    %% Connections
    Clients -->|"REST API calls"| API
    API -->|"calls"| AuthIndex
    API -->|"calls"| QuizService
    API -->|"calls"| OTPService
    API -->|"calls"| Utilities

    AuthIndex -->|"uses"| ORMIndex
    QuizService -->|"uses"| ORMIndex
    OTPService -->|"uses"| ORMIndex

    ORMIndex -->|"executes SQL over TCP"| DB

    Schema -.->|"migrations applied"| DB
    Migrations -.->|"versioned migrations"| DB
    SupaConfig -.->|"configures"| DB
    SupaMigrations -.->|"remote schema migrations"| DB

    %% Click Events
    click API "https://github.com/senqii/securejoin-server/blob/main/src/index.ts"
    click AuthIndex "https://github.com/senqii/securejoin-server/blob/main/src/auth/index.ts"
    click AuthUser "https://github.com/senqii/securejoin-server/blob/main/src/auth/user.ts"
    click QuizService "https://github.com/senqii/securejoin-server/blob/main/src/DB/quizes.ts"
    click OTPService "https://github.com/senqii/securejoin-server/blob/main/src/DB/OTP.ts"
    click ORMClient "https://github.com/senqii/securejoin-server/blob/main/src/DB/clinet.ts"
    click ORMIndex "https://github.com/senqii/securejoin-server/blob/main/src/DB/index.ts"
    click Schema "https://github.com/senqii/securejoin-server/blob/main/prisma/schema.prisma"
    click Migrations "https://github.com/senqii/securejoin-server/tree/main/prisma/migrations/"
    click SupaConfig "https://github.com/senqii/securejoin-server/blob/main/supabase/config.toml"
    click SupaMigrations "https://github.com/senqii/securejoin-server/tree/main/supabase/migrations/"

    %% Styles
    classDef code fill:#c3dafe,stroke:#2b6cb0,stroke-width:1px,color:#2c5282;
    classDef db fill:#f0fff4,stroke:#48bb78,stroke-width:1px,color:#2f855a;
    classDef dev fill:#edf2f7,stroke:#a0aec0,stroke-width:1px,color:#4a5568;
    classDef external fill:#fefcbf,stroke:#d69e2e,stroke-width:1px,color:#b7791f;
```
