How vivganes/zapddit works
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.