# proton1234/subscope architecture

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

- Interactive diagram: https://gitdiagram.com/proton1234/subscope
- Repository: https://github.com/proton1234/subscope

## Overview

#### Purpose and Entry Points
SubScope is a containerized dashboard for searching Reddit communities, saving their profile data, and computing recent-post engagement analytics. Browser entry is the React application at `frontend/src/main.tsx`, rooted in `frontend/src/App.tsx`. API startup and dependency wiring are in `backend/src/RedditAnalytics.Api/Program.cs`.

#### Frontend Dashboard
The React/TypeScript client presents search, saved-community, detail, and analytics views. `frontend/src/components/SearchPanel.tsx` initiates lookup/save actions; `frontend/src/components/SavedSubredditList.tsx` reloads persisted communities; `frontend/src/components/SubredditDetails.tsx` and `frontend/src/components/AnalyticsPanel.tsx` render profile and computed results. HTTP calls are centralized in `frontend/src/services/api.ts`, forming the frontend/backend boundary.

#### API Surface and Orchestration
ASP.NET Core exposes the application’s HTTP endpoints through `backend/src/RedditAnalytics.Api/Controllers/SubredditController.cs`. This controller coordinates validation, persistence-oriented operations, live Reddit retrieval, analytics requests, and health checking. The API contract is documented in `docs/api.md`; frontend traffic is expected to reach it through the `/api` proxy rather than coupling browser code to backend internals.

#### Reddit Integration and Analytics
`backend/src/RedditAnalytics.Api/Services/IRedditService.cs` defines the external-data boundary, implemented by `backend/src/RedditAnalytics.Api/Services/RedditService.cs`. The service obtains OAuth credentials/tokens and calls Reddit’s OAuth API for subreddit metadata and `/hot` listings. Response DTOs including `backend/src/RedditAnalytics.Api/Models/RedditAboutResponse.cs` and `backend/src/RedditAnalytics.Api/Models/RedditListingResponse.cs` isolate Reddit JSON shapes; analytics are emitted as `backend/src/RedditAnalytics.Api/Models/SubredditAnalytics.cs`.

#### Persistence Boundary
PostgreSQL stores saved subreddit profile records, represented by `backend/src/RedditAnalytics.Api/Models/SubredditEntity.cs`. EF Core access is centralized in `backend/src/RedditAnalytics.Api/Data/AppDbContext.cs`. Database bootstrap/schema ownership is in `database/init.sql`; the live analytics path remains external-data driven rather than persisting post listings.

#### Runtime and Infrastructure
Docker Compose is the local runtime coordinator in `docker-compose.yml`, connecting frontend, API, and PostgreSQL. The frontend is built and served through nginx (`frontend/Dockerfile`, `frontend/nginx.conf`); the .NET 8 API container is defined in `backend/src/Dockerfile`. Reddit client ID/secret enter the backend via Compose environment configuration, with expected values documented by `.env.example`.

#### Primary Flow
A browser search calls the frontend API client, which sends `/api` requests to ASP.NET Core. The controller asks the Reddit service for OAuth-backed community data, maps it to application models, and saves the profile through EF Core/PostgreSQL. Saved-list requests read PostgreSQL directly. Analytics requests fetch the current Reddit hot listing, calculate score/comment/engagement metrics and top posts, then return the result without making the database the source of recent engagement.

Main entry points: [`frontend/src/App.tsx`](https://github.com/proton1234/subscope/blob/main/frontend/src/App.tsx) (React application), [`backend/src/RedditAnalytics.Api/Controllers/SubredditController.cs`](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Controllers/SubredditController.cs) (Subreddit controller), [`frontend/src/services/api.ts`](https://github.com/proton1234/subscope/blob/main/frontend/src/services/api.ts) (API client), [`backend/src/RedditAnalytics.Api/Services/RedditService.cs`](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Services/RedditService.cs) (Reddit service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_browser(("Browser dashboard<br/>user client"))
  node_react_app["React application<br/>React/TypeScript<br/>[App.tsx]"]
  node_search_panel["Search panel<br/>React component<br/>[SearchPanel.tsx]"]
  node_saved_list["Saved community list<br/>React component"]
  node_analytics_panel["Analytics panel<br/>React component<br/>[AnalyticsPanel.tsx]"]
  node_api_client{{"API client<br/>HTTP boundary<br/>[api.ts]"}}
end

subgraph group_api["ASP.NET Core API"]
  node_api_startup["API startup<br/>ASP.NET Core wiring<br/>[Program.cs]"]
  node_subreddit_controller["Subreddit controller<br/>HTTP controller"]
  node_analytics_model["Analytics result<br/>application model"]
end

subgraph group_external["Reddit integration"]
  node_reddit_service["Reddit service<br/>external-data service<br/>[RedditService.cs]"]
  node_reddit_contract["Reddit service contract<br/>service interface<br/>[IRedditService.cs]"]
  node_reddit_dtos["Reddit response DTOs<br/>external DTOs"]
  node_reddit_oauth_api{{"Reddit OAuth API<br/>external API"}}
end

subgraph group_data["Persistence"]
  node_db_context["EF Core context<br/>data access<br/>[AppDbContext.cs]"]
  node_subreddit_entity["Saved subreddit entity<br/>EF entity<br/>[SubredditEntity.cs]"]
  node_postgres[("PostgreSQL<br/>database")]
  node_db_schema["Database bootstrap<br/>SQL schema<br/>[init.sql]"]
end

subgraph group_runtime["Container runtime"]
  node_nginx["nginx frontend server<br/>reverse proxy<br/>[nginx.conf]"]
  node_compose["Docker Compose<br/>local runtime coordinator<br/>[docker-compose.yml]"]
  node_api_container["API container<br/>.NET 8 container"]
  node_frontend_container["Frontend container<br/>nginx container"]
end

node_browser -->|"loads"| node_react_app
node_react_app -->|"renders"| node_search_panel
node_react_app -->|"renders"| node_saved_list
node_react_app -->|"renders"| node_analytics_panel
node_search_panel -->|"lookup and save"| node_api_client
node_saved_list -->|"reload saved"| node_api_client
node_analytics_panel -->|"request analytics"| node_api_client
node_api_client -->|"/api"| node_nginx
node_nginx -->|"proxies requests"| node_api_startup
node_api_startup -->|"maps endpoints"| node_subreddit_controller
node_subreddit_controller -->|"uses"| node_reddit_contract
node_reddit_service -.->|"implements"| node_reddit_contract
node_reddit_service -->|"OAuth, metadata, hot listings"| node_reddit_oauth_api
node_reddit_service -->|"maps responses"| node_reddit_dtos
node_subreddit_controller -->|"returns computed result"| node_analytics_model
node_subreddit_controller -->|"saves and reads profiles"| node_db_context
node_db_context -->|"maps"| node_subreddit_entity
node_db_context -->|"EF Core access"| node_postgres
node_db_schema -->|"initializes schema"| node_postgres
node_compose -->|"runs"| node_frontend_container
node_compose -->|"runs"| node_api_container
node_compose -->|"runs"| node_postgres
node_frontend_container -->|"serves"| node_nginx
node_api_container -->|"hosts"| node_api_startup

click node_react_app "https://github.com/proton1234/subscope/blob/main/frontend/src/App.tsx"
click node_search_panel "https://github.com/proton1234/subscope/blob/main/frontend/src/components/SearchPanel.tsx"
click node_saved_list "https://github.com/proton1234/subscope/blob/main/frontend/src/components/SavedSubredditList.tsx"
click node_analytics_panel "https://github.com/proton1234/subscope/blob/main/frontend/src/components/AnalyticsPanel.tsx"
click node_api_client "https://github.com/proton1234/subscope/blob/main/frontend/src/services/api.ts"
click node_nginx "https://github.com/proton1234/subscope/blob/main/frontend/nginx.conf"
click node_api_startup "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Program.cs"
click node_subreddit_controller "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Controllers/SubredditController.cs"
click node_reddit_service "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Services/RedditService.cs"
click node_reddit_contract "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Services/IRedditService.cs"
click node_reddit_dtos "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Models/RedditAboutResponse.cs"
click node_analytics_model "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Models/SubredditAnalytics.cs"
click node_db_context "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Data/AppDbContext.cs"
click node_subreddit_entity "https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Models/SubredditEntity.cs"
click node_db_schema "https://github.com/proton1234/subscope/blob/main/database/init.sql"
click node_compose "https://github.com/proton1234/subscope/blob/main/docker-compose.yml"
click node_api_container "https://github.com/proton1234/subscope/blob/main/backend/src/Dockerfile"
click node_frontend_container "https://github.com/proton1234/subscope/blob/main/frontend/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_react_app,node_search_panel,node_saved_list,node_analytics_panel,node_api_client toneBlue
class node_api_startup,node_subreddit_controller,node_analytics_model toneAmber
class node_reddit_service,node_reddit_contract,node_reddit_dtos,node_reddit_oauth_api toneMint
class node_db_context,node_subreddit_entity,node_postgres,node_db_schema toneRose
class node_nginx,node_compose,node_api_container,node_frontend_container toneIndigo
```

## Components

### Frontend

- **Browser dashboard**: user client
- [React application](https://github.com/proton1234/subscope/blob/main/frontend/src/App.tsx): React/TypeScript · Routes search, saved-community, detail, and analytics views. · `frontend/src/App.tsx`
- [Search panel](https://github.com/proton1234/subscope/blob/main/frontend/src/components/SearchPanel.tsx): React component · Starts lookup and save actions. · `frontend/src/components/SearchPanel.tsx`
- [Saved community list](https://github.com/proton1234/subscope/blob/main/frontend/src/components/SavedSubredditList.tsx): React component · Reloads persisted communities. · `frontend/src/components/SavedSubredditList.tsx`
- [Analytics panel](https://github.com/proton1234/subscope/blob/main/frontend/src/components/AnalyticsPanel.tsx): React component · Renders computed engagement results. · `frontend/src/components/AnalyticsPanel.tsx`
- [API client](https://github.com/proton1234/subscope/blob/main/frontend/src/services/api.ts): HTTP boundary · Sends browser requests through the /api proxy. · `frontend/src/services/api.ts`

### ASP.NET Core API

- [API startup](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Program.cs): ASP.NET Core wiring · Configures dependencies and HTTP application startup. · `backend/src/RedditAnalytics.Api/Program.cs`
- [Subreddit controller](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Controllers/SubredditController.cs): HTTP controller · Coordinates validation, saved records, live retrieval, and analytics. · `backend/src/RedditAnalytics.Api/Controllers/SubredditController.cs`
- [Analytics result](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Models/SubredditAnalytics.cs): application model · Contains computed score, comment, engagement, and top-post metrics. · `backend/src/RedditAnalytics.Api/Models/SubredditAnalytics.cs`

### Reddit integration

- [Reddit service](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Services/RedditService.cs): external-data service · Obtains OAuth tokens and retrieves community metadata and hot listings. · `backend/src/RedditAnalytics.Api/Services/RedditService.cs`
- [Reddit service contract](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Services/IRedditService.cs): service interface · `backend/src/RedditAnalytics.Api/Services/IRedditService.cs`
- [Reddit response DTOs](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Models/RedditAboutResponse.cs): external DTOs · Isolate Reddit about and listing JSON shapes. · `backend/src/RedditAnalytics.Api/Models/RedditAboutResponse.cs`
- **Reddit OAuth API**: external API · Provides OAuth-backed subreddit metadata and hot listings.

### Persistence

- [EF Core context](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Data/AppDbContext.cs): data access · Centralizes saved-community database access. · `backend/src/RedditAnalytics.Api/Data/AppDbContext.cs`
- [Saved subreddit entity](https://github.com/proton1234/subscope/blob/main/backend/src/RedditAnalytics.Api/Models/SubredditEntity.cs): EF entity · Represents persisted subreddit profile data. · `backend/src/RedditAnalytics.Api/Models/SubredditEntity.cs`
- **PostgreSQL**: database · Stores saved subreddit profiles, not live post listings.
- [Database bootstrap](https://github.com/proton1234/subscope/blob/main/database/init.sql): SQL schema · `database/init.sql`

### Container runtime

- [nginx frontend server](https://github.com/proton1234/subscope/blob/main/frontend/nginx.conf): reverse proxy · Serves the built frontend and proxies /api traffic. · `frontend/nginx.conf`
- [Docker Compose](https://github.com/proton1234/subscope/blob/main/docker-compose.yml): local runtime coordinator · Connects frontend, API, and PostgreSQL containers. · `docker-compose.yml`
- [API container](https://github.com/proton1234/subscope/blob/main/backend/src/Dockerfile): .NET 8 container · `backend/src/Dockerfile`
- [Frontend container](https://github.com/proton1234/subscope/blob/main/frontend/Dockerfile): nginx container · `frontend/Dockerfile`

## Connections

- Browser dashboard → React application: loads
- React application → Search panel: renders
- React application → Saved community list: renders
- React application → Analytics panel: renders
- Search panel → API client: lookup and save
- Saved community list → API client: reload saved
- Analytics panel → API client: request analytics
- API client → nginx frontend server: /api
- nginx frontend server → API startup: proxies requests
- API startup → Subreddit controller: maps endpoints
- Subreddit controller → Reddit service contract: uses
- Reddit service → Reddit service contract: implements
- Reddit service → Reddit OAuth API: OAuth, metadata, hot listings
- Reddit service → Reddit response DTOs: maps responses
- Subreddit controller → Analytics result: returns computed result
- Subreddit controller → EF Core context: saves and reads profiles
- EF Core context → Saved subreddit entity: maps
- EF Core context → PostgreSQL: EF Core access
- Database bootstrap → PostgreSQL: initializes schema
- Docker Compose → Frontend container: runs
- Docker Compose → API container: runs
- Docker Compose → PostgreSQL: runs
- Frontend container → nginx frontend server: serves
- API container → API startup: hosts
