ProjectsSocial media automation

Insight Dashboard

Active

Website on top of the Instagram Agent, behind Google sign-in: account growth and post trends, comment topics, AI-reviewed comments and DMs to handle in sync with the tablet, a media kit, and a weekly digest email. It is also where Claude and ChatGPT sign in to read the media kit.

Highlights

Overview

Dashboard Insights page under the six-tab navigation, with a followers card, a posts tracked card, 7/30/90 day toggles and a follower growth chart
The Insights page. The freshness line says which half of the page is sealed daily history and which half is live. All screenshots use a fictional account.

A website for checking my wife’s Instagram account from anywhere, built on top of the Instagram Agent. The tablet is great for a glance at home, but it is stuck on a wall. This is the same data on a phone or a laptop, with more room for tables and for handling comments and DMs.

It has six pages: Insights, Posts, Trends, Comments, Topics and Events, with the media kit and the digest one icon away. A reply, hide, delete or DM goes through the agent, and lands in the same action table the tablet reads. The media kit is also what Claude and ChatGPT can read, once someone signs them in here. A weekly digest email sums up the week, and a public demo runs the same frontend on a made-up cooking account.

Problem

  • The API token is not scoped per account. Any valid management token can read any account, so it must never reach a browser where devtools could pull it out.
  • The site is on the public internet. It has to be reachable from anywhere, but stay private to a few invited people, with no account system to build or run. AI chat apps need a way in too, and none of them can hold a pasted token.
  • Two clients, one to-do list, and a third that keeps no record. A comment answered on the tablet must not still show as “to handle” on the website, and a reply written in the Instagram app records nothing at all.
  • The data has holes that look like zeros. Collection started at different times for different metrics, and daily history is only sealed two days late.
  • The AWS account allows 10 concurrent Lambdas. Each dashboard call uses two (this backend plus the agent), the Insights page asks for nine things at once, and any of them can land on a cold start.

Approach

The browser gets nothing it could leak. The backend holds every secret, the frontend holds a session cookie, and each route is a straight pass-through to the agent scoped to one account ID. Query params and response shapes are forwarded unchanged, so the agent stays the only place where a metric is defined. The public demo follows the same rule from the other side: it has no backend at all, so there is nothing in it to leak.

The UI is honest about what it does not know. A null from the agent is rendered as a dash and sorted last, a window that covered fewer days than it names gets a marker, and the Insights page and the digest both state how fresh each half of their data is.

What I built

Backend proxy and Google sign-inDoneThe browser only holds a session cookie, issued to an invited Google account and rechecked per request.

GoalPut the dashboard on the public internet without the management token, the Google client secret or the session key ever leaving the server side.

Browser

Google sign-in, then an HttpOnly session cookie

two subdomains, one registrable domain

CloudFront + S3

the static SPA, bucket reachable only through OAC

Backend Lambda

checks the session, adds the bearer token

HTTPS + JWT, scoped to one account

Instagram Agent API

metrics, comments, analyses, proxy writes

Architecture

Chose
A thin FastAPI backend in front of the agent
Instead of
A static site calling the agent directly
Why
The agent token is not scoped per account, so a purely client-side app would hand it to anyone who opens devtools.

Sign-in

Chose
Sign in with Google, for a list of invited emails
Instead of
One shared password
Why
Nothing to share or rotate, and the list is checked on every request, so removing an email ends a session already open.

Secrets

Chose
One Secrets Manager entry, values pushed out-of-band
Instead of
Lambda environment variables from Terraform
Why
Env vars are readable with lambda:GetFunctionConfiguration and pass through CI and Terraform state on the way there.

Cookie

Chose
HttpOnly, SameSite=Lax, plus an Origin check on writes
Instead of
SameSite=None
Why
The site and API share kaseovo.com, so Lax works across the two subdomains without weakening CSRF protection.

The backend runs Google’s authorization-code flow itself, with PKCE and a state cookie, so the browser only ever follows redirects and the client secret never leaves the server. Rotating the session key logs every session out, which is the point of rotating it.

InsightsDoneGrowth, audience and posting patterns on one page, each labelled with how fresh its data is.

GoalShow how the account is doing (growth, audience, sentiment, when and how content lands) on one page, without claiming more freshness than the data has.

The page is a stack of chart cards, each backed by one agent route: follower growth (with a marker where the tablet import hands over to the poller), follower momentum at 5-30 minute resolution, daily activity, audience, comment sentiment, reach by content type, engagement by format, the posting slot heatmap and time to 80% reach.

Still pulling card: a ranked list of posts by views gained over the last 7 days, each with a bar and its lifetime total
Still pulling: which posts are still gaining an audience. Views for a Reel, accounts reached for a feed post, since Meta reports one or the other. Fictional data.
Comment handlingDoneReply, hide, delete or acknowledge from the browser, and the tablet's to-do list clears too.

GoalReview the agent's analysis of each new comment and act on it from any device, without the website and the tablet disagreeing about what is left to do.

Comments opens on To handle: analyses with no recorded action, grouped by post, with a filter row to work through one tag at a time. Each row shows the AI’s suggested action, sentiment, reply score and summary. Reply opens the draft for editing, and every write asks for confirmation.

A French question tagged Question with its suggested reply open in an editable box, an English translation of the draft underneath, and a Publish reply button
To handle: the AI suggests, a person edits and publishes. A draft in another language shows its English translation underneath. Fictional account and comments.

The translation runs once when the box opens and is cached by draft text. After an edit it marks itself out of date and offers to redo it, rather than spending the Gemini quota comment analysis needs on every keystroke.

Actions follow the tablet’s write-then-report order: the Instagram write goes through the agent’s proxy first, and only a confirmed result is recorded.

FailureWhat happenedRetry
Instagram failureNothing changed on InstagramSafe to retry the whole action
Recording failureInstagram succeeded, the record did notRetry only the recording, never the post

The list re-syncs every 30 seconds and when the tab regains focus, without dropping comments loaded with “Load more” or a reply being typed.

Direct messagesDoneDMs read as conversations and can be answered or liked until Instagram's 24-hour window closes.

GoalAnswer DMs from the same To handle list as comments, inside the 24-hour window Instagram allows for a reply.

Events shows each conversation as one chat-style card. To handle gets a Direct messages section fed by the agent’s conversation analyses: tags, an English summary, the thread, and the actions below. Past the 24-hour window, only the last one is offered.

  • Reply sends the DM, with the same English translation under the draft.
  • Like hearts the message.
  • Acknowledge or Already done on Instagram records it without sending anything.
Two DM conversations in To handle: a thank-you after the account sent a recipe, with Like suggested, and a question about frying oil, with Reply suggested
DMs in To handle, with the account's own message in pink. The AI suggests a like for a thank-you and a reply for a question. Fictional data.
Replies made in the Instagram appDoneComments answered in the app show as Replied or Probably replied, read from the thread itself.

GoalStop comments answered in the Instagram app from sitting in To handle forever, since a reply written there never reaches the action table.

The thread is the evidence. To handle reads the stored comments from the oldest pending one onwards (usually one request, nothing asked of Instagram), and tags each comment by what the account wrote after it.

What the thread showsTagEffect
The account’s reply @mentions the commenter, or they are the only other person in the threadRepliedSure; flagged in To handle
The account only wrote later in the same threadProbably repliedDashed tag; never suppresses the suggested reply
A comment tagged Probably replied, showing the account's later message in the thread, with Mark as replied first among the actions
A probable reply: the account wrote in the thread afterwards without naming the commenter. Mark as replied records it without touching Instagram. Fictional data.
Faster first loadDonePanels draw as their data lands, and cold-start imports drop from 518 to 222 ms with precompiled bytecode.

GoalOpen the dashboard after a break without waiting 8-10 seconds on Lambda cold starts stacked one behind the other.

Almost all of the wait was cold starts queued behind each other. Five changes cut it down, at no added cost:

ChangeWhat it saves
No session check before a page loads; the first 401 from a data route sends you to sign-inA full round trip, usually a cold start
Insights draws each panel as its data arrives, requesting in page orderThe top of the page fills first instead of waiting on all nine
One HTTP client per process instead of one per callA new connection to the agent on every call
Lambda memory from 256 to 1024 MB, still inside the free tierCPU scales with memory; a cold start spent ~1.8 s on imports and the secret fetch
Precompiled bytecode in the packageImports from 518 to 222 ms, measured locally on Python 3.12
Topics and post ideasDoneComments counted by tag with what is still open, and 3-5 post ideas tied to the comments behind them.

GoalShow what comments are about, not just how many there are, and turn what people ask for into ideas for the next posts.

The agent’s analysis gives each comment one of six tags: question, dish request, tried it, criticism, compliment or other. Topics counts them, then breaks the busiest posts down by tag; a click on a post’s segment opens those comments. The same tags and colours drive the filter row in To handle.

What people talk about card: six tags with a bar each, from 31 questions down to 3 other, each with how many were replied to and how many are open
What people talk about, over 30 days. Each tag says how many got a reply and how many are still open. Fictional data.

Suggest ideas asks the agent for 3-5 post ideas from the window’s comments, each listing the comments it answers. Ideas are generated on demand and never stored: each set is one Gemini call on the same free quota the comment analysis uses.

Ideas for your next posts: three ideas with a title and pitch, the first expanded to show the four comments behind it with Open thread links
Post ideas, each opening onto the comments that asked for it. Fictional data.
Weekly digest emailDoneAn email every Sunday at 20:00 Tokyo time, sent only to people who subscribed and verified themselves.

GoalBring the week to people who will not open the dashboard: the numbers, what is waiting, the posts that did best, what people talked about and ideas for the next posts.

Top of the digest email: follower, views, reach and interactions tiles with week-on-week changes, a Needs you card with comments and DMs waiting, and the most watched posts with their pictures
The top of a digest, rendered by the real template on a made-up week. Account insights cover the newest seven days Meta has sealed; followers are live, and the email says so.
  • Its own Lambda and IAM role, built from the backend’s package, fired by EventBridge Scheduler and sent through SES. The API Lambda never holds permission to send email.
  • A section that fails is reported in the email, not dropped. Silence on a Sunday looks exactly like a quiet week.
  • Post pictures travel inside the message as cid: attachments, because Instagram’s thumbnail links expire within days and an email is read whenever it is read.
  • Each person subscribes themselves on the Digest page, as the Google account they signed in with. A subscriber is a tagged SES identity, so the verification link SES sends is the confirmation.
Public demoDonedashboard-demo.kaseovo.com runs the real frontend on an invented account, with no backend behind it.

GoalLet anyone try the dashboard, replies and DMs included, with no account, no real data, and no way to reach the real one.

Pink demo banner explaining it is a made-up cooking account with nothing connected to Instagram, with a Start over link, above the dashboard's six-tab navigation
The banner on every page of the demo.

A demo build answers every request in the browser, from an invented cooking account laid out around the moment the page opens: the newest post is always a few hours old, and a few comments and a DM arrive while it is open. What a visitor does stays in their own localStorage and resets at their midnight. The switch is a build-time constant, so the normal build drops the demo code entirely.

What keeps it harmless even if its code changes:

  • No backend, no shared state. A Cloudflare Worker serves static files, so nothing one visitor types can reach another.
  • connect-src 'self' in its Content-Security-Policy makes the browser refuse any request off the demo’s own origin, the real API included.
  • The real session cookie is host-only on the API’s subdomain, and the API’s CORS and Origin checks accept only the real dashboard.
  • The Cloudflare token belongs to a demo environment that only main may deploy to, and only the deploy step sees it.
Media kitDoneThe 30-day figures, follower audience and top Reels on one page, with the raw API response to copy.

GoalShow the figures a brand asks for before a collaboration on one page, exactly as the agent's media-kit API serves them, so whatever a brand is sent can be checked against it.

Media kit page: followers with the 30-day gain, accounts reached with accounts engaged, views and engagement rate, then saves, shares, likes and comments
The top of the media kit: Meta's own totals over the last 30 days. The audience and the top Reels sit below. Fictional data.
  • Unknown gender stays in the split. Women’s share of the followers whose gender is known sits beside it, since that is the figure brand PDFs usually quote without saying unknowns were left out.
  • The audience is labelled followers, because that is all Meta reports about who the account reaches.
  • Top Reels are ranked by lifetime views, with their saves, shares and likes.
  • The raw JSON sits under the figures with a Copy button, and the demo answers the route with a made-up kit.
Sign-in for AI appsDoneAI apps sign in with Google and get a 90-day, read-only media-kit token; the backend stores nothing.

GoalLet claude.ai, Claude Desktop and ChatGPT reach the agent's media-kit MCP tool when none of them can send a pasted token, without giving any other website a way to get one for its visitors.

Use it in ChatGPT or Claude card: a name and a URL with copy buttons, a note that authentication is OAuth with Google sign-in, and three numbered steps each for Claude and ChatGPT
The media kit page says what to type where: one name, one URL, OAuth, and the steps in each app.

The backend is the OAuth 2.1 authorization server the agent’s MCP endpoint names. Once the URL is added in the app:

  1. It registers itself at /oauth/register (dynamic client registration).
  2. /oauth/authorize sends anyone signed out through Google first, against the same invited list.
  3. A consent page names the app and what it will see. Allow returns a one-minute code.
  4. /oauth/token trades the code and its PKCE verifier for a media-kit token the agent mints for that person.

What keeps it narrow:

  • Only apps returning to chatgpt.com, claude.ai / claude.com or loopback can register, so no website can get a token for a visitor.
  • The consent page cannot be framed, and its form needs the session, its own origin and a signed token bound to the person it was shown to.
  • Nothing is stored. Client ids, consent forms and codes are JWTs under their own audiences; the agent is what refuses a second token for a code.

Tech stack

Languages

  • TypeScript

    Typed mirrors of the agent API responses, including which fields are null when something was not measured.

Frameworks

  • React

    The single-page app, with React Router and no UI or chart library: every chart is a small hand-written SVG component.

  • FastAPI

    The backend: Google sign-in, signed session cookie, a proxy to the agent that holds the management token, and the OAuth server for AI apps.

Topics

  • Vite

    Dev server with an /api proxy, so local development runs on one origin like production does. A demo mode builds the same app around an in-browser fake API.

  • Google OAuth

    Sign in with Google through the authorization-code flow with PKCE, run server-side, for a list of invited emails.

  • OAuth 2.1

    The authorization server MCP clients sign in to: dynamic client registration, PKCE (S256), a consent page and RFC 9207 issuer, with nothing stored.

  • AWS Lambda

    Two functions from one package: the API behind API Gateway, and the weekly digest. The API runs at 1024 MB and ships precompiled bytecode.

  • S3 + CloudFront

    Static hosting for the SPA; the bucket blocks all public access and is only readable through Origin Access Control. CloudFront also forwards /mcp to the agent, so AI apps connect at the dashboard's own address.

  • Secrets Manager

    Holds the management token, Google client secret and session key, read at runtime rather than set as Lambda env vars.

  • SES + EventBridge Scheduler

    Send the weekly digest every Sunday evening. Subscribers are SES identities, so verifying the address is the opt-in.

  • Cloudflare

    DNS for the dashboard subdomains, and a Worker serving the public demo as static files.

  • Terraform

    Backend, digest, frontend hosting and certificates, deployed from GitHub Actions through an OIDC role.

Future improvements

  • No roles, and no names on actions. Everyone on the invited list can do everything, and the action table does not record who handled a comment.
  • The digest is still in SES’s sandbox. Every subscriber has to verify their address first, and the list is capped at 10.
  • Concurrency is capped client-side. The real fix is raising the AWS Lambda quota, which is a support request rather than a code change.