# vivganes/zapddit architecture

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

- Interactive diagram: https://gitdiagram.com/vivganes/zapddit
- Repository: https://github.com/vivganes/zapddit

## Overview

##### Project Overview and Type
- zapddit is an Angular-based single-page application (SPA) that functions as a Reddit-style client for the nostr protocol. It leverages Angular’s component-based architecture, Angular services, models, pipes, directives, and utilities.
- Its purpose is to allow users to search for hashtags (instead of sub-reddits), view feeds (populated based on hashtag activity), and perform interactions (like upzaps & downzaps, note composition/replies, etc.) similar to Reddit.

##### Main Components
a. Frontend (Angular Application)
- Angular Module (app.module.ts): Acts as the root module bootstrapping the application.
- Components: Organize by their role in the UI (e.g., event feeds, note composer, community cards, profiles, login page, etc.). These components are found under src/app/component and src/app/page.
- Services: Business logic and backend communications are abstracted here. Include services such as:
▪ community.service.ts
▪ relay.service.ts
▪ topic.service.ts
▪ ndkprovider.service.ts, etc.
- Directives, Pipes, and Filters: These provide additional functionalities (e.g., custom directives for image loading and pipes for formatting timestamps or IDs).
- Utilities & Helpers: Found under src/app/util and similar directories for constants, login utilities and other helper methods.
- Models: Defined under src/app/model, these represent the data structures like user profiles, communities, relays, etc.
- Routing Module: (app-routing.module.ts) is responsible for the navigation between different UI pages.

b. External Integrations / Protocols:
- Nostr Protocol & NIP-07 Login: Authentication and data fetching integrate with the nostr ecosystem.
- QR Code components for upzaps and downzaps.
- Possibly external libraries or APIs for LN wallet connect (although still in progress as per checklist).

##### Relationships and Data Flow
- Routing flow (from login-page, community-list, to detail views like single-post) managed by app-routing.module.ts.
- Interactions where the service layer (e.g., community or relay services) fetches/stores data from remote nostr endpoints or handles caching in object-cache.service.

##### Key Architectural Patterns and Principles
- Component-Based Architecture: Emphasizes modular UI development in Angular.
- Separation of Concerns: UI components, service/business logic, domain models, and routing are all separated in different directories.
- Observable/Data Binding Pattern: Components interact with Angular services that use observable patterns (as suggested by observable-service) to update UI reactively.
- Reusability: The use of common components (e.g., user-pic-and-name, community-card) shows an emphasis on reusability across pages.

##### Technologies and Frameworks
- Angular as the main front-end framework.
- TypeScript for type safety in coding and modularity.
- SCSS for styling components.
- Angular CLI and configuration files (e.g., angular.json) to manage builds and deployments.
- Additional build and configuration tools like package.json, tsconfig.json, and various linting and formatting configuration files.

##### Detailed Architectural Elements
▪ The Routing Module directing traffic between pages (Login, Community List, Single Post, etc.).
▪ A collection of UI components grouped by function.
- Below the UI layer, show a “Service Layer” where each service (community, relay, topic, etc.) interacts with data models and handles business logic.
- External services such as the nostr protocol interface (through NIP-07) and QR Code processing for upzaps/downzaps.
- Utility functions and custom Angular pipes/directives as cross-cutting concerns that serve many components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Angular App
    AR["Angular Root Module"]:::component
    RM["Angular Routing Module"]:::component

    subgraph "UI Layer"
        EF["Event Feed Component"]:::ui
        NC["Note Composer Component"]:::ui
        CC["Community Card Component"]:::ui
        PF["Profile Component"]:::ui
        LP["Login Page Component"]:::ui
    end

    subgraph "Service Layer"
        CS["Community Service"]:::service
        RS["Relay Service"]:::service
        TS["Topic Service"]:::service
        ND["NDK Provider Service"]:::service
    end

    subgraph "Data & Utilities"
        DM["Data Models"]:::data
        DR["Directives"]:::data
        PP["Pipes"]:::data
        UT["Utilities & Helpers"]:::data
    end

    subgraph "External Integrations"
        NP["Nostr Protocol / NIP-07 Login"]:::external
        QR["QR Code Upzap/Downzap"]:::external
    end

    %% Relationships within Angular App
    AR -->|"bootstraps"| RM
    AR -->|"initializes"| EF
    AR -->|"initializes"| NC
    AR -->|"initializes"| CC
    AR -->|"initializes"| PF
    AR -->|"initializes"| LP

    %% UI Layer to Service Layer interactions
    EF -->|"fetches"| CS
    EF -->|"formats"| PP
    NC -->|"composes"| TS
    NC -->|"loads"| DR
    CC -->|"displays"| CS
    PF -->|"retrieves"| CS
    LP -->|"authenticates"| ND

    %% Service Layer to Data & Utilities
    CS -->|"updates"| DM
    RS -->|"updates"| DM
    TS -->|"updates"| DM
    ND -->|"updates"| DM
    CS -->|"uses"| UT
    TS -->|"uses"| UT

    %% Service Layer to External Integrations
    ND -->|"calls"| NP
    RS -->|"calls"| NP
    ND -->|"triggers"| QR

    %% Click Events
    click AR "https://github.com/vivganes/zapddit/blob/main/src/app/app.module.ts"
    click RM "https://github.com/vivganes/zapddit/blob/main/src/app/app-routing.module.ts"
    click EF "https://github.com/vivganes/zapddit/blob/main/src/app/component/event-feed/event-feed.component.ts"
    click NC "https://github.com/vivganes/zapddit/blob/main/src/app/component/note-composer/note-composer.component.ts"
    click CC "https://github.com/vivganes/zapddit/blob/main/src/app/component/community-card/community-card.component.ts"
    click PF "https://github.com/vivganes/zapddit/blob/main/src/app/component/profile/profile.component.ts"
    click LP "https://github.com/vivganes/zapddit/blob/main/src/app/page/login-page/login-page.component.ts"
    click CS "https://github.com/vivganes/zapddit/blob/main/src/app/service/community.service.ts"
    click RS "https://github.com/vivganes/zapddit/blob/main/src/app/service/relay.service.ts"
    click TS "https://github.com/vivganes/zapddit/blob/main/src/app/service/topic.service.ts"
    click ND "https://github.com/vivganes/zapddit/blob/main/src/app/service/ndkprovider.service.ts"
    click DM "https://github.com/vivganes/zapddit/tree/main/src/app/model"
    click DR "https://github.com/vivganes/zapddit/tree/main/src/app/directive"
    click PP "https://github.com/vivganes/zapddit/tree/main/src/app/pipe"
    click UT "https://github.com/vivganes/zapddit/tree/main/src/app/util"

    %% Styles
    classDef component fill:#BBDEFB,stroke:#1F78B4,stroke-width:2px;
    classDef ui fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef service fill:#FFCDD2,stroke:#E53935,stroke-width:2px;
    classDef data fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef external fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
```
