# akash-selvaraj/pcb-defect-detection architecture

> Architecture diagram of the GitHub repository akash-selvaraj/pcb-defect-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akash-selvaraj/pcb-defect-detection
- Repository: https://github.com/akash-selvaraj/pcb-defect-detection

## Overview

##### Project Type and Purpose
- This is a full-stack web application combining:
- A Next.js (React) frontend for UI/UX
- A Python-based backend (likely Flask or FastAPI) that loads a pre-trained PyTorch model (`model_final.pth`) and runs inference based on YAML configs
- Purpose: Serve a single-page/web-app interface that sends image/data to the backend, performs object-detection inference, and returns results to the user.

##### File-Structure Analysis
- Top-level files
- Configuration: `.eslintrc.json`, `tsconfig.json`, `tailwind.config.ts`, `postcss.config.mjs`
- Next.js config: `next.config.ts`
- Package manager: `package.json`, `package-lock.json`
- Frontend (Next.js)
- `src/app/` – React components, layout.tsx (root layout), page.tsx (entry page), globals.css, custom fonts
- `src/utils/api.ts` – wrappers for HTTP calls to the backend
- `public/` – static assets (e.g. `front.pdf`)
- Backend (Python)
- `backend/app.py` – main application (Flask/FastAPI) exposing inference endpoints
- `backend/model/model_final.pth` – serialized ML model
- `backend/yaml/…` – Detectron2 or SSD/FPN configuration files
- `backend/requirements.txt` & `requirements_cpu.txt` – Python dependencies

##### README Insights
- Standard Next.js scaffolding; no mention of DB or caching layer
- No built-in instructions for the backend—implies it runs as a separate service

##### Main Components & Relationships
a. Frontend Layer (Next.js)
– Runs in the browser (SSR or static)
– Hosts UI, routes, styling (Tailwind), and calls backend via `src/utils/api.ts`
b. API/Backend Service
– Python server (Flask/FastAPI)
– Endpoint(s) for image/data upload → model inference → JSON response
c. ML Model Storage
– Local disk or external volume holding `model_final.pth`
– YAML config files guiding model architecture and hyperparameters
d. External/Infrastructure (optional)
– Deployment: Vercel for Next.js, Docker/Kubernetes or EC2 for backend
– (Optional) Cloud storage or volume for model artifacts

##### Architectural Patterns & Principles
- Separation of Concerns: UI layer vs. inference service
- Microservice-style: Frontend and backend deployed independently
- Configuration-driven model loading (YAML + .pth)
- Utility layer (`api.ts`) abstracts HTTP calls and enforces type safety

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser (User Interface)"
        Browser["Browser"]:::frontend
    end

    subgraph "Next.js Frontend"
        NextServer["Next.js Server"]:::frontend
        APIUtil["api.ts"]:::frontend
        Layout["layout.tsx"]:::frontend
        Page["page.tsx"]:::frontend
        Globals["globals.css"]:::frontend
        Fonts["fonts"]:::frontend
        NextConfig["next.config.ts"]:::frontend
        Tailwind["tailwind.config.ts"]:::frontend
        PostCSS["postcss.config.mjs"]:::frontend
        TSConfig["tsconfig.json"]:::frontend
        ESLint[".eslintrc.json"]:::frontend
        Public["public/"]:::frontend
    end

    subgraph "Python Inference Service"
        AppPy["app.py"]:::service
        Dependencies["requirements.txt / requirements_cpu.txt"]:::service
        subgraph "Model Loader"
            ConfigYAML["YAML Configs"]:::data
            ModelFile["model_final.pth"]:::data
        end
    end

    DB["Model Store"]:::data

    Browser -->|"HTTP GET/POST"| NextServer
    NextServer -->|"uses"| APIUtil
    NextServer -->|"renders"| Layout
    NextServer -->|"renders"| Page
    NextServer -->|"applies styles"| Globals
    NextServer -->|"loads fonts"| Fonts
    NextServer -->|"serves assets"| Public
    NextServer -->|"build config"| NextConfig
    NextServer -->|"build config"| Tailwind
    NextServer -->|"build config"| PostCSS
    NextServer -->|"ts config"| TSConfig
    NextServer -->|"lint config"| ESLint

    APIUtil -->|"REST API call"| AppPy
    AppPy -->|"loads from"| DB
    AppPy -->|"loads configs"| ConfigYAML
    AppPy -->|"loads model"| ModelFile
    AppPy -->|"responds JSON"| NextServer

    click Layout "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/src/app/layout.tsx"
    click Page "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/src/app/page.tsx"
    click Globals "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/src/app/globals.css"
    click Fonts "https://github.com/akash-selvaraj/pcb-defect-detection/tree/main/src/app/fonts"
    click APIUtil "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/src/utils/api.ts"
    click Public "https://github.com/akash-selvaraj/pcb-defect-detection/tree/main/public/"
    click NextConfig "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/next.config.ts"
    click Tailwind "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/tailwind.config.ts"
    click PostCSS "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/postcss.config.mjs"
    click TSConfig "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/tsconfig.json"
    click ESLint "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/.eslintrc.json"
    click AppPy "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/backend/app.py"
    click Dependencies "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/backend/requirements.txt"
    click Dependencies "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/backend/requirements_cpu.txt"
    click ModelFile "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/backend/model/model_final.pth"
    click ConfigYAML "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/backend/yaml/Base-RCNN-FPN.yaml"
    click ConfigYAML "https://github.com/akash-selvaraj/pcb-defect-detection/blob/main/backend/yaml/ssd/faster_rcnn_R_50_SSD_FPN_3x.yaml"

    classDef frontend fill:#E0F7FA,stroke:#0277BD,color:#01579B
    classDef service fill:#E8F5E9,stroke:#388E3C,color:#1B5E20
    classDef data fill:#FFF3E0,stroke:#F57C00,color:#E65100
```
