# prashantkhandelwal/popcorn architecture

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

- Interactive diagram: https://gitdiagram.com/prashantkhandelwal/popcorn
- Repository: https://github.com/prashantkhandelwal/popcorn

## Overview

##### Project Type and Purpose
- Popcorn is a full-stack, C#/.NET-based GraphQL API with a minimal static web UI for movie data.
- It ingests and hosts a movie database sourced from themoviedb.org, exposing data through a GraphQL schema.

##### File Structure Analysis
- Top-level code:
- Program.cs, Popcorn.csproj, Popcorn.sln — entry point and solution.
- /Models — domain entities (Movie, Person, Keywords, Credits).
- /Queries — GraphQL query definitions and extension methods.
- /Repositories — repository interfaces and implementations (data-access pattern).
- /Web — static assets (index.html, CSS, images) served alongside the API.
- /Database — archived movie database zip parts (for backup/restore).
- Deployment:
- /Deployment/Azure — Terraform files provisioning App Service or VM, Azure SQL Database, networking rules.
- .github/workflows — GitHub Actions CI/CD pipelines.
- Config:
- appsettings.json / appsettings.Production.json — environment-specific configuration.
- Properties/launchSettings.json — local dev launch profiles.

##### README Insights
- Describes Popcorn as a GraphQL interface, with live demo on Azure Web App.
- Points to docs on dev setup, backup/restore, and all GraphQL queries.

##### Main Components
a. Client Layer
- Web Browser (static SPA served from Web folder).
- GraphQL clients such as GraphQL Playground or Postman.
b. API Layer
- .NET Core GraphQL Server (Program.cs → GraphQL middleware).
- Query Handlers (/Queries), Repositories (/Repositories), Models (/Models).
c. Data Layer
- Azure SQL Database (holds the movie data).
- Backup artifacts (/Database zip parts).
d. Infrastructure Layer
- Azure Resources provisioned via Terraform:
– App Service or Azure VM hosting the API and static UI
– Azure SQL Database
– Networking (NSG, firewall rules)
- Terraform modules (/Deployment/Azure/*.tf).
e. CI/CD Pipeline
- GitHub Actions workflows triggering build and Terraform apply.
- GitHub repo as source code management.

##### Relationships and Data Flows
- Server: GraphQL Resolver → Repository → Azure SQL → data → upward back to client.
- CI/CD: Git Push → GitHub Actions → Build & Test → Terraform → deploy to Azure.
- Backup/Restore: Admin runs DB restore from .zip parts → Azure SQL.

##### Architectural Patterns and Principles
- Layered architecture (Presentation → GraphQL API → Data Access).
- Repository pattern for data access abstraction.
- Infrastructure as Code (Terraform) for repeatable deployments.
- Configuration per environment (appsettings.json).
- Static assets served alongside dynamic API.

##### Final Checklist
- All major components identified above.
- Labels for technologies (e.g., “Azure SQL Database”, “Terraform”).
- Container/group outlines for “Azure Infrastructure” and “Local Dev”.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CI/CD Pipeline
    subgraph "GitHub" 
        direction TB
        Repo["GitHub Repo"]:::cicd
        Actions["GitHub Actions Workflows"]:::cicd
    end

    Repo -->|"push"| Actions
    Actions -->|"build & test"| Build["Build & Test"]:::cicd
    Build -->|"terraform apply"| Terraform["Terraform IaC"]:::infra

    %% Infrastructure Layer
    subgraph "Azure Subscription"
        direction TB
        Terraform
        NSG["Networking (NSG/Firewall)"]:::infra
        WebApp["App Service / VM"]:::infra
        SQLDB[(Azure SQL Database)]:::data
    end

    Terraform --> NSG
    Terraform --> WebApp
    Terraform --> SQLDB

    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Web Browser (SPA)"]:::client
        Playground["GraphQL Playground / Postman"]:::client
    end

    Browser -->|"HTTPS"| WebApp
    Playground -->|"GraphQL Queries"| WebApp

    %% API Layer
    subgraph "API Layer"
        direction TB
        Server[".NET Core GraphQL Server"]:::api
        subgraph "GraphQL Logic"
            direction TB
            Queries["Query Handlers"]:::api
            Repos["Repositories"]:::api
            Models["Domain Models"]:::api
        end
    end

    WebApp --> Server
    Server --> Queries
    Queries --> Repos
    Repos --> SQLDB
    SQLDB --> Repos
    Repos --> Queries
    Queries --> Server
    Server --> Browser
    Server --> Playground

    %% Data Backup
    subgraph "Data Layer"
        direction TB
        Backup["DB Backup Artifacts (.zip parts)"]:::data
    end

    Backup -->|"restore"| SQLDB

    %% Click Events
    click Repo "https://github.com/prashantkhandelwal/popcorn/tree/main/.github/workflows"
    click Actions "https://github.com/prashantkhandelwal/popcorn/blob/main/.github/workflows/build-main.yml"
    click Actions "https://github.com/prashantkhandelwal/popcorn/blob/main/.github/workflows/popcorndb.yml"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/Azure/main.tf"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/Azure/providers.tf"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/Azure/variables.tf"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/Azure/rules.tf"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/Azure/vm.tf"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/Azure/webapp.tf"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/Azure/output.tf"
    click Terraform "https://github.com/prashantkhandelwal/popcorn/blob/main/Deployment/README.md"
    click Browser "https://github.com/prashantkhandelwal/popcorn/blob/main/Web/index.html"
    click Browser "https://github.com/prashantkhandelwal/popcorn/blob/main/Web/css/style.css"
    click Browser "https://github.com/prashantkhandelwal/popcorn/tree/main/Web/img/"
    click Server "https://github.com/prashantkhandelwal/popcorn/blob/main/Program.cs"
    click Server "https://github.com/prashantkhandelwal/popcorn/blob/main/Popcorn.csproj"
    click Server "https://github.com/prashantkhandelwal/popcorn/blob/main/Popcorn.sln"
    click Queries "https://github.com/prashantkhandelwal/popcorn/blob/main/Queries/MoviesQuery.cs"
    click Queries "https://github.com/prashantkhandelwal/popcorn/blob/main/Queries/Extensions/CreditsMovieExtension.cs"
    click Queries "https://github.com/prashantkhandelwal/popcorn/blob/main/Queries/Extensions/KeywordsMovieExtension.cs"
    click Queries "https://github.com/prashantkhandelwal/popcorn/blob/main/Queries/Extensions/MovieCreditsExtension.cs"
    click Queries "https://github.com/prashantkhandelwal/popcorn/blob/main/Queries/SortTypes/MovieSortType.cs"
    click Models "https://github.com/prashantkhandelwal/popcorn/blob/main/Models/Movie.cs"
    click Models "https://github.com/prashantkhandelwal/popcorn/blob/main/Models/Person.cs"
    click Models "https://github.com/prashantkhandelwal/popcorn/blob/main/Models/Keywords.cs"
    click Models "https://github.com/prashantkhandelwal/popcorn/blob/main/Models/Credits.cs"
    click Models "https://github.com/prashantkhandelwal/popcorn/blob/main/Models/IMDBMovies.cs"
    click Repos "https://github.com/prashantkhandelwal/popcorn/blob/main/Repositories/IMoviesRepository.cs"
    click Repos "https://github.com/prashantkhandelwal/popcorn/blob/main/Repositories/MoviesRepository.cs"
    click Backup "https://github.com/prashantkhandelwal/popcorn/blob/main/Database/moviedb.zip.001"
    click Backup "https://github.com/prashantkhandelwal/popcorn/blob/main/Database/moviedb.zip.075"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#0066CC,color:#003366
    classDef api fill:#DFF0D8,stroke:#3C763D,color:#2B542C
    classDef data fill:#FDEBD0,stroke:#D35400,color:#873600
    classDef infra fill:#E8DAEF,stroke:#8E44AD,color:#512E5F
    classDef cicd fill:#ECECEC,stroke:#999999,color:#666666
```
