# divyesh2508/todoapp architecture

> Architecture diagram of the GitHub repository divyesh2508/todoapp, 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/divyesh2508/todoapp
- Repository: https://github.com/divyesh2508/todoapp

## Overview

##### Project type and purpose
- This is a full-stack, containerized web application (“Dockerize Node-ToDo Application”).
- It uses Node.js/Express as the backend providing a CRUD API and EJS/static files for the frontend, and MongoDB as the data store.
- It’s packaged and deployed via Docker (Dockerfile, docker-compose.yml) with CI/CD pipelines defined in GitHub Actions and Jenkins.

##### File structure
- Top-level directories and files:
- app.js, index.html, views/, public/ → Node/Express server, server-rendered UI and static assets
- Dockerfile, docker-compose.yml → container build and orchestration
- .github/workflows & Jenkinsfile(s) → CI/CD pipelines targeting QA/UAT/PROD and AWS ECR
- test/ → integration tests for the /api/v1 endpoints
- sonar-project.properties, trivy…deb, rollbar.js → code quality, security scanning, error reporting

##### README for additional insights
- Two services are brought up in a Docker network:
1. A MongoDB container with credentials injected as env vars
2. A todoapp container exposing port 3000, connecting to MongoDB over the custom Docker network
- Uses docker-compose for “up –build -d” to create network, volume, and both containers in one command.

##### Main components & interactions (to be shown
a. Presentation Layer
- Browser (client) → HTTP(S) → Node/Express container (port 3000)
- Static assets (public/style.css, index.html) and server-rendered views (views/index.ejs) delivered by the backend
b. Application Layer
- app.js (Express server) exposing RESTful endpoints under /api/v1
- Business logic and validation, integration with Rollbar for error reporting
- CI/CD hooks trigger tests (test/integration/api/v1/test.js) and quality/security scans (SonarQube, Trivy)
c. Data Layer
- MongoDB container (mongoserver4) storing todo data in a Docker volume
- Environment variables: MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD
d. Infrastructure & DevOps
- Docker host or cluster where docker-compose runs both containers on todoapp_network
- CI/CD pipelines:
- GitHub Actions workflows push images to AWS ECR
- Jenkins pipelines deploy to QA, UAT, and Production servers
- Artifact flow: Source repo → CI build → Docker image → Registry (ECR) → Deployment

##### Architectural patterns & design principles
- Three-tier architecture (Presentation, Application, Data)
- Containerization (Docker & docker-compose) for isolation and reproducible environments
- Infrastructure as Code for network, volumes, and build scripts
- Automated CI/CD with quality gates (Sonar, Trivy, integration tests)
- Secure credential management via environment variables

##### Final checklist
[ ] Presentation (Browser) → Express (port 3000)
[ ] Application (app.js + tests + Rollbar)
[ ] Data (MongoDB + Docker volume)
[ ] Docker network boundary enclosing Node and Mongo containers
[ ] CI/CD section: GitHub Actions, Jenkins, AWS ECR, SonarQube, Trivy

## Diagram (Mermaid)

```mermaid
graph TB

    %% Client Layer
    subgraph "Client"
        direction TB
        Browser["Browser\n(Client)"]:::client
    end

    %% Docker Host & Network
    subgraph "Docker Host / todoapp_network" 
        direction TB
        Express["Node/Express Container\nPort 3000"]:::runtime
        DockerCompose["docker-compose.yml"]:::infra
        DockerfileNode["Dockerfile"]:::infra
        subgraph "Static & Views"
            direction TB
            StyleCSS["public/style.css"]:::assets
            IndexHTML["index.html"]:::assets
            IndexEJS["views/index.ejs"]:::assets
        end
        MongoDB["MongoDB Container\nPort 27017"]:::runtime
        Volume["Docker Volume\n(mongo_data)"]:::infra
    end

    %% CI/CD & Registry
    subgraph "CI/CD & Registry" 
        direction TB
        subgraph "GitHub Actions" 
            direction TB
            AWS_ECR_YML["AWS-ECR.yml"]:::cicd
            QA_YML["QA-Server.yml"]:::cicd
            UAT_YML["UAT-Server.yml"]:::cicd
            PROD_YML["PROD-Server.yml"]:::cicd
        end
        subgraph "Jenkins Pipelines"
            direction TB
            JenkinsMain["Jenkinsfile"]:::cicd
            JenkinsDev["Jenkinsfile.dev"]:::cicd
        end
        subgraph "Quality & Tests"
            direction TB
            Sonar["sonar-project.properties"]:::cicd
            Trivy["trivy_0.41.0_Linux-64bit.deb"]:::cicd
            Tests["test.js\n(/api/v1)"]:::cicd
            Fixtures["test.json"]:::cicd
        end
        Build["Docker Build\n(Dockerfile)"]:::cicd
        AWS["AWS ECR Registry"]:::registry
        Deploy["Deploy to Docker Host"]:::cicd
    end

    %% Connections
    Browser -->|"HTTP(S) Request"| Express
    Express -->|"Serves"| StyleCSS
    Express -->|"Serves"| IndexHTML
    Express -->|"Renders"| IndexEJS
    Express -->|"MongoDB Driver\nConnects to port 27017"| MongoDB
    MongoDB -->|"Stores Data"| Volume

    AWS_ECR_YML --> QA_YML
    QA_YML --> UAT_YML
    UAT_YML --> PROD_YML
    AWS_ECR_YML -->|"Triggers"| Build
    JenkinsMain -->|"Triggers"| Deploy
    JenkinsDev -->|"Triggers"| Deploy

    AWS_ECR_YML --> Sonar
    AWS_ECR_YML --> Trivy
    AWS_ECR_YML --> Tests
    Sonar --> Build
    Trivy --> Build
    Tests --> Build

    Build -->|"Push Image"| AWS
    AWS -->|"Pull Image on Deploy"| Deploy
    Deploy -->|"redeploy containers"| DockerCompose

    %% Click Events
    click StyleCSS "https://github.com/divyesh2508/todoapp/blob/main/public/style.css"
    click IndexHTML "https://github.com/divyesh2508/todoapp/blob/main/index.html"
    click IndexEJS "https://github.com/divyesh2508/todoapp/blob/main/views/index.ejs"
    click Express "https://github.com/divyesh2508/todoapp/blob/main/app.js"
    click Express "https://github.com/divyesh2508/todoapp/blob/main/package.json"
    click Express "https://github.com/divyesh2508/todoapp/blob/main/package-lock.json"
    click Express "https://github.com/divyesh2508/todoapp/blob/main/release.config.js"
    click Express "https://github.com/divyesh2508/todoapp/blob/main/rollbar.js"
    click DockerCompose "https://github.com/divyesh2508/todoapp/blob/main/docker-compose.yml"
    click DockerfileNode "https://github.com/divyesh2508/todoapp/tree/main/Dockerfile"
    click AWS_ECR_YML "https://github.com/divyesh2508/todoapp/blob/main/.github/workflows/AWS-ECR.yml"
    click QA_YML "https://github.com/divyesh2508/todoapp/blob/main/.github/workflows/QA-Server.yml"
    click UAT_YML "https://github.com/divyesh2508/todoapp/blob/main/.github/workflows/UAT-Server.yml"
    click PROD_YML "https://github.com/divyesh2508/todoapp/blob/main/.github/workflows/PROD-Server.yml"
    click JenkinsMain "https://github.com/divyesh2508/todoapp/tree/main/Jenkinsfile"
    click JenkinsDev "https://github.com/divyesh2508/todoapp/blob/main/Jenkinsfile.dev"
    click Tests "https://github.com/divyesh2508/todoapp/blob/main/test/integration/api/v1/test.js"
    click Fixtures "https://github.com/divyesh2508/todoapp/blob/main/test/fixtures/test.json"
    click Sonar "https://github.com/divyesh2508/todoapp/blob/main/sonar-project.properties"
    click Trivy "https://github.com/divyesh2508/todoapp/blob/main/trivy_0.41.0_Linux-64bit.deb"

    %% Styles
    classDef client fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef runtime fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef assets fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20
    classDef infra fill:#eeeeee,stroke:#424242,color:#424242
    classDef cicd fill:#dcedc8,stroke:#558b2f,color:#33691e
    classDef registry fill:#ffe0b2,stroke:#e65100,color:#bf360c
```
