Skip to content

Implement comprehensive follower stats tracking and dashboard features#10

Merged
jaseva merged 27 commits intomainfrom
shadcn
Apr 23, 2026
Merged

Implement comprehensive follower stats tracking and dashboard features#10
jaseva merged 27 commits intomainfrom
shadcn

Conversation

@jaseva
Copy link
Copy Markdown
Owner

@jaseva jaseva commented Apr 23, 2026

This pull request significantly improves the documentation, analytics code, and project organization for the GitHub Follower Checker. The README is now much more comprehensive, highlighting both the web dashboard and desktop utility, providing clearer setup instructions, and including new visuals and architecture diagrams. The analytics code has been refactored for better plotting and maintainability, and legacy scripts have been properly archived.

Documentation and User Experience Improvements:

  • README.md has been completely rewritten to provide a clear overview of the project, highlight both the web dashboard and desktop utility, include feature tables, setup instructions, visuals, architecture diagrams, and detailed development commands. The structure now makes it much easier for new users and contributors to understand and get started with the project.

Analytics Code Enhancements:

  • Refactored plotting functions in analytics.py to use Matplotlib's object-oriented API, improving date handling and visuals for both follower growth and unfollower trends. Added checks for empty data and improved axis formatting for better clarity. [1] [2] [3]
  • Improved the segment_followers function for more robust and readable segmentation logic.

Project Organization:

  • Added an archive/legacy-follow-scripts/README.md to clarify the status and location of old Selenium follow/unfollow scripts, distinguishing them from the active codebase.

These changes collectively make the project easier to use, maintain, and extend, while also preserving the history of previous approaches.

jaseva added 23 commits May 2, 2025 20:17
mkdir -p backend/app/{api,services}
mkdir frontend
mv analytics.py utils.py backend/app/services/
# keep main.py for reference; hollow it out later
- Set up FastAPI app entry point in backend/app/main.py
- Added CORS middleware for development
- Implemented /ping health check endpoint
- Verified server startup and working route at /ping
- Expose `/stats/followers` FastAPI endpoint returning total, new, and unfollower counts
- Refactor tracker service to extract `get_follower_stats` and `track_followers_job`
- Integrate APScheduler in backend to poll GitHub hourly and update SQLite database
- Configure CORS and scheduler startup in `app/main.py`
- Add `getFollowerStats` API helper in frontend (`lib/api.ts`)
- Scaffold Shadcn Card component to display follower snapshot on the dashboard
- Update `app/page.tsx` to fetch and render real follower stats after sign-in
- Add /stats/followers FastAPI endpoint backed by SQLite with proper `timestamp` column
- Update tracker service to create and populate `followers(timestamp, id)` table on startup
- Fix DB schema migration: include missing `timestamp` field
- Expose getFollowerStats() in lib/api.ts and type Stats
- Enhance Next.js page.tsx:
  • Fetch follower stats on login in useEffect()
  • Render Snapshot card with total_followers, new_followers, unfollowers
  • Update ping button to show status instead of time
  • Handle loading & error states
Add Stats Pydantic model

Refactor tracker.py to initialize SQLite DB, upsert followers, compute total/new counts

Create /stats/followers FastAPI endpoint returning Stats JSON

Wire up APScheduler in main.py for hourly background job and add /ping route

Tighten CORS settings for frontend origin

Update frontend lib/api.ts and app/page.tsx to fetch and render follower snapshot (total, new, unfollowers)

Handle error states and loading for a smoother UX
- Install Recharts and fetch follower trends from /stats/trends
- Extend API client (getFollowerTrends) and types (FollowerSnapshot)
- Update page.tsx:
  • KPI cards for total, new, and lost followers
  • Line chart of historical follower counts
  • Improved layout and UX
- Fix script path for npm in frontend
…d trends endpoints

- Extend API client with getChangeHistory to fetch `/stats/new` and `/stats/lost`
- Update page.tsx to render scrollable New Followers and Lost Followers lists
- Include avatar, username link, and timestamp for each entry
- Improve overall dashboard interactivity

Implement /stats/new, /stats/lost & /stats/trends routes plus corresponding service functions and Pydantic models
Replace local DB-count for total_followers with a call to GitHub’s REST API
Add CORSMiddleware to allow http://localhost:3000 access to API
Expose /stats/new and /stats/lost, implement get_change_history(), and configure FastAPI CORS so Next.js can fetch.
- Added `from app.models import Stats, Trends, Change` at the top of tracker.py
- Ensures Pydantic models are available for type annotations and return values
Multiple features and refactors:

- Add analytics.py for SQLite follower tables, plotting (matplotlib + mdates), segmentation helpers.
- Improve backend API: ping returns {status: ok}; stats endpoints now return JSONResponse and perform error/validation changes.
- Update Pydantic models (typing List[datetime]/List[int]) and add typing imports.
- Refactor services/tracker.py: load .env, initialize DB (init_db), unify DB path, persist follower snapshots, compute 24h deltas, sanitize query ordering/formatting, and return Pydantic models. Small cleanup and formatting.
- Enhance services/analytics.py plotting to use date conversion, guard empty data, and use Axes API.
- Update backend main app: include routers, enable CORS via a variable, set app version.
- Add backend requirements for FastAPI, pydantic, python-dotenv, uvicorn.
- Add two Selenium-based follow/unfollow scripts (follow_unfollow_main.py and follow_unfollow_main_j.py) and a followers.json dataset; remove follower_data.db-journal.
- GUI/main.py tweaks: better connection cleanup, guard OpenAI response, prefill username/token from env, default followers file, fix tab switching state and notebook usage, and minor UI adjustments.

These changes add analytics and automation tooling, harden DB and API behavior, and wire environment configuration into the tracker flow.
Import Change, Stats, and Trends and update endpoints to use response_model and explicit return type hints. Removed manual JSONResponse/.dict() conversions and return the service Pydantic objects directly so FastAPI handles serialization/validation; existing error handling remains.
Expose a /stats/profile endpoint and introduce a GitHubProfile model. Refactor tracker service to centralize GitHub requests (fetch_github_profile) and add get_github_profile mapping to the Pydantic model; get_follower_stats now reuses the shared fetch. Frontend page was revamped into a richer dashboard: added profile fetching, KPI cards, activity panels, range selection, improved chart (AreaChart) and tooltip, Promise.allSettled-based loading, and several UI/UX improvements. Also added GitHubProfile types and getGitHubProfile client, and allowed avatars.githubusercontent.com in next.config for Next/Image remote loading.
Expand and reorganize README with a focused Next.js + FastAPI dashboard guide, environment and run instructions, project structure, and instructions to update the dashboard screenshot. Add the dashboard PNG to docs/screenshots. In backend: broaden CORS origins to include localhost and 127.0.0.1 on ports 3000 and 3001. In tracker service: adjust dotenv loading to prefer a repo-root .env and then override with backend/.env for local overrides.
Update README to document two application experiences (ShadCN-style web dashboard and the legacy Tkinter desktop app), add a desktop screenshots gallery and file structure entries, and clarify screenshot update instructions. Also add docs/screenshots/desktop/README.md listing required desktop screenshot filenames so the root README renders the gallery correctly.
Replace the HTML table gallery in README with a simple list of expected desktop screenshot filenames to avoid broken image links. Add five screenshot files under docs/screenshots/desktop/: followers-tracked.png, not-following-back.png, profile-summary.png, follower-growth-chart.png, and follower-history-json.png. The README can render the gallery again once those images are present.
Completely reorganize and modernize the README: add centered badges and hero image, clarify the repo's two experiences (web dashboard vs desktop utility), and improve Quick Start, install, and run instructions. Document local dev endpoints and base URL, add an architecture diagram, consolidate data/storage notes, and update development/type-check commands. Remove the separate docs/screenshots/desktop/README.md and inline/clean up desktop screenshot references in the root README.
Insert an HTML table into README.md showcasing desktop app screenshots and captions (follower tracking, not-following-back, profile summary, growth chart, saved follower history) and note that the Tkinter desktop app is a legacy local workflow while the web dashboard is the primary experience.
Move legacy root-level scripts into archival folders: relocated main1.py..main12.py to archive/legacy-main-scripts/ and follow_unfollow_main*.py to archive/legacy-follow-scripts/. Add README files to both archive folders and update the repository README to document the archived snapshots. Update pyrightconfig.json to stop listing individual legacy files and to exclude the new archive directory so they don't affect type-checking. This preserves historical scripts while keeping the active codebase and tooling cleaner.
Introduce a consolidated /stats/dashboard endpoint and a richer DashboardData model (metrics, health, annotations, enriched change records). Rework the tracker service: new DB schema (caches, sync_runs, imports, current_followers), snapshot logic, legacy import, user cache, scoring, metrics computation, annotations, and sync routines; expose helper getters (get_dashboard_data, get_follower_stats/profile/trends) and add refresh/params support to API routes. Update Pydantic models to reflect new shapes (DashboardMetrics, DashboardHealth, ChartAnnotation, EnrichedChange, etc.). Frontend page refactored to consume the unified dashboard API and new dashboard components (chart panel, KPI card, change drawer, loading), plus added screenshots and a PowerShell script to kill/refresh the frontend dev port. Misc: adjust docs/README, API typing, request headers, and small config/package updates to support the new features.
@jaseva jaseva self-assigned this Apr 23, 2026
Copilot AI review requested due to automatic review settings April 23, 2026 20:28
@jaseva jaseva added the enhancement New feature or request label Apr 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Implements a new FastAPI-backed follower tracking subsystem with a richer dashboard data model, while expanding documentation and archiving legacy scripts.

Changes:

  • Added a SQLite-backed tracker service that syncs GitHub follower snapshots/changes and computes dashboard metrics, health, and annotations.
  • Introduced Pydantic models + FastAPI endpoints for dashboard/profile/stats/trends/history.
  • Reworked README and reorganized old desktop/Selenium scripts into archive/ for clarity.

Reviewed changes

Copilot reviewed 24 out of 2981 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
backend/app/services/tracker.py New core tracker: SQLite schema/init, GitHub sync, metrics/health/annotations, dashboard aggregation.
backend/app/services/analytics.py Added a Matplotlib-based analytics helper module under backend services.
backend/app/models.py Added Pydantic models for stats, profile, metrics, health, annotations, and dashboard payload.
backend/app/main.py Added FastAPI app with CORS and mounted routers.
backend/app/api/stats.py Added /stats/* endpoints for dashboard and supporting data.
backend/app/api/ping.py Added basic /ping endpoint.
analytics.py Refactored plotting to Matplotlib OO API and improved handling for empty datasets.
README.md Major documentation rewrite describing web dashboard + desktop utility + architecture and commands.
archive/legacy-main-scripts/main1.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main2.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main3.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main4.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main5.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main6.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main7.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main8.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main9.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main10.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main11.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/main12.py Archived legacy desktop script snapshot.
archive/legacy-main-scripts/README.md Documents archived legacy desktop script snapshots.
archive/legacy-follow-scripts/follow_unfollow_main.py Archived legacy Selenium follow/unfollow automation script.
archive/legacy-follow-scripts/follow_unfollow_main_j.py Archived legacy Selenium follow/unfollow automation script variant.
archive/legacy-follow-scripts/README.md Documents archived legacy Selenium follow/unfollow scripts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/app/api/stats.py Outdated
Comment thread backend/app/services/tracker.py Outdated
Comment thread backend/app/services/tracker.py Outdated
Comment thread backend/app/api/stats.py Outdated
Comment thread backend/app/services/tracker.py
Comment thread backend/app/services/analytics.py Outdated
Refactor tracker DB initialization and sync logic to improve concurrency and reliability, and add robust error handling/logging in the stats API.

Changes include:
- Add initialize_tracker_db and remove eager init_db() at import time to avoid races; expose lifespan in FastAPI app to initialize DB at startup.
- Configure SQLite for WAL mode, set busy_timeout, and add write retry/backoff logic to mitigate "database is locked" errors.
- Introduce thread locks (_DB_INIT_LOCK, _SYNC_LOCK) and retry/backoff when syncing; split sync_followers into a guarded retry wrapper and a single-run _sync_followers_once.
- Harden DB usage: ensure proper conn close/rollback handling on errors, validate change tables, and add constants for SQLite timeouts/retry settings.
- Update get_change_history to validate/choose change table earlier and call sync_followers as needed; ensure initialize_tracker_db is invoked by high-level getters.
- Replace async endpoints in backend/app/api/stats.py with sync handlers that use a centralized _raise_service_error and logging; add logger and consistent 500 responses.
- Add lifespan helper in main.py to call initialize_tracker_db during app startup.
- Remove unused analytics.py.

These changes aim to reduce DB lock failures, make startup deterministic, and provide clearer error logging for API consumers.
@jaseva jaseva requested a review from Copilot April 23, 2026 20:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 2980 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/app/services/tracker.py Outdated
Comment thread backend/app/services/tracker.py
Comment thread backend/app/services/tracker.py
Comment thread backend/app/services/tracker.py Outdated
Comment thread backend/app/services/tracker.py Outdated
Comment thread backend/app/services/tracker.py
Comment thread backend/app/services/tracker.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jaseva
Copy link
Copy Markdown
Owner Author

jaseva commented Apr 23, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

@copilot apply changes based on the comments in this thread

All 7 items from that review have already been applied:

  • Authorization: Bearer (applied in 8cb6fda)
  • get_dashboard_data commit user-cache writes on refresh=True (215e7d5)
  • load_dotenv moved out of module import into initialize_tracker_db() (076dcb4)
  • _SYNC_LOCK single-process limitation documented with a comment and sync_followers docstring (076dcb4)

@jaseva jaseva merged commit b85c753 into main Apr 23, 2026
1 check passed
@jaseva
Copy link
Copy Markdown
Owner Author

jaseva commented Apr 23, 2026

Closed

@jaseva jaseva deleted the shadcn branch April 23, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants