# fortune-cook1e/iot-smart-parking-system architecture

> Architecture diagram of the GitHub repository fortune-cook1e/iot-smart-parking-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fortune-cook1e/iot-smart-parking-system
- Repository: https://github.com/fortune-cook1e/iot-smart-parking-system

## Overview

##### Project type & purpose
– This is a full-stack, IoT-enabled Smart Parking System in a pnpm monorepo.
– Components:
- Mobile App (React Native + Expo) for end users
- Admin Dashboard (Next.js) for parking administrators
- Backend API (Express + TypeScript + Prisma + PostgreSQL + Socket.IO + Swagger)
- Shared Schemas (Zod + TypeScript) used across client and server
- AI/ML Service (Python + FastAPI + scikit-learn) for occupancy-prediction

##### File-structure analysis
– Top-level directories:
- apps/mobile – React Native code, Expo config, Socket.IO client, hooks, services, store
- apps/dashboard – Next.js pages, components (UI library, charts, dialogs), services (REST & SSE), Zustand store
- apps/server – Express app with layered subfolders (config, controllers, routes, services, middleware, utils), Prisma schema, migrations, seed
- packages/shared-schemas – Zod schemas and TS types for DTO validation
- AI-ML – Python scripts for training and a FastAPI service, Dockerfile
– Cross-cutting: Dockerfile, docker-compose.yml/​prod, GitHub workflows, workspace config

##### README insights
– Realtime updates via Socket.IO (server pushes events to mobile & dashboard)
– IoT webhook ingestion: sensors POST occupancy/price updates → server
– Dashboard AI-chat uses Ollama (gpt-oss) over SSE
– Occupancy-probability predictions via Python FastAPI service
– Shared Zod schemas guarantee consistency across all apps

## Diagram (Mermaid)

```mermaid
graph TD
    %% Clients Layer
    subgraph "Clients" 
        Mobile["Mobile App<br/>(React Native + Expo + Socket.IO Client)"]:::client
        Dashboard["Admin Dashboard<br/>(Next.js + Zustand + SSE)"]:::client
    end

    %% Shared Schemas
    Shared["Shared Schemas<br/>(Zod + TS Types)"]:::shared

    %% Backend API Layer
    subgraph "Backend API" 
        WsCtrl["Webhook Handler"]:::backend
        REST["REST API<br/>(Parking, Users, Subscriptions)"]:::backend
        Socket["Socket.IO Gateway"]:::backend
        AIChat["AI-Chat SSE API"]:::backend
        Predict["Prediction Endpoint"]:::backend
        Swagger["Swagger UI"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        DB[(PostgreSQL)]:::db
    end

    %% Microservices
    subgraph "Microservices"
        ML["AI/ML Service<br/>(FastAPI + scikit-learn)"]:::ml
    end

    %% External Systems
    subgraph "External"
        Sensors["IoT Sensors"]:::external
        Ollama["Ollama Chat Service"]:::external
    end

    %% Data Flows
    Sensors -->|"POST /webhook"| WsCtrl
    WsCtrl -->|writes/updates| DB
    REST -->|CRUD ops| DB
    REST -->|CRUD API| Dashboard
    REST -->|CRUD API| Mobile
    Socket -->|parking-events| Dashboard
    Socket -->|parking-events| Mobile
    Dashboard -->|SSE /ai-chat| AIChat
    AIChat -->|streaming| Ollama
    Ollama -->|streaming| AIChat
    AIChat -->|SSE stream| Dashboard
    Predict -->|HTTP /predict| ML
    ML -->|occupancy_probability| Predict
    Shared -->|imports| Mobile
    Shared -->|imports| Dashboard
    Shared -->|imports| WsCtrl
    Shared -->|imports| REST
    Shared -->|imports| Socket
    Shared -->|imports| AIChat
    Shared -->|imports| Predict

    %% Click Events
    click Mobile "https://github.com/fortune-cook1e/iot-smart-parking-system/tree/master/apps/mobile"
    click Dashboard "https://github.com/fortune-cook1e/iot-smart-parking-system/tree/master/apps/dashboard"
    click WsCtrl "https://github.com/fortune-cook1e/iot-smart-parking-system/blob/master/apps/server/src/controllers/webhook.controller.ts"
    click Socket "https://github.com/fortune-cook1e/iot-smart-parking-system/blob/master/apps/server/src/config/socket.ts"
    click Swagger "https://github.com/fortune-cook1e/iot-smart-parking-system/blob/master/apps/server/src/config/swagger.ts"
    click DB "https://github.com/fortune-cook1e/iot-smart-parking-system/blob/master/apps/server/prisma/schema.prisma"
    click ML "https://github.com/fortune-cook1e/iot-smart-parking-system/blob/master/AI-ML/service.py"
    click AIChat "https://github.com/fortune-cook1e/iot-smart-parking-system/blob/master/apps/server/src/controllers/ai-chat.controller.ts"
    click Predict "https://github.com/fortune-cook1e/iot-smart-parking-system/blob/master/apps/server/src/controllers/prediction.controller.ts"
    click Shared "https://github.com/fortune-cook1e/iot-smart-parking-system/tree/master/packages/shared-schemas"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#E6F4EA,stroke:#217B37,color:#217B37;
    classDef db fill:#FFF4E5,stroke:#E67700,color:#E67700;
    classDef ml fill:#FFEFEF,stroke:#D23C3C,color:#D23C3C;
    classDef external fill:#F0F0F0,stroke:#999999,color:#555555;
    classDef shared fill:#F5E1FD,stroke:#8A3FFC,color:#8A3FFC
```
