# mrtaz77/bdstokz architecture

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

- Interactive diagram: https://gitdiagram.com/mrtaz77/bdstokz
- Repository: https://github.com/mrtaz77/bdstokz

## Overview

##### Main Project Components
- Frontend – The Public Directory:
- Contains the static HTML, CSS, JavaScript assets for various pages such as login, dashboard, order list, market view, portfolio, etc.
- That there are distinct sub-folders (e.g., BdStokz_main/login, BdStokz_main/funds, BdStokz_main/market, etc.) representing different UI views and functionalities.
- Backend – Node.js/Express Application:
- The entry point is index.js. There is an app.js along with controllers, routes, middleware, and utilities.
- The controllers (e.g., controller/activity.js, controller/admin.js, etc.) encapsulate business logic related to stock trading operations.
- Routes (found in the “route” directory) define the API endpoints and determine how incoming requests are routed to the appropriate controllers.
- Middleware (such as auth.js and errHandler.js) handles authentication and error processing.
- Database – Oracle Database Integration:
- A configuration is provided in config/database.js and the README instructs how to initialize the Oracle 19c database with provided SQL dump files.
- The SQL Dump folder includes schema definitions, procedures, functions, triggers, and data population scripts.
- Utility Components:
- Utilities in the “util” directory include helper modules for HTTP status codes, field definitions, and input validation.

##### Relationships and Interactions
- User requests initiated from the Frontend (static pages served from the public directory) interact with the Backend via API calls (HTTP requests).
- Requests hit specific routes (e.g., /login, /order, /stock, etc.) which are managed by the Express server.
- The Routes forward the calls to the appropriate Controllers where business logic is executed.
- Middleware (authentication and error handling) is applied to ensure secure and stable communications.
- The Backend then communicates with the Oracle database – either retrieving data (for things like stock search, market status, etc.) or writing/updating data (for order placements and user operations).
- Auxiliary tools such as the SQL Dump population scripts and documentation provide context for database schema and stored procedures.

##### Architectural Patterns and Technologies
- MVC/MV* Pattern: Although not strictly enforced in separate folders, there is a clear separation between frontend (view), controller (business logic), and data (database). The route handling and middleware add additional separation of concerns.
- Client-Server Architecture: The frontend (served as static assets) communicates with the backend REST APIs.
- Use of Express in Node.js: The backend is structured using Express, handling routes, middleware, and controller logic.
- Database Integration: The project integrates with an Oracle 19c Database, making use of provided SQL scripts for schema and procedure initialization.

##### Essential Elements
- Clear Labels: Each component such as “Frontend (Public Assets)”, “API Server (Node.js)”, “Controllers”, “Routes”, “Middleware”, “Oracle Database”, and “Utility Modules” should be clearly labeled.
- From the Frontend (user’s browser) to the Routes/Controllers in the Backend.

##### Additional Suggestions
- Layer down the details: First show the overall flow (User → Frontend → Backend → Database) and then “drill-down” into layering the Express setup (Routes → Controllers → Middleware).
- Separation of concerns: Highlight that the UI (in “public”) is entirely separate from the backend processing logic (in “controller”, “route”, and “middleware” directories).
- Incorporate annotations where necessary to note that the system is built using Node.js, uses Oracle as the database, and that the project is structured to support functionalities like stock buying/selling, stock search, market monitoring, etc.
- For critical components like database interactions, indicate that the SQL Dump folders with scripts and documentation are used for schema initialization, stored procedures, and triggers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User"]:::frontend

    subgraph "Frontend Layer"
        FE["Frontend (Public Assets)"]:::frontend
    end

    subgraph "Backend Layer"
        subgraph "Entry Points"
            JS1["index.js"]:::backend
            JS2["app.js"]:::backend
        end
        RT["Routes"]:::backend
        MW["Middleware"]:::backend
        CT["Controllers"]:::backend
        UT["Utility Modules"]:::backend
    end

    subgraph "Database Layer"
        DB["Oracle Database"]:::database
        DC["Database Config"]:::database
        SD["SQL Dump"]:::database
    end

    U --> FE
    FE --> JS1
    FE --> JS2
    JS1 --> RT
    JS2 --> RT
    RT --> MW
    MW --> CT
    CT --> DB
    CT -->|"uses"| UT
    DC --> DB
    SD --> DB

    click FE "https://github.com/mrtaz77/bdstokz/tree/master/public/BDStokz_main"
    click JS1 "https://github.com/mrtaz77/bdstokz/blob/master/index.js"
    click JS2 "https://github.com/mrtaz77/bdstokz/blob/master/app.js"
    click RT "https://github.com/mrtaz77/bdstokz/tree/master/route/"
    click MW "https://github.com/mrtaz77/bdstokz/tree/master/middleware/"
    click CT "https://github.com/mrtaz77/bdstokz/tree/master/controller/"
    click UT "https://github.com/mrtaz77/bdstokz/tree/master/util/"
    click DC "https://github.com/mrtaz77/bdstokz/blob/master/config/database.js"
    click SD "https://github.com/mrtaz77/bdstokz/tree/master/SQL Dump/"

    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef database fill:#ffa07a,stroke:#000,stroke-width:2px;
```
