# ynthnwhjn/programstok architecture

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

- Interactive diagram: https://gitdiagram.com/ynthnwhjn/programstok
- Repository: https://github.com/ynthnwhjn/programstok

## Overview

##### Project type and purpose
- This is a full-stack, monolithic Laravel (PHP) web application for inventory management and invoicing (customers, products, purchase/sales invoices, stock reports, variables).
- It exposes both blade-based HTML pages for users (dashboard, forms, reports) and JSON APIs (routes/api.php) secured by Laravel Sanctum and standard auth middleware.

##### File structure
- Top-level directories:
- app/                → core MVC code (Models, Controllers, Observers, Traits, Middleware, ServiceProviders)
- bootstrap/          → Laravel bootstrap files
- config/             → environment-agnostic configuration (database, cache, mail, sanctum, etc.)
- database/           → migrations, seeders, factories
- public/             → web server root (index.php, CSS/JS assets, mix manifest)
- resources/          → Blade views, raw CSS/JS, language files
- routes/             → web.php (Blade pages), api.php (API endpoints)
- storage/            → logs, cache, sessions, file uploads
- tests/              → PHPUnit feature/unit tests
- webpack.mix.js      → asset pipeline (Laravel Mix)

- Architectural choices:
- MVC pattern (app/Models, app/Http/Controllers, resources/views)
- Event-driven via Observers (app/Observers)
- Traits for cross-cutting concerns (CRUD, kode generation, stock updates)
- Middleware for request filtering (auth, csrf, etc.)
- ServiceProviders for bootstrapping services

##### Additional insights from README
- Uses seeders to prepopulate users, products, variables.

##### Elements
- Clear labels: “Browser / Client”, “Nginx/Apache”, “Laravel Kernel”, “Controllers”, “Models (Eloquent)”, “MySQL DB”, “Storage (disk/S3)”, “Queue”, “Mail”, “Observers”
- Rectangles for components (e.g., Web Server, DB)
- Clouds for external services (Queue, Mail)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Layer"
        ClientBrowser["Browser / Client"]:::frontend
        AssetsJS["resources/js/\\npublic/js/"]:::asset
        AssetsCSS["resources/css/\\npublic/css/"]:::asset
        Views["resources/views/"]:::frontend
    end

    subgraph "Web Server"
        WebServer["Nginx/Apache"]:::backend
        Index["public/index.php"]:::backend
        ServerPHP["server.php"]:::backend
    end

    WebServer -->|serve| Index
    Index --> Kernel

    subgraph "Application Layer"
        Kernel["Laravel Kernel\\napp/Http/Kernel.php"]:::middleware

        subgraph "Routing"
            WebRoutes["routes/web.php"]:::backend
            APIRoutes["routes/api.php"]:::backend
        end

        subgraph "Middleware Pipeline"
            AuthMW["Authenticate\\napp/Http/Middleware/Authenticate.php"]:::middleware
            CsrfMW["VerifyCsrfToken\\napp/Http/Middleware/VerifyCsrfToken.php"]:::middleware
            EncCookies["EncryptCookies\\napp/Http/Middleware/EncryptCookies.php"]:::middleware
        end

        subgraph "Controllers"
            BaseController["Controller.php"]:::controller
            AuthController["AuthController"]:::controller
            CrudController["CrudController"]:::controller
            DashboardController["DashboardController"]:::controller
            CustomerController["CustomerController"]:::controller
            ProductController["ProductController"]:::controller
            PurchaseInvCtrl["PurchaseInvoiceController"]:::controller
            SalesInvCtrl["SalesInvoiceController"]:::controller
            StockReportCtrl["LaporanStokBarangController"]:::controller
            BrowseController["Api/BrowseController"]:::controller
        end

        subgraph "Models"
            UserModel["User\\napp/Models/User.php"]:::model
            BarangModel["Mbarang\\napp/Models/Mbarang.php"]:::model
            CustSuppModel["Mcustsupp\\napp/Models/Mcustsupp.php"]:::model
            TJualNotaH["Tjualnotah\\napp/Models/Tjualnotah.php"]:::model
            TJualNotaD["Tjualnotad\\napp/Models/Tjualnotad.php"]:::model
            TBeliNotaH["Tbelinotah\\napp/Models/Tbelinotah.php"]:::model
            TBeliNotaD["Tbelinotad\\napp/Models/Tbelinotad.php"]:::model
            TStokBarang["Tstokbarang\\napp/Models/Tstokbarang.php"]:::model
            VariabelModel["Variabel\\napp/Models/Variabel.php"]:::model
        end

        Observers["CrudObserver\\napp/Observers/CrudObserver.php"]:::backend
        Traits["Traits\\napp/Traits/"]:::backend
        ServiceProviders["ServiceProviders\\napp/Providers/"]:::backend
    end

    subgraph "Persistence Layer"
        Database["MySQL/PostgreSQL\\n(config/database.php)"]:::db
        Storage["File Storage\\nstorage/app/public/"]:::storage
    end

    subgraph "External Services"
        Mail["Mail Server\\nconfig/mail.php"]:::external
        Queue["Queue Backend\\nconfig/queue.php"]:::external
        Broadcast["Broadcasting\\nconfig/broadcasting.php"]:::external
        CloudStorage["S3 (optional)\\nconfig/filesystems.php"]:::external
    end

    ClientBrowser -->|requests| WebServer
    AssetsJS -->|assets| ClientBrowser
    AssetsCSS -->|assets| ClientBrowser
    Views -->|render| ClientBrowser

    Index --> WebRoutes
    Index --> APIRoutes
    WebRoutes --> AuthMW
    APIRoutes --> AuthMW
    AuthMW --> BaseController
    CsrfMW --> BaseController
    BaseController --> Controllers
    Controllers --> Models
    Models --> Database
    Models --> Observers
    Observers --> Models
    Controllers -->|uploads| Storage
    Controllers -->|dispatch jobs| Queue
    Controllers -->|send mail| Mail
    Controllers -->|broadcast| Broadcast
    Controllers -->|store files| CloudStorage

    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px;
    classDef asset fill:#ff9,stroke:#333,stroke-width:1px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:1px;
    classDef middleware fill:#cfc,stroke:#333,stroke-width:1px;
    classDef controller fill:#fc9,stroke:#333,stroke-width:1px;
    classDef model fill:#9cf,stroke:#333,stroke-width:1px;
    classDef db fill:#cc9,stroke:#333,stroke-width:1px;
    classDef storage fill:#9f9,stroke:#333,stroke-width:1px;
    classDef external fill:#fcc,stroke:#333,stroke-width:1px;

    click AssetsJS "https://github.com/ynthnwhjn/programstok/tree/master/resources/js/"
    click AssetsJS "https://github.com/ynthnwhjn/programstok/tree/master/public/js/"
    click AssetsCSS "https://github.com/ynthnwhjn/programstok/tree/master/resources/css/"
    click AssetsCSS "https://github.com/ynthnwhjn/programstok/tree/master/public/css/"
    click Views "https://github.com/ynthnwhjn/programstok/tree/master/resources/views/"
    click Index "https://github.com/ynthnwhjn/programstok/blob/master/public/index.php"
    click ServerPHP "https://github.com/ynthnwhjn/programstok/blob/master/server.php"
    click Kernel "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Kernel.php"
    click WebRoutes "https://github.com/ynthnwhjn/programstok/blob/master/routes/web.php"
    click APIRoutes "https://github.com/ynthnwhjn/programstok/blob/master/routes/api.php"
    click BaseController "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/Controller.php"
    click AuthController "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/AuthController.php"
    click CrudController "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/CrudController.php"
    click DashboardController "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/DashboardController.php"
    click CustomerController "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/CustomerController.php"
    click ProductController "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/ProductController.php"
    click PurchaseInvCtrl "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/PurchaseInvoiceController.php"
    click SalesInvCtrl "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/SalesInvoiceController.php"
    click StockReportCtrl "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/LaporanStokBarangController.php"
    click BrowseController "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Controllers/Api/BrowseController.php"
    click AuthMW "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Middleware/Authenticate.php"
    click CsrfMW "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Middleware/VerifyCsrfToken.php"
    click EncCookies "https://github.com/ynthnwhjn/programstok/blob/master/app/Http/Middleware/EncryptCookies.php"
    click UserModel "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/User.php"
    click BarangModel "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Mbarang.php"
    click CustSuppModel "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Mcustsupp.php"
    click TJualNotaH "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Tjualnotah.php"
    click TJualNotaD "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Tjualnotad.php"
    click TBeliNotaH "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Tbelinotah.php"
    click TBeliNotaD "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Tbelinotad.php"
    click TStokBarang "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Tstokbarang.php"
    click VariabelModel "https://github.com/ynthnwhjn/programstok/blob/master/app/Models/Variabel.php"
    click Observers "https://github.com/ynthnwhjn/programstok/blob/master/app/Observers/CrudObserver.php"
    click Traits "https://github.com/ynthnwhjn/programstok/tree/master/app/Traits/"
    click ServiceProviders "https://github.com/ynthnwhjn/programstok/tree/master/app/Providers/"
```
