# ahmedkhaleel2004/mec-2023 architecture

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

- Interactive diagram: https://gitdiagram.com/ahmedkhaleel2004/mec-2023
- Repository: https://github.com/ahmedkhaleel2004/mec-2023

## Overview

##### Project type and purpose
- This is a standalone Python-based computer‐vision/pathfinding tool (not a web or microservice). It takes a top-down parking-lot image or video frame, detects empty spots with YOLOv8, then computes/displayes the shortest path to a user-selected spot using A*.

##### File structure
- Top‐level scripts:
- main.py – orchestration: loads frames, runs detection, handles user input/visualization via Pygame.
- astar.py – encapsulates the A* pathfinding logic on a discretized grid.
- README.md – project overview & instructions.
- yolov8n.pt – pretrained YOLOv8 model weights.
- runs/detect/... – example outputs/directories created by Ultralytics detect commands.

##### README for additional insights
- Dependency stack: Python, Ultralytics YOLO package, NumPy, Pygame

##### Components
a. Main Components
1) Input Source: Camera feed or static image/video.
2) Preprocessing Module: Frame resizing, normalization (NumPy).
3) Detection Module: Ultralytics YOLOv8 using yolov8n.pt
4) Post-Processing/Mapper:
– Rounds & scales into a discrete grid.
5) Pathfinding Module: A* algorithm (astar.py).
6) Visualization & UI Module: Pygame window, user selects start/end/barriers.
7) Output: Visual overlay of detected spots and computed path.
b. Relationships & Data Flow
– → Pathfinding → path coordinates → Visualization
– Visualization feeds back user input (start, end, barriers) to Mapper/Pathfinding.
c. Architectural Patterns & Principles
– Pipeline design: sequential processing stages.
– Separation of concerns: detection, mapping, algorithm, and UI are distinct modules.
– Modular configuration: model weights (yolov8n.pt) loaded at runtime, can be swapped.
d. Key Technologies
– Python 3.x, Ultralytics YOLOv8 library, NumPy for array ops, Pygame for rendering.

##### Detailed Elements to Capture
- The discrete grid as an intermediate data artifact between detection and A*.
- The multiprocessing or loop in main.py that continuously grabs frames, processes, and renders.
- Explicitly note the barrier‐placement capability in the UI module, feeding back to the A* module.

## Diagram (Mermaid)

```mermaid
graph TB
    Input["Input: Camera/Image/Video"]:::data
    Preprocessing["Preprocessing: Resize, Normalize (NumPy)"]:::process
    Detection["Detection: YOLOv8"]:::process
    YOLO_Weights["Model Weights: yolov8n.pt"]:::artifact
    Mapper["Post-Processing/Mapper: bbox to grid"]:::process
    Grid["Discrete Grid"]:::artifact
    Pathfinding["Pathfinding: A* Algorithm"]:::process
    UI["Visualization & UI: Pygame"]:::process
    Storage(("runs/detect/")):::artifact

    Input --> Preprocessing
    Preprocessing --> Detection
    YOLO_Weights --> Detection
    Detection --> Mapper
    Mapper --> Grid
    Grid --> Pathfinding
    Pathfinding --> UI
    UI -->|user input| Mapper
    UI -->|user input| Pathfinding
    Detection --> Storage

    click Input "https://github.com/ahmedkhaleel2004/mec-2023/blob/main/main.py"
    click Preprocessing "https://github.com/ahmedkhaleel2004/mec-2023/blob/main/main.py"
    click Detection "https://github.com/ahmedkhaleel2004/mec-2023/blob/main/main.py"
    click YOLO_Weights "https://github.com/ahmedkhaleel2004/mec-2023/blob/main/yolov8n.pt"
    click Mapper "https://github.com/ahmedkhaleel2004/mec-2023/blob/main/main.py"
    click Pathfinding "https://github.com/ahmedkhaleel2004/mec-2023/blob/main/astar.py"
    click UI "https://github.com/ahmedkhaleel2004/mec-2023/blob/main/main.py"
    click Storage "https://github.com/ahmedkhaleel2004/mec-2023/tree/main/runs/detect/"

    classDef data fill:#a6cee3,stroke:#333,stroke-width:1px;
    classDef process fill:#b2df8a,stroke:#333,stroke-width:1px;
    classDef artifact fill:#ffff99,stroke:#333,stroke-width:1px;
```
