You cannot press pause on development. That is the first thing to accept. Tickets keep arriving, customers expect shipments, and your existing code does not stop running just because you decided to document it. No engineering manager will greenlight a month-long freeze so the team can write the specification that should have existed from day one. OpenSpec was built for reality, not for greenfield fantasies. It works best when you bolt it onto what you already have, customers and all.
The goal here is not a rewrite. It is honest archaeology. You dig up what is actually running in production, describe it accurately, and let that description evolve as your code does. When your specification matches your system, you make life easier for the engineers who join next quarter and for the AI tools that now sit in your IDE. Here is how to do it without missing a single release.
Start With What You Actually Do
Open your repository and you will see folders named controllers, models, services, and utils. Those are technical layers, and they lie to you. They do not describe what your system does for the business. A folder full of JavaScript files does not explain how an order becomes a shipment. To retrofit OpenSpec, you need to think in capabilities.
Look for the stable business operations that would survive even if you rewrote the entire stack in a different language. In most product companies, these show up again and again: Orders, Billing, Inventory, Customers, and Notifications. Name five to eight of these core capabilities.
For each one, force yourself to answer five specific questions. What real-world problem does this capability solve? Where does the code actually live—one service, three microservices, or a legacy module no one wants to touch? What triggers it: a user click, a scheduled cron job, an inbound webhook? What data goes in and what data comes out? And finally, which other systems depend on it, meaning what breaks if this piece stops working?
Be brutally honest. If your "Customers" capability is smeared across a Rails monolith, a Node API, and an external CRM, write that down exactly. Your map has to look like the territory, not an architect's dream.
Write the Truth, Not the Wishlist
The most dangerous sentence in any documentation effort is, "While we're writing this down, we might as well fix it." Stop. You are not redesigning the checkout flow. You are describing the checkout flow that is charging real credit cards right now.
If placing an order triggers an immediate payment capture and then fires an email through a background worker, document that exact sequence. Do not insert an event queue you plan to add next quarter. Do not pretend the validation happens at the API edge if it actually lives deep inside a service class. Accuracy matters far more than aspiration.
Incorrect documentation is worse than none. It trains new hires to expect behavior that does not exist. It sends AI coding assistants down imaginary paths based on wishful thinking. When your spec matches production, you create a reliable baseline. Debugging gets faster because you stop guessing about the "intended" flow. Refactoring gets safer because you know the starting point is real.
Extract Contracts From Your APIs
Your API endpoints already enforce rules. They just keep them implicit. Retrofitting OpenSpec means pulling those rules into the open.
Start with inputs and validation. What does the endpoint actually accept? Document the types, the required fields, the maximum lengths, and the cross-field dependencies. Then describe the business behavior. Does this call create a record, trigger a side effect, or simply validate state against another service? Be specific.
Finally, catalog the responses. What does success return? What are the exact error codes and under what conditions do they appear? Do not write "returns an error." Write "returns 422 when the billing address is missing and 409 when the inventory was already reserved by another process." That level of precision turns a vague route into a contract that frontend teams, QA engineers, and automated tooling can trust.
Hunt Down the Hidden Rules
आपके सिस्टम का कुछ सबसे कीमती ज्ञान अंतराल (gaps) में छिपा होता है। यह सर्विस क्लासेस के भीतर कंडीशनल ब्लॉक्स में दबा होता है, डेटाबेस ट्रिगर्स में छिपा होता है, या उन स्टोर्ड प्रोसीजर में लिखा होता है जिन्हें दो साल से किसी ने छुआ तक नहीं है। ये आपके बिजनेस रूल्स हैं, और इनका पता आमतौर पर आउटेज के दौरान या उस एकमात्र इंजीनियर को ढूंढकर लगाया जाता है जो शुरुआत से वहां मौजूद है।
इन्हें सामने लाएं। उन नियमों से शुरुआत करें जिन्हें आप पहले से जानते हैं। एक निश्चित मूल्य से अधिक के ऑर्डर्स को आगे बढ़ने से पहले मैनेजर की मंजूरी की आवश्यकता होती है। निष्क्रिय यूजर अकाउंट नए ऑर्डर नहीं बना सकते। रिफंड केवल सेटलमेंट पूरा होने से पहले ही अनुमत हैं। प्रत्येक नियम को उस क्षमता (capability) के बगल में लिखें जिसे वह नियंत्रित करता है, और भाषा इतनी स्पष्ट रखें कि एक प्रोडक्ट मैनेजर बिना किसी अनुवादक के इसे पढ़ सके।
जब आप इन नियमों को केंद्रीकृत करते हैं, तो आप केवल उनका दस्तावेजीकरण ही नहीं करते, बल्कि आप दोहराव (duplication) को भी उजागर करते हैं। आप टकरावों (conflicts) को सामने लाते हैं। और आप पूरी टीम को नीति पर चर्चा करने के लिए एक एकल स्थान देते हैं, इससे पहले कि कोई एक लाइन का बदलाव करे जो अनजाने में उस सीमा (constraint) का उल्लंघन कर दे जिसे आप भूल चुके थे।
प्लंबिंग को मैप करें
आधुनिक सिस्टम इवेंट्स (events) पर चलते हैं। एक सर्विस में किया गया एक एक्शन यूजर तक कुछ भी दिखने से पहले आधा दर्जन अन्य सर्विसेज में प्रभाव डालता है। आपको उन प्रभावों का चार्ट बनाने की आवश्यकता है। अपने कोर वर्कफ्लो के लिए एक इवेंट से दूसरे इवेंट तक के प्रवाह को मैप करें। 'ऑर्डर क्रिएट हुआ' से 'इन्वेंट्री रिजर्व हुई' तक, जो 'पेमेंट कन्फर्म' होने का इंतज़ार करती है। पूरी श्रृंखला का चित्रण करें, भले ही कुछ कड़ियाँ नाजुक लगें या अलग-अलग प्रोटोकॉल का उपयोग करती हों।
केवल इंटरनल ट्रैफिक तक ही न रुकें। एक्सटर्नल सर्विसेज भी आपके सिस्टम का हिस्सा हैं, चाहे आप उन्हें इस तरह मानें या नहीं। प्रत्येक इंटीग्रेशन के लिए, उसका उद्देश्य, आपका एप्लिकेशन कैसे ऑथेंटिकेट करता है, और वह कैसे विफल होता है, इसे रिकॉर्ड करें। क्या पेमेंट गेटवे तीस सेकंड के बाद टाइमआउट हो जाता है और एक जेनेरिक 500 एरर देता है? क्या शिपिंग API वीकेंड पर मैल्फॉर्मड JSON लौटाता है? क्या आइडेंटिटी प्रोवाइडर अपने स्वयं के दस्तावेज़ों के दावे से पहले रिफ्रेश टोकन को रिवोक कर देता है? ये विवरण मामूली लग सकते हैं
