# gitmicafri/quiztopiauppgift architecture

> Architecture diagram of the GitHub repository gitmicafri/quiztopiauppgift, 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/gitmicafri/quiztopiauppgift
- Repository: https://github.com/gitmicafri/quiztopiauppgift

## Overview

##### Project Type and Purpose
- Type: A serverless API backend.
- Purpose: To power a quiz application where users can register, log in, create quizzes, add questions (including geolocation data) and delete quizzes, with additional features (such as a leaderboard) specified in the guidelines.
- Technologies: AWS Lambda, API Gateway, DynamoDB, Serverless Framework, Middy middleware for error handling and validations, JSON Web Tokens (JWT) for authentication, and JSON schemas for request validation.

##### Analyzing the File Structure
- Key directories:
– /src/handlers: Contains Lambda handlers for endpoints (signIn, signUp, createQuiz, getQuiz, getAllQuizzes, deleteQuiz, postQuestion).
– /src/middleware: Implements middleware (e.g., token validation) likely integrated with Middy.
– /src/schemas: Holds JSON schema files (for validating signIn, signUp, quiz creation, and question posting).
– /src/services and /src/utilities: Contain helper services and utilities (e.g., token generation) used by various handlers.
- Configuration files:
– serverless.yml: Configures deployment for AWS Lambda, API Gateway endpoints, DynamoDB integration, and other AWS resources.
– package.json: Lists dependencies that include serverless, Middy, and JSON Web Token libraries.
- Additional: documentation.json might be serving internal documentation or further details of the API design.

##### Examining the README
- The README provides functional and technical requirements that emphasize modular endpoints (account creation, quiz management, question management, leaderboard functionality) along with integration points with AWS services.
- It highlights the importance of error handling (especially with DynamoDB) and authentication for user-specific operations.
- The technical stack is explicitly mentioned: Serverless, AWS Lambda, API Gateway, DynamoDB, Middy, and JSON Web Token.

- Use clear, concise labels for each component (e.g., “API Gateway”, “SignIn Lambda Handler”, “ValidateToken Middleware”).
- Including a section for error handling flows, indicating where error messages are caught and returned if something goes wrong with DynamoDB or if JWT validation fails.

##### Final Touches
– Add annotations to describe critical interactions or any non-trivial design decisions (such as how schema validations are enforced or how the JWT middleware fits into the processing chain).
– Since the project relies on the Serverless Framework, you might also include a note on how deployment configurations (from serverless.yml) tie into the overall architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-Level Clients and API Gateway
    Client["Client (Web/Mobile)"]:::client
    APIGateway["API Gateway"]:::apigw
    ServerlessConfig["Serverless Config"]:::config
    Documentation["Documentation"]:::doc

    Client -->|"HTTP Request"| APIGateway
    APIGateway -->|"Uses"| ServerlessConfig
    Documentation -.-> ServerlessConfig

    %% Middleware Layer
    ValidateToken["ValidateToken Middleware"]:::middleware
    APIGateway -->|"routes to"| ValidateToken

    %% Lambda Handlers Subgraph
    subgraph "Lambda Handlers"
        SignInHandler["SignIn Handler"]:::lambda
        SignUpHandler["SignUp Handler"]:::lambda
        CreateQuizHandler["CreateQuiz Handler"]:::lambda
        GetQuizHandler["GetQuiz Handler"]:::lambda
        GetAllQuizzesHandler["GetAllQuizzes Handler"]:::lambda
        DeleteQuizHandler["DeleteQuiz Handler"]:::lambda
        PostQuestionHandler["PostQuestion Handler"]:::lambda
    end

    %% Connect Middleware to Lambda Handlers (entry point via SignIn Handler as representative)
    ValidateToken -->|"invokes"| SignInHandler

    %% Business Logic Aggregator Node
    BusinessLogic["Business Logic"]:::bl
    SignInHandler -->|"processes"| BusinessLogic
    SignUpHandler --> BusinessLogic
    CreateQuizHandler --> BusinessLogic
    GetQuizHandler --> BusinessLogic
    GetAllQuizzesHandler --> BusinessLogic
    DeleteQuizHandler --> BusinessLogic
    PostQuestionHandler --> BusinessLogic

    %% Schema Validation and Utility Flow
    JSONSchemas["JSON Schemas"]:::schema
    TokenUtility["Token Utility"]:::utility
    HelperServices["Helper Services"]:::service
    DynamoDB["DynamoDB"]:::database
    ResponseFormatter["Response Formatter"]:::response

    BusinessLogic -->|"validates"| JSONSchemas
    JSONSchemas -->|"triggers"| TokenUtility
    TokenUtility -->|"calls"| HelperServices
    HelperServices -->|"persists"| DynamoDB
    DynamoDB -->|"formats data"| ResponseFormatter
    ResponseFormatter -->|"response"| APIGateway
    APIGateway -->|"HTTP Response"| Client

    %% Click Events
    click SignInHandler "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/handlers/signIn.js"
    click SignUpHandler "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/handlers/signUp.js"
    click CreateQuizHandler "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/handlers/createQuiz.js"
    click GetQuizHandler "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/handlers/getQuiz.js"
    click GetAllQuizzesHandler "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/handlers/getAllQuizzes.js"
    click DeleteQuizHandler "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/handlers/deleteQuiz.js"
    click PostQuestionHandler "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/handlers/postQuestion.js"
    click ServerlessConfig "https://github.com/gitmicafri/quiztopiauppgift/blob/main/serverless.yml"
    click ValidateToken "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/middleware/validateToken.js"
    click JSONSchemas "https://github.com/gitmicafri/quiztopiauppgift/tree/main/src/schemas"
    click TokenUtility "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/utilities/signInToken.js"
    click HelperServices "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/services/index.js"
    click ResponseFormatter "https://github.com/gitmicafri/quiztopiauppgift/blob/main/src/responses/index.js"
    click Documentation "https://github.com/gitmicafri/quiztopiauppgift/blob/main/documentation.json"

    %% Styles
    classDef client fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef apigw fill:#ffcc80,stroke:#bf360c,stroke-width:2px;
    classDef lambda fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef middleware fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef config fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
    classDef schema fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;
    classDef utility fill:#b2ebf2,stroke:#006064,stroke-width:2px;
    classDef service fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
    classDef database fill:#ffab91,stroke:#d84315,stroke-width:2px;
    classDef response fill:#d7ccc8,stroke:#3e2723,stroke-width:2px;
    classDef doc fill:#c5e1a5,stroke:#33691e,stroke-width:2px;
    classDef bl fill:#e1bee7,stroke:#6a1b9a,stroke-width:2px;
```
