# tricksumo/cognitocourse architecture

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

- Interactive diagram: https://gitdiagram.com/tricksumo/cognitocourse
- Repository: https://github.com/tricksumo/cognitocourse

## Overview

##### Project Type and Purpose
- The overall repository bundles several projects that demonstrate full‐stack web applications with authentication features. For example, the “3-ReactSPA-BackendNodeJS” folder contains separate frontend (React with Vite) and backend (Node.js server) folders. Other projects (GoogleLoginCustom, ShareMyFile-Web-App, and UserPoolSDK) indicate additional, related implementations.
- The included README (“CognitoCourse”) details API interactions with AWS Cognito using both User Pool and Identity Pool flows, including examples for integration with Google as an identity provider. This suggests the central purpose is to illustrate and enable robust user authentication flows in web applications.

##### Analyzing the File Structure
- Notice that the repository separates frontend code and backend code in the “3-ReactSPA-BackendNodeJS” directory, indicating a clear separation of concerns—a typical full-stack design. Additionally, projects like “GoogleLoginCustom” and “UserPoolSDK” also follow a similar structure using Vite and React.
- There are configuration files (e.g., .env.example, vite.config.js, eslint.config.js) that hint at environment-specific parameters, build configurations, and code quality setups. On the backend, files such as “authMiddleware.js” and “server.js” suggest that authentication and API routing logic are handled in a modular manner.

##### Core Components and Relationships
- Frontend Components: For every SPA, the frontends (React-based in directories like “3-ReactSPA-BackendNodeJS/frontend”, “GoogleLoginCustom/src”, “ShareMyFile-Web-App/src”, etc.) will represent the client layer. They likely handle user authentication (e.g., login, token storage, and redirection) and interactions with the backend.
- Backend Components: The NodeJS backend (found in “3-ReactSPA-BackendNodeJS/backend”) handles API endpoints, authentication middleware, and possibly token validation. It acts as an intermediary between the frontend and AWS Cognito.
- AWS Cognito Services: The README lists separate API calls for:
◦ User Pool functions – token endpoint and initiating “USER_PASSWORD_AUTH” or “USER_AUTH” flows.
◦ Identity Pool functions – obtaining an identity and IAM credentials.
These should be depicted as external cloud services that the backend (and sometimes the frontend directly) interacts with for authentication.
- External Authentication Providers: Google integration is a core element. Several API calls illustrate how a Google OAuth client is used to demo the integration by exchanging authorization codes and retrieving tokens.
- Additional Modules: For the file sharing web app (“ShareMyFile-Web-App”), components like S3 buckets (with provided CORS policies) and IAM role policies should be acknowledged. The “UserPoolSDK” project indicates a modular SDK or client library approach to interfacing with Cognito.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly split the frontend (user interaction) from the backend (authentication logic, API routing, external service calls).
- Microservices Integration: Although it may be a single backend service, the division into authentication (via Cognito) and file management (in ShareMyFile-Web-App) suggests modular responsibilities.
- Environment Configuration: Use of .env files suggests that environment-based configurations are critical (for keys, client IDs, endpoints, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user

    %% Frontend Applications
    F1["3-ReactSPA-BackendNodeJS Frontend"]:::frontend
    F2["Google Login Custom Frontend"]:::frontend
    F3["Share My File Web App Frontend"]:::frontend
    F4["User Pool SDK"]:::frontend

    %% Backend Components
    B1["NodeJS API Server"]:::backend
    B2["Authentication Middleware"]:::backend
    B3["Server Initialization"]:::backend
    B4["Utilities"]:::backend

    %% External Services
    C1["AWS Cognito - User Pool"]:::external
    C2["AWS Cognito - Identity Pool"]:::external
    C3["Google OAuth"]:::external
    C4["AWS S3 & IAM (ShareMyFile Resources)"]:::external
    R1["Authenticated IAM Role Policy"]:::external
    R2["Guest IAM Role Policy"]:::external
    R3["S3 Bucket CORS Settings"]:::external

    %% Configuration Files Subgraph
    subgraph "Configuration Files"
        E1["Backend .env Config"]:::config
        F1_config["Frontend Vite Config (3-ReactSPA)"]:::config
        F2_config["GoogleLoginCustom Vite Config"]:::config
        F3_config["ShareMyFile Vite Config"]:::config
        F4_config["UserPoolSDK Vite Config"]:::config
    end

    %% User interactions with Frontend
    User --> F1
    User --> F2
    User --> F3
    User --> F4

    %% Frontend API calls to Backend
    F1 --> B1
    F2 --> B1
    F3 --> B1
    F4 --> B1

    %% Backend internal modules
    B1 --> B2
    B1 --> B3
    B1 --> B4

    %% Backend communication with external auth services
    B1 -->|"TokenRequests"| C1
    B1 -->|"CredentialExchange"| C2
    B1 -->|"AuthIntegration"| C3

    %% Direct integration from Frontend to external auth
    F2 -->|"OAuthFlow"| C3

    %% File sharing application external integration
    F3 -->|"FileOps"| C4
    C4 --> R1
    C4 --> R2
    C4 --> R3

    %% Link configuration files to respective components
    B1 --- E1
    F1 --- F1_config
    F2 --- F2_config
    F3 --- F3_config
    F4 --- F4_config

    %% Styles
    classDef user fill:#d1e8ff,stroke:#333,stroke-width:2px;
    classDef frontend fill:#fde2e2,stroke:#333,stroke-width:2px;
    classDef backend fill:#e2f0cb,stroke:#333,stroke-width:2px;
    classDef external fill:#f4d6cc,stroke:#333,stroke-width:2px;
    classDef config fill:#fff2cc,stroke:#333,stroke-width:2px;

    %% Click Events
    click F1 "https://github.com/tricksumo/cognitocourse/tree/main/3-ReactSPA-BackendNodeJS/frontend"
    click F2 "https://github.com/tricksumo/cognitocourse/tree/main/GoogleLoginCustom"
    click F3 "https://github.com/tricksumo/cognitocourse/tree/main/ShareMyFile-Web-App/src"
    click F4 "https://github.com/tricksumo/cognitocourse/tree/main/UserPoolSDK"
    
    click B1 "https://github.com/tricksumo/cognitocourse/tree/main/3-ReactSPA-BackendNodeJS/backend"
    click B2 "https://github.com/tricksumo/cognitocourse/blob/main/3-ReactSPA-BackendNodeJS/backend/authMiddleware.js"
    click B3 "https://github.com/tricksumo/cognitocourse/blob/main/3-ReactSPA-BackendNodeJS/backend/server.js"
    click B4 "https://github.com/tricksumo/cognitocourse/blob/main/3-ReactSPA-BackendNodeJS/backend/utils.js"
    
    click E1 "https://github.com/tricksumo/cognitocourse/blob/main/3-ReactSPA-BackendNodeJS/backend/.env.example"
    click F1_config "https://github.com/tricksumo/cognitocourse/blob/main/3-ReactSPA-BackendNodeJS/frontend/vite.config.js"
    click F2_config "https://github.com/tricksumo/cognitocourse/blob/main/GoogleLoginCustom/vite.config.js"
    click F3_config "https://github.com/tricksumo/cognitocourse/blob/main/ShareMyFile-Web-App/vite.config.js"
    click F4_config "https://github.com/tricksumo/cognitocourse/blob/main/UserPoolSDK/vite.config.js"
    
    click R1 "https://github.com/tricksumo/cognitocourse/blob/main/ShareMyFile-Web-App/Resources/Authenticated IAM Role Policy.txt"
    click R2 "https://github.com/tricksumo/cognitocourse/blob/main/ShareMyFile-Web-App/Resources/Guest IAM Role Policy.txt"
    click R3 "https://github.com/tricksumo/cognitocourse/blob/main/ShareMyFile-Web-App/Resources/S3 Bucket CORS.txt"
```
