# learnshare/blog-test architecture

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

- Interactive diagram: https://gitdiagram.com/learnshare/blog-test
- Repository: https://github.com/learnshare/blog-test

## Overview

##### Main Components
- Backend Services:
- Admin API: Found under apps/admin-api, this is the backend service that likely handles administrative tasks (managing accounts, posts, tickets, authentication, etc.).
- API: Located in apps/api, this service appears to provide the core blog functionality for public users – handling posts, files, bookmarks, and more.
- Frontend Applications:
- Admin Web: Under apps/admin-web, this application serves the administrative user interface.
- Web: Located in apps/web, this is the public-facing website likely built using Next.js (as indicated by next.config.ts and the file structure). It handles the user interface for blog readers, authors, and interactive pages.
- Shared Libraries and Utilities:
- packages/lib: Contains shared helper functions such as error handling, HTTP utilities, JWT and MD utilities.
- packages/lib/sdk: This SDK appears to provide programmatic access for both the admin and web frontends.
- packages/database: Serves as the data access layer with database configuration, migrations (using Prisma), and modules for handling accounts, posts, bookmarks, etc.
- Infrastructure & Environment:
- Dockerfiles, docker-compose.yaml, .env files, and pm2.json indicate container orchestration and process management.
- The presence of Nginx configuration files (e.g., .envs/dev/nginx-admin.conf) suggests that reverse proxy and load balancing are part of the deployment.

##### Understand the Relationships and Interactions
- The Admin Web application communicates with the Admin API service to perform back-office tasks.
- The Web application interacts with the API for public blog functionalities such as fetching posts and managing user sessions.
- Both API backends (Admin API and API) rely on the shared database layer (packages/database) for persistence. They use corresponding data models and migrations managed by Prisma.
- Shared libraries (packages/lib and its SDK) are integrated with these apps to provide common functionality (like JWT handling, error management, and HTTP requests).
- Docker and environment configurations indicate that all these components are containerized and may interact over defined network bridges or via a reverse proxy (Nginx).

##### Architectural Patterns and Design Principles
- Microservice/Multi-application Paradigm: While all code is in one repository, separate applications (admin API, API, admin web, and web) underline a separation of concerns, where the backend logic is divided based on user type (administrative vs. public).
- Shared Modules: The repo uses a modular approach for the database and library functions, promoting reuse across applications.
- Containerization: Dockerfiles and docker-compose signal a containerized deployment model, which is essential for replicating the environment reliably in production.

##### Key Technologies and Frameworks
- TypeScript: Evident by the .ts files across the backend and frontend.
- Node.js: The backend services and utilities are built in Node.js.
- Prisma: Used in packages/database for migrations and ORM functionality.
- Next.js: The Web application uses Next.js (as indicated by next.config.ts) for its frontend.
- Vite: The Admin Web application uses Vite for building and development as indicated by vite.config.ts.
- Docker and PM2: For deployment, process management, and environment configuration.

- Two Backend Services: "Admin API" and "API"
- Two Frontend Applications: "Admin Web" and "Web (Next.js)"
- Infrastructure components like "Docker", "PM2", and "Nginx" (if relevant to the architectural view).
- The API calls from Admin Web to Admin API.
- The API calls from Web to API.
- The database connections from both backend services to the Database.
- The integration between frontend apps and shared SDK libraries.
- Notes or legends:
- That the services are containerized.
- Technologies next to each service (e.g., “Admin API (Node.js, TypeScript)”, “Web (Next.js)”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend Services
    subgraph "Backend Services"
        AdminAPI["Admin API (Node.js, TypeScript)"]:::backend
        APIService["API (Node.js, TypeScript)"]:::backend
    end

    %% Frontend Applications
    subgraph "Frontend Applications"
        AdminWeb["Admin Web (Vite)"]:::frontend
        WebApp["Web (Next.js)"]:::frontend
    end

    %% Shared Libraries & Database
    subgraph "Shared Libraries & Database"
        SharedLib["Shared Lib"]:::lib
        SDK["SDK"]:::lib
        Database["Database (Prisma)"]:::database
    end

    %% Infrastructure & Environment
    subgraph "Infrastructure"
        Docker["Docker & Compose"]:::infra
        Env["Environment Config"]:::infra
        Nginx["Nginx Reverse Proxy"]:::infra
        PM2["PM2 (Process Mgmt)"]:::infra
    end

    %% Connections between Frontend and Backend
    AdminWeb -->|"calls"| AdminAPI
    WebApp   -->|"calls"| APIService

    %% Backend Services to Database
    AdminAPI -->|"data-access"| Database
    APIService -->|"data-access"| Database

    %% Backend Services using Shared Lib
    AdminAPI ---|"utilizes"| SharedLib
    APIService ---|"utilizes"| SharedLib

    %% Frontend Applications using SDK
    AdminWeb ---|"usesSDK"| SDK
    WebApp   ---|"usesSDK"| SDK

    %% Infrastructure Connections (containerization and reverse proxy)
    Docker -.-> AdminAPI
    Docker -.-> APIService
    Docker -.-> AdminWeb
    Docker -.-> WebApp
    Docker -.-> Database
    Env -.-> Docker
    Nginx -.-> AdminAPI
    Nginx -.-> APIService
    Nginx -.-> AdminWeb
    Nginx -.-> WebApp
    PM2 -.-> AdminAPI
    PM2 -.-> APIService

    %% Click Events for Component Mapping
    click AdminAPI "https://github.com/learnshare/blog-test/tree/main/apps/admin-api"
    click APIService "https://github.com/learnshare/blog-test/tree/main/apps/api"
    click AdminWeb "https://github.com/learnshare/blog-test/tree/main/apps/admin-web"
    click WebApp "https://github.com/learnshare/blog-test/tree/main/apps/web"
    click SharedLib "https://github.com/learnshare/blog-test/tree/main/packages/lib"
    click SDK "https://github.com/learnshare/blog-test/tree/main/packages/lib/sdk"
    click Database "https://github.com/learnshare/blog-test/tree/main/packages/database"

    %% Styles
    classDef backend fill:#ffdead,stroke:#ff6500,stroke-width:2px;
    classDef frontend fill:#add8e6,stroke:#004,stroke-width:2px;
    classDef lib fill:#98fb98,stroke:#008000,stroke-width:2px;
    classDef database fill:#fffacd,stroke:#daa520,stroke-width:2px;
    classDef infra fill:#d3d3d3,stroke:#696969,stroke-width:2px;
```
