# shahzain-lab/amplify-oauth2 architecture

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

- Interactive diagram: https://gitdiagram.com/shahzain-lab/amplify-oauth2
- Repository: https://github.com/shahzain-lab/amplify-oauth2

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js (using the new “app” directory) and AWS Amplify.
- The goal is to serve React pages, handle client-side authentication, and interact with cloud data resources (through Amplify).

##### File structure
- Top-level Next.js front-end (“app” folder):
- app/layout.tsx, app/page.tsx: root layout and home page
- app/signin/page.tsx + components/Signin.tsx + AuthClient.tsx + amplify-utils.ts: login flow
- globals.css, tailwind.config.ts, postcss.config.mjs: styling with Tailwind CSS
- AWS Amplify configuration (“amplify” folder):
- amplify/auth/resource.ts: Cognito auth resource definitions
- amplify/data/resource.ts: Data store (likely GraphQL/DynamoDB) definitions
- amplify/backend.ts + tsconfig.json + package.json: Amplify backend bootstrap
- Config files: next.config.mjs, tsconfig.json, .eslintrc.json

##### README
- Confirms a create-next-app scaffold

- Browser / Client (React running in user’s browser)
- Next.js Server (app router + server components)
- AWS Amplify Backend
– Cognito (Authentication)
– Data API (GraphQL or REST backed by DynamoDB)
- Dev tooling (Amplify CLI / Node build process)

1. User → Browser UI (HTTP/HTTPS)
2. Browser UI → Next.js Server (SSR/SSR data fetching)
3. Browser (AuthClient) → AWS Cognito (via Amplify SDK)
4. Browser (amplify-utils) → AWS Data API (GraphQL/REST calls)
5. Next.js Server (if using getServerSideProps or API routes) → Amplify backend (optional server-side calls)

c. Architectural patterns & design principles
- Full-stack separation: front-end (Next.js UI) vs. backend (AWS microservices).
- Server-side rendering (SSR) alongside client-side hydration for auth flows.
- Cloud-native backend using managed services (Cognito + GraphQL/DynamoDB).
- Infrastructure as code via Amplify resource.ts files.

d. Key technologies & libraries
- Next.js 13 (app router, server components)
- React & Tailwind CSS for UI
- AWS Amplify SDK for client-side calls
- AWS Cognito for user pools (authentication)
- AWS AppSync or API Gateway + DynamoDB for data (amplify/data)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Front-end Layer
    subgraph "Front-end" 
        direction TB
        U["User"]:::user
        B["Browser UI"]:::frontend
        U -->|interacts| B

        subgraph "Next.js Client Components"
            direction TB
            L["Root Layout"]:::frontend
            HP["Home Page"]:::frontend
            SIP["Sign-in Page"]:::frontend
            SIC["Signin Component"]:::frontend
            AC["AuthClient"]:::frontend
            AU["amplify-utils"]:::frontend
        end

        B -->|renders| L
        L -->|routes to| HP
        L -->|routes to| SIP
        SIP -->|uses| SIC
        SIC -->|calls| AC
        SIC -->|calls| AU
        AC -->|"AWS Cognito SDK"| Cog
        AU -->|"AWS Data API SDK"| DataAPI
    end

    %% Next.js Server Layer
    subgraph "Next.js Server" 
        direction TB
        NS["Next.js Server (SSR/API)"]:::server
    end

    B -->|page requests| NS
    NS -->|"SSR/Data Fetch"| DataAPI
    NS -->|"Auth Ops"| Cog

    %% Amplify Backend Layer
    subgraph "Amplify Backend" 
        direction TB
        Cog["Cognito User Pool"]:::aws
        DataAPI["GraphQL API & DynamoDB"]:::aws
    end

    %% Configuration & Build Tools
    subgraph "Configuration & Build Tools"
        direction TB
        GS["globals.css"]:::config
        TC["tailwind.config.ts"]:::config
        PC["postcss.config.mjs"]:::config
        NC["next.config.mjs"]:::config
        TS["tsconfig.json"]:::config
        ESL[".eslintrc.json"]:::config
        AB["amplify/backend.ts"]:::config
        AP["amplify/package.json"]:::config
        ATS["amplify/tsconfig.json"]:::config
        BD["Build/Deploy"]:::tool
        GS --> BD
        TC --> BD
        PC --> BD
        NC --> BD
        TS --> BD
        ESL --> BD
        AB --> BD
        AP --> BD
        ATS --> BD
        BD --> NS
        BD --> DataAPI
        BD --> Cog
    end

    %% Click Events
    click L "https://github.com/shahzain-lab/amplify-oauth2/blob/master/app/layout.tsx"
    click HP "https://github.com/shahzain-lab/amplify-oauth2/blob/master/app/page.tsx"
    click SIP "https://github.com/shahzain-lab/amplify-oauth2/blob/master/app/signin/page.tsx"
    click SIC "https://github.com/shahzain-lab/amplify-oauth2/blob/master/app/components/Signin.tsx"
    click AC "https://github.com/shahzain-lab/amplify-oauth2/blob/master/app/components/AuthClient.tsx"
    click AU "https://github.com/shahzain-lab/amplify-oauth2/blob/master/app/components/amplify-utils.ts"
    click GS "https://github.com/shahzain-lab/amplify-oauth2/blob/master/app/globals.css"
    click TC "https://github.com/shahzain-lab/amplify-oauth2/blob/master/tailwind.config.ts"
    click PC "https://github.com/shahzain-lab/amplify-oauth2/blob/master/postcss.config.mjs"
    click NC "https://github.com/shahzain-lab/amplify-oauth2/blob/master/next.config.mjs"
    click TS "https://github.com/shahzain-lab/amplify-oauth2/blob/master/tsconfig.json"
    click ESL "https://github.com/shahzain-lab/amplify-oauth2/blob/master/.eslintrc.json"
    click Cog "https://github.com/shahzain-lab/amplify-oauth2/blob/master/amplify/auth/resource.ts"
    click DataAPI "https://github.com/shahzain-lab/amplify-oauth2/blob/master/amplify/data/resource.ts"
    click AB "https://github.com/shahzain-lab/amplify-oauth2/blob/master/amplify/backend.ts"
    click AP "https://github.com/shahzain-lab/amplify-oauth2/blob/master/amplify/package.json"
    click ATS "https://github.com/shahzain-lab/amplify-oauth2/blob/master/amplify/tsconfig.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef server fill:#FFE8D0,stroke:#D97706,color:#D97706
    classDef aws fill:#D0FFD6,stroke:#059669,color:#059669
    classDef config fill:#F0F0F0,stroke:#6B7280,color:#374151
    classDef user fill:#E2E8F0,stroke:#1E40AF,color:#1E40AF
    classDef tool fill:#FDF2F8,stroke:#DB2777,color:#DB2777
```
