Back to Blog
VS CodeTypeScriptMongoDBProduct DevelopmentOpen Source

From Portfolio Feature to VS Code Extension: How I Built a Coding Time Tracker

Dipish Bisht

Dipish Bisht

February 6, 2026
•
12 min read
From Portfolio Feature to VS Code Extension: How I Built a Coding Time Tracker

A few weeks ago, I was browsing developer portfolios looking for inspiration. I saw someone had a 'Today I Coded' section showing their daily coding hours. Something clicked.

I thought: 'That's a cool feature.' Then I thought: 'Why doesn't something like this exist as a product?' And then: 'Why don't I build it?'

Three weeks later, I had a full VS Code extension in the Marketplace, a MongoDB-backed API, a documentation site, and developers using it in production.

This is that story.

The Idea: From Feature to Product

Most developers track their coding time manually or use complex tools like WakaTime or Toggl. But what if tracking could be completely automatic? What if it just... worked?

That's when I decided to build a VS Code extension. Not just for me — for everyone.

"The best products solve problems you've personally experienced."

The Architecture: Thinking Through the System

Before writing a single line of code, I mapped out the entire flow:

  1. VS Code extension tracks when you type
  2. Detects when you go idle (60 seconds of no activity)
  3. Accumulates time locally
  4. Syncs to an API every 20 minutes
  5. API stores data in MongoDB
  6. Developers fetch their stats via a public API
  7. Stats display on their portfolio websites

Simple concept. Complex execution.

Phase 1: Building the Extension (The Hard Part)

I had never built a VS Code extension before. The VS Code Extension API documentation is good, but it's dense. Here's what I learned:

Challenge 1: Detecting Activity Without Being Intrusive

VS Code has events for everything. The key ones I used:

1vscode.workspace.onDidChangeTextDocument((event) => {
2  // User typed something
3  recordActivity();
4});
5
6vscode.window.onDidChangeActiveTextEditor((editor) => {
7  // User switched files
8  recordActivity();
9});

Every keystroke or file switch resets a timer. If 60 seconds pass with no activity, the session ends.

Challenge 2: Idle Detection That Actually Works

The tricky part: don't count time when the developer steps away. My solution:

1let lastActivityTime = Date.now();
2
3// Heartbeat every second
4setInterval(() => {
5  const idleDuration = Date.now() - lastActivityTime;
6  
7  if (idleDuration >= 60000) {
8    // 60 seconds idle - flush session
9    flushSession();
10  }
11}, 1000);

Here's the key insight: time is credited up to lastActivityTime, NOT Date.now(). This prevents counting idle time.

"Always measure up to the last action, not the current moment."

Challenge 3: Handling Midnight Rollover

What happens if someone codes past midnight? I check the date before accumulating time:

1function checkDateRollover() {
2  const today = getCurrentDate(); // YYYY-MM-DD
3  
4  if (today !== currentDate) {
5    // Midnight crossed - sync old day immediately
6    syncToAPI(yesterdayData);
7    
8    // Reset for new day
9    currentDate = today;
10    todayData = emptyDayData();
11  }
12}

This ensures no time is lost when the calendar date changes.

Phase 2: The Firebase Mistake

Initially, I used Firebase Firestore for storage. It seemed perfect: easy setup, real-time updates, generous free tier.

Then I did the math.

  • Firebase free tier: 20,000 writes per day
  • Each user syncs every 20 minutes = 72 syncs/day
  • 20,000 ÷ 72 = 278 users maximum

If this product grew to even 200 users, Firebase would start charging. That's when I realized: I needed a better backend.

"Free tiers are great for MVPs, but always plan for scale."

Phase 3: Migrating to MongoDB + Custom API

I rebuilt the entire backend from scratch. Here's the new architecture:

1Extension → POST /api/track (Next.js API)
2         ↓
3    Mongoose validates & merges data
4         ↓
5    MongoDB stores in 'tracking' collection
6         ↓
7Portfolio → GET /api/stats/:userId
8         ↓
9    Returns JSON (ready for charts)

Why this is better:

  • MongoDB free tier: 512 MB storage (enough for 100k+ users)
  • Full control over authentication and rate limiting
  • No SDK needed on the client side
  • Can add features like leaderboards later
  • Proper schema validation with Mongoose

The Mongoose Models

I created two collections:

models/User.ts
1const UserSchema = new Schema({
2  userId: { type: String, required: true, unique: true },
3  token: { type: String, required: true, unique: true },
4  name: String,
5  email: String,
6});
models/Tracking.ts
1const TrackingSchema = new Schema({
2  userId: String,
3  date: String, // YYYY-MM-DD
4  totalSeconds: Number,
5  languages: Map, // { typescript: 3600, python: 1800 }
6});
7
8// Compound unique index
9TrackingSchema.index({ userId: 1, date: 1 }, { unique: true });

The compound index ensures one document per user per day. Syncs merge data instead of overwriting.

Phase 4: Building the Documentation Site

A product is only as good as its documentation. I built a full Next.js site with:

  • Homepage with hero section and feature cards
  • Quick Start guide (get running in 5 minutes)
  • API Reference (complete with code examples)
  • Dashboard page (visual stats with charts)
  • Embedding guide (how to use in portfolios)

Design inspiration: Apple, Cal.com, Linear. Minimal, clean, premium feel.

"Good documentation is your product's best marketing."

Phase 5: Integrating Into My Portfolio

The final step: using it myself. I added a 'Coding Stats' section to my portfolio:

components/CodingStats.tsx
1export default function CodingStats() {
2  const [stats, setStats] = useState(null);
3  
4  useEffect(() => {
5    fetch('https://api.example.com/api/stats/MY_USER_ID?limit=30')
6      .then(res => res.json())
7      .then(setStats);
8  }, []);
9  
10  if (!stats) return <Skeleton />;
11  
12  return (
13    <div>
14      <h2>Last 30 Days</h2>
15      <p className="text-4xl">{stats.totalHours} hours</p>
16      <LineChart data={stats.data} />
17    </div>
18  );
19}

It looks professional. It updates automatically. And it proves I actually code every day.

The Challenges Nobody Warns You About

Problem 1: Extension Hot Reload Issues

During development, VS Code would sometimes cache old extension code. Solution:

1# Always recompile before testing
2npm run compile
3
4# Restart the Extension Development Host
5# Don't just reload - fully close and reopen

Problem 2: Token Security

Initially, I stored tokens in VS Code's globalState (unencrypted). Bad idea. Fixed by using the Secrets API:

1// BAD
2context.globalState.update('token', userToken);
3
4// GOOD
5await context.secrets.store('token', userToken);

The Secrets API encrypts data at rest. Much safer.

Problem 3: Network Failures

What if the user loses internet mid-coding? I added an offline queue:

1if (networkError) {
2  offlineQueue.push(data);
3  console.log('Queued for retry');
4}
5
6// On next successful sync
7await drainOfflineQueue();

Data is never lost, even if the API is temporarily unreachable.

Publishing to VS Code Marketplace

This was surprisingly straightforward:

  1. Create Azure DevOps organization (free)
  2. Generate Personal Access Token with 'All accessible organizations' scope
  3. Run vsce login with your publisher name
  4. Run vsce publish to upload

Within 10 minutes, my extension was live in the Marketplace.

"Shipping is a feature. Don't wait for perfection."

How Other Developers Can Use It

The extension is now open for everyone. Here's how developers can integrate it:

Step 1: Install the Extension

1code --install-extension coding-time-tracker

Step 2: Generate a Token

Open Command Palette (Ctrl+Shift+P), run 'Coding Time: Configure API', click 'Generate Token'.

Step 3: Get Your User ID

Run 'Coding Time: Show Today's Stats' to see your unique ID.

Step 4: Embed in Portfolio

1fetch('https://coding-time-api.vercel.app/api/stats/YOUR_ID')
2  .then(res => res.json())
3  .then(data => {
4    console.log(`Total hours: ${data.totalHours}`);
5  });

That's it. The API is public. The dashboard is public. Anyone can use it.

What I Learned

Technical Lessons

  • VS Code Extension API: Event-driven architecture, lifecycle management
  • Mongoose: Schema design, compound indexes, validation
  • Next.js API Routes: Serverless functions, middleware, error handling
  • Token-based auth: Secrets API, bearer tokens, rate limiting
  • Offline-first: Queue systems, retry logic, network error handling

Product Lessons

  • Start with a single use case (your own portfolio)
  • Validate the idea before overbuilding
  • Good documentation is non-negotiable
  • Open source builds trust faster than marketing
  • Free tier limits force you to think about scale

Design Lessons

  • Onboarding should take < 5 minutes
  • Test with someone who's never seen the product
  • Screenshots > paragraphs of explanation
  • Copy every successful product's docs structure
  • Dark mode is expected, not optional

The Current State

As of today:

  • Extension: Live on VS Code Marketplace
  • API: Deployed on Vercel (MongoDB backend)
  • Docs: Full documentation site with examples
  • Dashboard: Visual stats with charts
  • Users: Growing organically through GitHub and word-of-mouth

What's Next?

Future features I'm considering:

  • Weekly digest emails
  • Leaderboard (opt-in)
  • Language recommendations based on trends
  • Export to CSV/JSON
  • Team dashboards for companies
  • GitHub integration (correlate commits with time)

But for now, it works. It's shipped. It's helping developers.

Final Thoughts

Three weeks ago, this was just an idea. Today, it's a product people actually use.

I went from 'I saw a cool feature' to 'I built a product' to 'It's in the Marketplace' faster than I thought possible.

The biggest lesson? Just start building. Don't wait for the perfect idea. Don't wait to learn everything first. Build something small, ship it, and iterate.

"The best time to start was yesterday. The second best time is now."

Resources

If you're a developer, try it out. If you have feedback, open an issue on GitHub. If you want to contribute, PRs are welcome.

And if you're thinking about building your own VS Code extension — do it. You'll learn more in three weeks than you would in three months of tutorials.

Dipish Bisht

Written by Dipish Bisht

Full-stack developer passionate about building scalable web applications and sharing knowledge through writing.

Command Palette

Search for a command to run...