# vanneszias/drone-manager architecture

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

- Interactive diagram: https://gitdiagram.com/vanneszias/drone-manager
- Repository: https://github.com/vanneszias/drone-manager

## Overview

##### Project Type and Purpose
- This is a full-stack hybrid application combining a Next.js frontend with a Python/Flask API backend.
- The frontend is built with Next.js v13 App Router (TypeScript, Tailwind CSS) to render pages and UI components.
- The backend is a Flask app (in the `/api` folder) exposing REST endpoints for resources like drones, events, zones, etc.
- The entire stack is deployed on Vercel: Next.js as edge/SSR, Flask as Python serverless functions.

##### File Structure Analysis
- `/app`
- Next.js App Router pages under `/app/dashboard/...` (one page per resource) and global layouts & CSS.
- `app/types.ts` defines shared data types.
- `/components`
- Reusable React components organized by feature (dashboard/resource) and UI primitives (`components/ui`).
- `/hooks`
- Custom React hooks (`useDrones`, `useEvents`, etc.) encapsulate data fetching via the API.
- `/api`
- `app.py` defines the Flask application and route registrations.
- `config.py` holds environment and database settings.
- `/helpers` contains one helper per resource (e.g. `drone_helper.py`) encapsulating DB logic.
- `db.sql`
- Database schema and seed statements.
- Configuration & build files
- `next.config.js` with rewrite rules mapping `/api/*` to the Flask server (locally to `127.0.0.1:5328`, in prod to serverless).
- `vercel.json` / `requirements.txt` for Python serverless deployment.

##### README Insights
- Explains the Next.js ↔ Flask integration via rewrite rules.
- On localhost, Next.js proxies `/api` calls to a local Flask server; in production, Flask lives as Vercel serverless functions.
- Encourages leveraging Python AI libraries on the backend.

a. Main Components
- **User / Browser**: issues HTTP requests, renders UI.
- **Next.js Frontend** (Edge/SSR):
- Pages & Layouts (`/app`)
- React Components (`/components`)
- Hooks (`/hooks`) for data layer
- Tailwind CSS & global assets.
- **API Gateway / Rewrite Layer**: `next.config.js` rewrite of `/api/*`.
- **Flask Backend** (Python serverless functions):
- `api/app.py` routes
- `helpers/*_helper.py` for data access
- `config.py` for DB settings
- **Database**: relational DB (SQLite/Postgres) defined via `db.sql`.
- **Hosting/Infrastructure**: Vercel platform (Edge for Next.js, serverless for Flask).

b. Relationships & Data Flows
1. Browser → Next.js page (SSR or CSR)
2. UI (React) → Hook (e.g. `useDrones`)
3. Hook → HTTP GET/POST to `/api/drones`
4. Next.js rewrite → Flask function endpoint
5. Flask route → calls corresponding Helper → DB query via `db.sql` schema
6. Data returned back up the chain to UI.
7. User sees updated UI.

c. Architectural Patterns & Principles
- **Client-Server Separation**: clearly defined frontend vs backend responsibilities.
- **Monorepo Hybrid**: both Next.js and Flask live in same codebase.
- **Serverless Functions**: each Flask endpoint deploys as an independent lambda.
- **DRY + Single Source of Truth**: shared types (`app/types.ts`), centralized helpers in Flask.
- **Feature-based Componentization** in React.

d. Key Technologies & Frameworks
- Frontend: Next.js (TypeScript, App Router), React Hooks, Tailwind CSS
- Backend: Flask (Python 3), serverless on Vercel, WSGI
- Database: SQLite/PostgreSQL (schema in `db.sql`)
- Deployment: Vercel (edge functions for Next.js, Python serverless)
- Build & Config: `next.config.js`, `vercel.json`, `requirements.txt`, `tsconfig.json`

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        Browser["User / Browser"]:::frontend
        Pages["Next.js Pages & Layouts"]:::frontend
        Components["React UI Components"]:::frontend
        Hooks["Data-Fetching Hooks"]:::frontend
        Styles["Tailwind CSS & Global Styles"]:::frontend
        Middleware["Middleware (Edge / SSR hooks)"]:::frontend
        Assets["Public Static Assets"]:::frontend
    end

    %% API Proxy Layer
    subgraph "API Proxy / Rewrite" 
        direction TB
        Proxy["next.config.js Rewrite Layer"]:::proxy
    end

    %% Backend Layer
    subgraph "Backend (Flask Serverless)" 
        direction TB
        FlaskApp["Flask app.py"]:::backend
        FlaskConfig["Flask config.py"]:::backend
        Helpers["Data-Access Helpers"]:::backend
    end

    %% Database
    DB[(Managed SQL DB)]:::db

    %% Infrastructure
    subgraph "Vercel Platform" 
        direction TB
        Edge["Next.js Edge/SSR"]:::infra
        Serverless["Flask Serverless Functions"]:::infra
    end

    %% Connections
    Browser -->|"HTTP Request"| Pages
    Pages -->|"uses"| Components
    Components -->|"calls"| Hooks
    Hooks -->|"fetch /api/*"| Proxy
    Proxy -->|"rewrites to"| FlaskApp
    FlaskApp -->|"loads"| FlaskConfig
    FlaskApp -->|"uses"| Helpers
    Helpers -->|"queries"| DB
    DB -->|"returns data"| Helpers
    Helpers -->|"returns JSON"| FlaskApp
    FlaskApp -->|"HTTP Response"| Proxy
    Proxy -->|"HTTP Response"| Hooks
    Hooks -->|"provides data"| Components
    Components -->|"renders UI"| Pages
    Pages -->|"HTML/CSS"| Browser

    %% Infra Connections
    Edge --> Pages
    Serverless --> FlaskApp

    %% Click Events
    click Pages "https://github.com/vanneszias/drone-manager/tree/master//app"
    click Components "https://github.com/vanneszias/drone-manager/tree/master//components"
    click Hooks "https://github.com/vanneszias/drone-manager/tree/master//hooks"
    click Styles "https://github.com/vanneszias/drone-manager/blob/master//app/globals.css"
    click Styles "https://github.com/vanneszias/drone-manager/blob/master/tailwind.config.js"
    click Styles "https://github.com/vanneszias/drone-manager/blob/master/postcss.config.js"
    click Middleware "https://github.com/vanneszias/drone-manager/blob/master/middleware.ts"
    click Assets "https://github.com/vanneszias/drone-manager/tree/master//public/images"
    click Proxy "https://github.com/vanneszias/drone-manager/blob/master/next.config.js"
    click FlaskApp "https://github.com/vanneszias/drone-manager/blob/master//api/app.py"
    click FlaskConfig "https://github.com/vanneszias/drone-manager/blob/master//api/config.py"
    click Helpers "https://github.com/vanneszias/drone-manager/tree/master//api/helpers"
    click DB "https://github.com/vanneszias/drone-manager/blob/master/db.sql"
    click Edge "https://github.com/vanneszias/drone-manager/blob/master/vercel.json"
    click Edge "https://github.com/vanneszias/drone-manager/blob/master/package.json"
    click Edge "https://github.com/vanneszias/drone-manager/blob/master/tsconfig.json"
    click Serverless "https://github.com/vanneszias/drone-manager/blob/master/requirements.txt"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef proxy fill:#FFD700,stroke:#000,stroke-width:1px
    classDef infra fill:#F0E68C,stroke:#000,stroke-width:1px
    classDef db fill:#E6E6FA,stroke:#000,stroke-width:1px
```
