# obiwan00/question-answer architecture

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

- Interactive diagram: https://gitdiagram.com/obiwan00/question-answer
- Repository: https://github.com/obiwan00/question-answer

## Overview

##### Project type and purpose
- This is a full-stack monorepo (Nx) application:
- Frontend: Angular 14 SPA with Angular Material, HTTP APIs + WebSocket chats
- Backend: NestJS 9 REST + WebSocket (Socket.io) server, TypeORM & PostgreSQL
- Shared “api-interfaces” library for DTOs/models

##### File structure
- Top level:
- apps/client → Angular application
- apps/server → NestJS application
- libs/api-interfaces → shared TypeScript interfaces (Answer, Chat, Message, Tag, Topic, User)
- Client follows Angular’s modular MVC: core/auth/layout/services, feature modules (topic, answer, chat), shared/components
- Server follows NestJS modular MVC: modules (User, Topic, Answer, Tag, Chat), controllers, services, DTOs, entities, WebSocket gateway
- TypeORM config, migrations and seeds under apps/server/src/typeorm
- CI/config: Nx workspace files, tsconfigs, lint and prettier rules

##### README insights
- “Simplified clone of StackOverflow with chats per topic”
- Communication: REST for CRUD operations, Socket.io for chat messages
- Monorepo managed with Nx—allows generating apps/libs, running affected tests, visualizing dependency graph

a. Main components
- Client (Angular SPA)
- Server (NestJS REST & WebSocket)
- Database (PostgreSQL via TypeORM)
- Shared Interfaces (api-interfaces)
- Nx Dev Tools (build/test orchestrator)

b. Relationships & interactions
- Client ↔ Server (HTTP REST for auth, topics, answers, tags)
- Client ↔ Server (WebSocket/Socket.io for chat messages)
- Server ↔ Database (TypeORM entities ↔ PostgreSQL)
- Client & Server ← shared DTOs via libs/api-interfaces

c. Architectural patterns & design principles
- Frontend: modular feature-based Angular architecture (core vs shared vs feature modules)
- Backend: modular NestJS architecture (per-feature modules, controllers, services, middleware/guards)
- Layered separation: presentation (controllers/components), business logic (services), persistence (TypeORM repositories/entities)
- Single source of truth for API contracts via shared DTO library
- WebSocket gateway pattern for real-time chat

d. Key technologies
- Angular 14, Angular Material, RxJS, Socket.io-client
- NestJS 9, TypeORM, Socket.io-server
- PostgreSQL
- Nx (monorepo toolkit)

##### Detail level
- High-level modules on both sides (Auth, Topic, Answer, Tag, Chat)
- Middleware/guards (e.g. AuthGuard) intercepting REST calls
- TypeORM layer (entities, migrations) connecting to PostgreSQL
- Socket gateway handling chat namespace

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Root nodes
    ClientRoot["Angular Client"]:::frontend
    ServerRoot["NestJS Server"]:::backend
    Shared["API Interfaces Library"]:::shared
    Nx["Nx Workspace Tools"]:::tooling
    DB["PostgreSQL DB"]:::db

    %% Frontend Modules
    subgraph "Frontend (Angular SPA)"
        Auth["Auth Module"]:::frontend
        Guards["Guards"]:::frontend
        Layout["Layout Module"]:::frontend
        CoreServices["Core Services"]:::frontend

        TopicF["Topic Feature Module"]:::frontend
        AnswerF["Answer Feature Module"]:::frontend
        ChatF["Chat Feature Module"]:::frontend

        Spinner["Spinner"]:::frontend
        Rating["Rating"]:::frontend
        SearchBar["Search Bar"]:::frontend
    end

    %% Backend Modules
    subgraph "Backend (NestJS)"
        UserB["User Module"]:::backend
        TopicB["Topic Module"]:::backend
        AnswerB["Answer Module"]:::backend
        TagB["Tag Module"]:::backend
        ChatB["Chat Module (Gateway)"]:::backend

        Entities["TypeORM Config / Migrations"]:::backend
    end

    %% Relationships
    ClientRoot --> Auth
    ClientRoot --> Guards
    ClientRoot --> Layout
    ClientRoot --> CoreServices
    ClientRoot --> TopicF
    ClientRoot --> AnswerF
    ClientRoot --> ChatF
    ClientRoot --> Spinner
    ClientRoot --> Rating
    ClientRoot --> SearchBar

    ServerRoot --> UserB
    ServerRoot --> TopicB
    ServerRoot --> AnswerB
    ServerRoot --> TagB
    ServerRoot --> ChatB
    ServerRoot --> Entities

    Auth -->|REST| UserB
    TopicF -->|REST| TopicB
    AnswerF -->|REST| AnswerB
    ChatF -.->|WebSocket| ChatB
    CoreServices -->|REST| Auth
    CoreServices -.->|WebSocket| ChatB

    Entities -->|SQL Queries| DB

    Shared -->|DTOs| ClientRoot
    Shared -->|DTOs| ServerRoot

    Nx --> ClientRoot
    Nx --> ServerRoot
    Nx --> Shared

    %% Click Events
    click ClientRoot "https://github.com/obiwan00/question-answer/tree/main/apps/client"
    click Auth "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/core/auth"
    click Guards "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/core/guards"
    click Layout "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/core/layout"
    click CoreServices "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/core/services"
    click TopicF "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/topic"
    click AnswerF "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/answer"
    click ChatF "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/chat"
    click Spinner "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/shared/components/spinner"
    click Rating "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/modules/components/rating"
    click SearchBar "https://github.com/obiwan00/question-answer/tree/main/apps/client/src/app/modules/components/search-bar"
    click Shared "https://github.com/obiwan00/question-answer/tree/main/libs/api-interfaces"
    click ServerRoot "https://github.com/obiwan00/question-answer/tree/main/apps/server"
    click UserB "https://github.com/obiwan00/question-answer/tree/main/apps/server/src/user"
    click TopicB "https://github.com/obiwan00/question-answer/tree/main/apps/server/src/topic"
    click AnswerB "https://github.com/obiwan00/question-answer/tree/main/apps/server/src/answer"
    click TagB "https://github.com/obiwan00/question-answer/tree/main/apps/server/src/tag"
    click ChatB "https://github.com/obiwan00/question-answer/tree/main/apps/server/src/chat"
    click Entities "https://github.com/obiwan00/question-answer/tree/main/apps/server/src/typeorm"
    click Nx "https://github.com/obiwan00/question-answer/blob/main/nx.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#3385FF
    classDef backend fill:#D0FFD8,stroke:#28A745
    classDef db fill:#FFDFA3,stroke:#D39E00
    classDef shared fill:#FFE4B3,stroke:#E69500
    classDef tooling fill:#E3E3E3,stroke:#8F8F8F
```
