# smi0001/crudapp architecture

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

- Interactive diagram: https://gitdiagram.com/smi0001/crudapp
- Repository: https://github.com/smi0001/crudapp

## Overview

##### Project Type and Purpose
- This is a full-stack CRUD web application built on Node.js/Express with MongoDB as the data store. It uses EJS for server-side page rendering and serves CSS/JS assets from a static folder. It’s deployed on Heroku.

##### Main Architectural Components
a. Client Side
- Web Browser
- Static assets (HTML, CSS, JS, fonts, images) under /static
- EJS templates under /views
b. Server Side
- Node.js runtime
- Express application (defined in server.js)
- Configuration loader (config.js, _config.yml)
- Route handlers (CRUD endpoints)
- Template engine integration (EJS)
c. Database
- MongoDB instance (e.g., mLab addon on Heroku)
d. Platform/Infrastructure
- Heroku dyno
- GitHub (source code repository)
- Heroku CLI & build pipeline

##### Relationships and Data Flow
- The Browser initiates HTTP requests to the Express server (hosted on a Heroku dyno).
- Express routing logic in server.js directs each request to the appropriate controller:
- GET routes fetch data from MongoDB via Mongoose
- POST/PUT/DELETE routes modify data in MongoDB
- Controllers pass data to EJS templates, which render HTML.
- The server responds with HTML pages or JSON (if it exposes any API endpoints).
- Static middleware serves files under /static directly to the client.
- Configuration (e.g., database URI, port) is read from config.js and environment variables (Heroku’s PORT, MONGODB_URI).

##### Architectural Patterns & Design Principles
- MVC-style separation:
- Model: MongoDB collections accessed via Mongoose
- View: EJS templates
- Controller: Express route handlers in server.js
- Convention-over-configuration:
- Static assets in one folder
- Views in one folder
- Twelve-factor app practices for Heroku:
- Configuration in environment variables
- Procfile (optional) for process declaration
- Git-based deployments

##### Detailed Checklist
- [ ] Heroku Platform layer
- [ ] Express server component (server.js, config.js)
- [ ] Static assets folder (/static)
- [ ] View layer (/views)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Browser["Web Browser"]:::client

    %% Infrastructure Layer
    subgraph "Infrastructure"
        GitHub["GitHub Repository"]:::infra
        Heroku["Heroku Platform"]:::infra
    end

    %% Deployment Pipeline
    GitHub -->|"git push heroku master"| Heroku
    Heroku -->|"Build & Deploy"| Dyno

    %% Dyno (Runtime)
    subgraph "Heroku Dyno"
        Dyno["Dyno Runtime"]:::infra
        Express["Express App\n(server.js)"]:::server
        Config["Config Loader\n(config.js, _config.yml)"]:::server
        Static["Static Middleware\n/static"]:::server
        Views["EJS Templates\n/views"]:::server
    end

    %% Database Layer
    DB[(MongoDB Database)]:::db

    %% Request Flow
    Browser -->|"HTTP Request"| Express
    Express -->|"GET/POST/PUT/DELETE"| DB
    DB -->|"Query Results"| Express
    Express -->|"Render EJS Templates"| Views
    Views -->|"HTML Response"| Browser
    Express -->|"Serve Static Assets"| Static
    Static -->|"CSS/JS/Images"| Browser
    Config -->|"Load Env Vars"| Express

    %% Repository Files
    subgraph "GitHub Repo Contents"
        README["README.md"]:::repo
        PackageJSON["package.json"]:::repo
        PackageLock["package-lock.json"]:::repo
        RootHTML["index.html"]:::repo
    end
    GitHub -->|"Contains"| README
    GitHub -->|"Contains"| PackageJSON
    GitHub -->|"Contains"| PackageLock
    GitHub -->|"Contains"| RootHTML

    %% Click Events
    click Express "https://github.com/smi0001/crudapp/blob/master/server.js"
    click Config "https://github.com/smi0001/crudapp/blob/master/config.js"
    click Config "https://github.com/smi0001/crudapp/blob/master/_config.yml"
    click Static "https://github.com/smi0001/crudapp/tree/master/static/"
    click Views "https://github.com/smi0001/crudapp/tree/master/views/"
    click PackageJSON "https://github.com/smi0001/crudapp/blob/master/package.json"
    click PackageLock "https://github.com/smi0001/crudapp/blob/master/package-lock.json"
    click README "https://github.com/smi0001/crudapp/blob/master/README.md"
    click RootHTML "https://github.com/smi0001/crudapp/blob/master/index.html"

    %% Styles
    classDef client fill:#B3D4FC,stroke:#0366d6,color:#0366d6;
    classDef server fill:#D4FCD3,stroke:#28a745,color:#28a745;
    classDef db fill:#FFE4B5,stroke:#FF8C00,color:#FF8C00;
    classDef infra fill:#E0E0E0,stroke:#666666,color:#333333;
    classDef repo fill:#F0F0F0,stroke:#999999,color:#555555;
```
