# satyamraj2101/linklite architecture

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

- Interactive diagram: https://gitdiagram.com/satyamraj2101/linklite
- Repository: https://github.com/satyamraj2101/linklite

## Overview

##### Main components
- Frontend – Static HTML pages, CSS, and JavaScript files for pages like the dashboard, analytics, authentication (login/signup) and profile. This represents the user interface.
- Backend – Node.js/Express application (with distinct directories for controllers, routes, middleware, migrations, and utility functions). This is where all business logic, link management, and analytics processing occur.
- Database – PostgreSQL backend that stores user data, shortened URLs, and detailed analytics. Migrations in the backend folder indicate schema management.
- Nginx – A separate container with its Dockerfile and configuration used to serve as a reverse proxy, load balancer, or SSL terminator.
- Docker Infrastructure – Dockerfiles in both backend and Nginx directories, as well as docker-compose configurations (available at the project root and within the backend folder), which allow containerized deployment and orchestration.
- GitHub Actions – CI/CD workflows present under .github, ensuring code quality and automated testing/deployment.

##### Relationships and interactions
- The frontend interacts with the backend via HTTP API requests (for user authentication, URL creation and management, and analytics data retrieval).
- The backend handles these requests using its controllers and routes, applying middleware (e.g., authentication and rate limiting) before interacting with the PostgreSQL database.
- The database, managed via migration files and configuration scripts, supports persistent data storage.
- Nginx acts as an intermediary; incoming HTTP requests from clients reach Nginx first, which then routes the traffic to the backend container.
- Docker Compose orchestrates the startup and networking of these different containers ensuring they communicate seamlessly.

##### Architectural patterns and design principles
- Separation of Concerns: Clearly separated frontend (UI assets) from backend (business logic, routing, and data handling).
- MVC-like Structure: The backend follows a Controller and Routing pattern similar to MVC, managing logic and views (using EJS templating for redirection pages).
- Containerization: Use of Docker and Docker Compose for isolated, reproducible deployments.
- Scalability & Security: Use of middleware for authentication, rate limiting, and potential SSL configurations suggest attention to security and reliability.
- CI/CD Integration: GitHub Actions ensures ongoing code quality and automation.

##### Relevant technologies and frameworks
- Node.js and Express for server-side code.
- PostgreSQL as the relational database.
- Docker and Docker Compose for containerization.
- Nginx as a reverse proxy.
- EJS for server-side view rendering.
- GitHub Actions for continuous integration/deployment.
- Frontend plain HTML/CSS/JavaScript files.

– User Requests: Flow from browsers/clients to Nginx (and vice versa for responses).
– API Layer: Communication from the frontend to backend controllers/routes.
– Database Interaction: Backend querying and updating the PostgreSQL database.
– CI/CD Flow: Indicate GitHub Actions pipelines that result in deployment via Docker containers.
– Web UI assets (frontend) versus server-side logic (backend).
– Infrastructure components (Nginx, Docker Compose) versus core application logic.
- Notes on critical middleware functions (authentication, rate limiting) and the role of migrations and views.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client/Browsers"]:::external
    Nginx["Nginx Reverse Proxy"]:::nginx
    Frontend["Frontend (Static Assets)"]:::frontend
    Backend["Backend (Node.js/Express)"]:::backend
    DB["PostgreSQL Database"]:::database
    Migrations["SQL Migrations"]:::database

    Client -->|"HTTP"| Nginx
    Nginx -->|"Routes"| Frontend
    Nginx -->|"Routes"| Backend
    Frontend -->|"APICalls"| Backend
    Backend -->|"Queries"| DB
    Backend -->|"SchemaMgmt"| Migrations
    Migrations -->|"Manages"| DB

    subgraph "Infrastructure"
        direction TB
        DockerRoot["docker-compose.yml (Root)"]:::infra
        DockerBackend["docker-compose.yml (Backend)"]:::infra
        DockerfileBackend["Dockerfile (Backend)"]:::infra
        DockerfileNginx["Dockerfile (Nginx)"]:::infra
        CICD["CI/CD Pipelines (GitHubActions)"]:::cicd
    end

    CICD -->|"Triggers"| DockerRoot
    DockerRoot -->|"Orchestrates"| Nginx
    DockerRoot -->|"Orchestrates"| Backend
    DockerBackend --> Backend
    DockerfileBackend --> Backend
    DockerfileNginx --> Nginx

    click Frontend "https://github.com/satyamraj2101/linklite/tree/master/frontend/"
    click Backend "https://github.com/satyamraj2101/linklite/tree/master/backend/"
    click DB "https://github.com/satyamraj2101/linklite/blob/master/backend/config/db.js"
    click Migrations "https://github.com/satyamraj2101/linklite/tree/master/backend/migrations/"
    click Nginx "https://github.com/satyamraj2101/linklite/tree/master/nginx/"
    click DockerRoot "https://github.com/satyamraj2101/linklite/blob/master/docker-compose.yml"
    click DockerBackend "https://github.com/satyamraj2101/linklite/blob/master/backend/docker-compose.yml"
    click DockerfileBackend "https://github.com/satyamraj2101/linklite/tree/master/backend/Dockerfile"
    click DockerfileNginx "https://github.com/satyamraj2101/linklite/tree/master/nginx/Dockerfile"
    click CICD "https://github.com/satyamraj2101/linklite/tree/master/.github/workflows/"

    classDef frontend fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef backend fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef database fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef nginx fill:#E8DAEF,stroke:#AF7AC5,stroke-width:2px;
    classDef infra fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef cicd fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef external fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
```
