Insight Dashboard
ActiveWebsite 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
- Token never in browserA small backend holds the API token; the browser only gets an HttpOnly session cookie after Google sign-in.
- Public demo, no backendThe same frontend answers every request in the browser from a made-up account, and its CSP blocks the real API.
- Sign-in for Claude, ChatGPTAn OAuth 2.1 server lets AI apps sign in with Google for a read-only media-kit token, with nothing stored.
- Imports 518 → 222 msShipping precompiled bytecode in the Lambda package more than halved the backend's import time on a cold start.
Overview

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
CloudFront + S3
the static SPA, bucket reachable only through OAC
Backend Lambda
checks the session, adds the bearer token
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.

TrendsDoneEvery post against today, yesterday, 7 and 30 days, sortable, with unmeasured shown as a dash.
GoalCompare every post against every time window at once, to see which ones are still being watched rather than which ones are simply old and big.
Post insights are lifetime counters that only climb, so the raw total says how big a post is, not whether anyone is still watching it. The table ranks on the day-over-day gain the agent computes instead.

- Today is only answerable for posts sampled more than once a day, and is counted from the local midnight, not UTC.
- A window ends at a missing day instead of being voided, so one gap does not blank a whole column.
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.

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.
| Failure | What happened | Retry |
|---|---|---|
| Instagram failure | Nothing changed on Instagram | Safe to retry the whole action |
| Recording failure | Instagram succeeded, the record did not | Retry 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.

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 shows | Tag | Effect |
|---|---|---|
| The account’s reply @mentions the commenter, or they are the only other person in the thread | Replied | Sure; flagged in To handle |
| The account only wrote later in the same thread | Probably replied | Dashed tag; never suppresses the suggested reply |

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:
| Change | What it saves |
|---|---|
| No session check before a page loads; the first 401 from a data route sends you to sign-in | A full round trip, usually a cold start |
| Insights draws each panel as its data arrives, requesting in page order | The top of the page fills first instead of waiting on all nine |
| One HTTP client per process instead of one per call | A new connection to the agent on every call |
| Lambda memory from 256 to 1024 MB, still inside the free tier | CPU scales with memory; a cold start spent ~1.8 s on imports and the secret fetch |
| Precompiled bytecode in the package | Imports 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.

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.

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.

- 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.

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
demoenvironment that onlymainmay 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.

- 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.

The backend is the OAuth 2.1 authorization server the agent’s MCP endpoint names. Once the URL is added in the app:
- It registers itself at
/oauth/register(dynamic client registration). /oauth/authorizesends anyone signed out through Google first, against the same invited list.- A consent page names the app and what it will see. Allow returns a one-minute code.
/oauth/tokentrades 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
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.