How proton1234/subscope works
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: App.tsx React application · SubredditController.cs Subreddit controller · api.ts API client · RedditService.cs Reddit service
Components 21
Frontend
- Browser dashboard
- React application · Routes search, saved-community, detail, and analytics views.
frontend/src/App.tsx - Search panel · Starts lookup and save actions.
frontend/src/components/SearchPanel.tsx - Saved community list · Reloads persisted communities.
frontend/src/components/SavedSubredditList.tsx - Analytics panel · Renders computed engagement results.
frontend/src/components/AnalyticsPanel.tsx - API client · Sends browser requests through the /api proxy.
frontend/src/services/api.ts
ASP.NET Core API
- API startup · Configures dependencies and HTTP application startup.
backend/src/RedditAnalytics.Api/Program.cs - Subreddit controller · Coordinates validation, saved records, live retrieval, and analytics.
backend/src/RedditAnalytics.Api/Controllers/SubredditController.cs - Analytics result · Contains computed score, comment, engagement, and top-post metrics.
backend/src/RedditAnalytics.Api/Models/SubredditAnalytics.cs
Reddit integration
- Reddit service · Obtains OAuth tokens and retrieves community metadata and hot listings.
backend/src/RedditAnalytics.Api/Services/RedditService.cs - Reddit service contract
backend/src/RedditAnalytics.Api/Services/IRedditService.cs - Reddit response DTOs · Isolate Reddit about and listing JSON shapes.
backend/src/RedditAnalytics.Api/Models/RedditAboutResponse.cs - Reddit OAuth API · Provides OAuth-backed subreddit metadata and hot listings.
Persistence
- EF Core context · Centralizes saved-community database access.
backend/src/RedditAnalytics.Api/Data/AppDbContext.cs - Saved subreddit entity · Represents persisted subreddit profile data.
backend/src/RedditAnalytics.Api/Models/SubredditEntity.cs - PostgreSQL · Stores saved subreddit profiles, not live post listings.
- Database bootstrap
database/init.sql
Container runtime
- nginx frontend server · Serves the built frontend and proxies /api traffic.
frontend/nginx.conf - Docker Compose · Connects frontend, API, and PostgreSQL containers.
docker-compose.yml - API container
backend/src/Dockerfile - Frontend container
frontend/Dockerfile
Connections 24
- 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