# dstu-diploma/back_monorepo architecture

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

- Interactive diagram: https://gitdiagram.com/dstu-diploma/back_monorepo
- Repository: https://github.com/dstu-diploma/back_monorepo

## Overview

##### Project Type and Purpose
- This is a backend monorepo hosting multiple microservices for a diploma project’s backend.
- The services (chatservice, hackathonservice, teamservice, userservice) each expose HTTP APIs.
- An Nginx reverse-proxy routes incoming traffic; Postgres stores data; Docker Compose handles orchestration.

##### Main Components
a. External Frontend
- Next.js/React application (not in this repo).
- Communicates via HTTP requests to Nginx.
b. Nginx Reverse Proxy
- Entry point for all HTTP(S) from frontend or external clients.
- Routes to individual backend services based on URL paths or host headers.
c. Microservices
- chatservice
- hackathonservice
- teamservice
- userservice
Each runs independently, exposing REST or GraphQL endpoints.
d. Database
- PostgreSQL instance (initialized by dev/init_db.sql).
e. Infrastructure / Orchestration
- Docker Compose (docker-compose.example.yml)
- Makefile targets for setup & startup
- dev/nginx.conf for local proxy settings

##### Relationships & Data Flows
1. Frontend → Nginx: External HTTP requests (Next.js/React → Nginx)
2. Nginx → Microservices: Routes path-based requests to the appropriate service
3. Microservices → Database: Each service issues SQL queries to Postgres
4. Services ↔ Services (optional): If chatservice needs user data, it calls userservice via HTTP or RPC

##### Architectural Patterns & Principles
- Microservice architecture: each business domain is an independent deployable unit.
- Infrastructure as code: Docker Compose and Makefile scripts standardize environments.
- API gateway pattern: Nginx acts as a single entry point routing to services.
- Separation of concerns: different services manage distinct data and logic.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend
    FE["Next.js/React Frontend"]:::frontend

    %% Gateway
    NG["Nginx Reverse Proxy"]:::gateway

    %% Backend Services
    subgraph "Backend Services"
        direction TB
        CHAT["chatservice"]:::service
        HACK["hackathonservice"]:::service
        TEAM["teamservice"]:::service
        USER["userservice"]:::service
    end

    %% Database
    DB["PostgreSQL Database"]:::db

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        COMPOSE["docker-compose.example.yml"]:::infra
        MAKE["Makefile"]:::infra
        INIT["init_db.sql"]:::infra
    end

    %% Data Flows
    FE -->|"HTTP/HTTPS"| NG
    NG -->|"HTTP proxy"| CHAT
    NG -->|"HTTP proxy"| HACK
    NG -->|"HTTP proxy"| TEAM
    NG -->|"HTTP proxy"| USER

    CHAT -->|"SQL queries"| DB
    HACK -->|"SQL queries"| DB
    TEAM -->|"SQL queries"| DB
    USER -->|"SQL queries"| DB

    %% Optional inter-service
    CHAT -.->|"User data API"| USER

    %% Orchestration relationships
    COMPOSE -->|"orchestrates containers"| NG
    COMPOSE -->|"orchestrates containers"| CHAT
    COMPOSE -->|"orchestrates containers"| HACK
    COMPOSE -->|"orchestrates containers"| TEAM
    COMPOSE -->|"orchestrates containers"| USER
    COMPOSE -->|"orchestrates container"| DB

    MAKE -->|"provides targets"| COMPOSE
    INIT -->|"initialization script"| DB

    %% Click Events
    click NG "https://github.com/dstu-diploma/back_monorepo/blob/main/dev/nginx.conf"
    click CHAT "https://github.com/dstu-diploma/back_monorepo/tree/main/chatservice/"
    click HACK "https://github.com/dstu-diploma/back_monorepo/tree/main/hackathonservice/"
    click TEAM "https://github.com/dstu-diploma/back_monorepo/tree/main/teamservice/"
    click USER "https://github.com/dstu-diploma/back_monorepo/tree/main/userservice/"
    click INIT "https://github.com/dstu-diploma/back_monorepo/blob/main/dev/init_db.sql"
    click COMPOSE "https://github.com/dstu-diploma/back_monorepo/blob/main/docker-compose.example.yml"
    click MAKE "https://github.com/dstu-diploma/back_monorepo/tree/main/makefile"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#337ab7,color:#000
    classDef gateway fill:#d4edda,stroke:#28a745,color:#000
    classDef service fill:#ffe5b4,stroke:#ff8c00,color:#000
    classDef db fill:#e2d6f3,stroke:#6f42c1,color:#000
    classDef infra fill:#f0f0f0,stroke:#6c757d,color:#000
```
