dsa-conscious-coding
Skill2 starsChanged 2 days agoMITView on GitHub
Use when designing, implementing, reviewing, or optimizing any app feature so data structures, algorithms, Big O, and real production tradeoffs are considered before code is written.
In this repository9 other files it gives its agents.
- control-roomSkill
- excalidraw-architectureSkill
- improve-codebase-architectureSkill
- issue-to-phasesSkill
- pr-screenshotsSkill
- raise-prSkill
- visual-reviewerSkill
- wayfinderSkill
- workSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
26 rules. About 0 are common, 24 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈24
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Use this skill whenever you build or review application code.
- Distinctive: line 25
Use a dictionary when you need exact lookup.
- Distinctive: line 26
Use a queue when work must be processed in order.
- Distinctive: line 27
Use a heap when urgent items must be processed first.
- Distinctive: line 28
Use a trie or indexed search when prefix search matters.
- Distinctive: line 29
Use graph thinking when records are connected.
- Distinctive: line 30
Avoid fetching everything and looping when the database can filter/index.
- Distinctive: line 34
Use this skill when:
- Distinctive: line 43
Do not use this to overengineer tiny one-off scripts.
- Distinctive: line 47
Before writing code, answer these five questions:
- Distinctive: line 55
If you cannot answer these, pause and inspect the real requirement first.
- Distinctive: line 115
If a report/API frequently filters by a field, consider indexing that field in the DocType or migration.
- Distinctive: line 126
Do not blindly index every field.
- Distinctive: line 130
If a request sends emails, generates PDFs, syncs APIs, or processes many records, use a background job.
- Distinctive: line 140
Do not block the user request for long operations.
- Distinctive: line 184
If repeated many times, convert to set:
- Distinctive: line 222
Only optimize where data size/access pattern needs it.
- Distinctive: line 230
Test with 10 records and 500+ records.
- Distinctive: line 235
Before marking a feature done, verify:
- Distinctive: line 258
Use SQL filtering instead of Python filtering.
- Distinctive: line 259
Use DB indexes instead of building manual BSTs for persistent records.
- Distinctive: line 260
Use Redis/queue workers instead of custom in-memory queues for production jobs.
- Distinctive: line 261
Use full-text/search engines for serious search.
- Distinctive: line 275
Building clever DSA too early: If the dataset is tiny and will stay tiny, simple code is better.
- Very specific: line 281
Forgetting cycles in graphs: Always track visited in graph traversal unless the graph is guaranteed acyclic.
- Very specific: line 283
Using
list.pop(0)as a queue: Use collections.deque for FIFO queues.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DSA-Conscious Coding
Overview
Use this skill whenever you build or review application code. The goal is not to force complex DSA everywhere. The goal is to choose simple, correct data structures and algorithms that keep the app fast, readable, and maintainable as data grows.
DSA in real projects means asking:
If this data becomes 10x, 100x, or 1000x bigger, will this code still survive?
Good app code usually comes from simple choices made early:
- Use a dictionary when you need exact lookup.
- Use a queue when work must be processed in order.
- Use a heap when urgent items must be processed first.
- Use a trie or indexed search when prefix search matters.
- Use graph thinking when records are connected.
- Avoid fetching everything and looping when the database can filter/index.
When to Use
Use this skill when:
- Writing a new app feature, API, report, job, or dashboard.
- Reviewing code that loops over records, filters data, searches, sorts, or builds summaries.
- Choosing between list, dict, set, queue, heap, tree, graph, or database query.
- Handling Frappe/ERPNext records, background jobs, reports, workflows, document links, or dashboards.
- A feature works on small data but may fail on large data.
- You need to explain the performance or scalability of code.
Do not use this to overengineer tiny one-off scripts. Prefer the simplest structure that satisfies the real data size and access pattern.
Core Rule
Before writing code, answer these five questions:
- What data am I storing?
- How will I access it most often?
- Will I search by exact key, prefix, range, priority, order, or connection?
- What is the expected data size now and later?
- Can the database do this better than in-memory Python?
If you cannot answer these, pause and inspect the real requirement first.
Quick Decision Table
| Need | Prefer | Why |
| Exact lookup by ID/email/name | HashMap / dict / DB indexed lookup | Average O(1) in memory; fast indexed DB lookup |
| Remove duplicates or membership check | set | Average O(1) membership |
| Preserve ordered recent items | list | Simple, direct index access |
| Process first-created item first | Queue / deque | FIFO, O(1) append/pop-left |
| Process latest action first | Stack / list.append/pop | LIFO, O(1) push/pop |
| Process most urgent item first | Heap / Priority Queue | O(log n) insert/pop priority item |
| Search sorted data | Binary Search | O(log n) if data is sorted |
| Prefix/autocomplete search | Trie or search index | Search by typed prefix, not full scan |
| Parent-child hierarchy | Tree | Categories, workflows, accounts, org charts |
| Connected records/routes/dependencies | Graph | BFS/DFS/path/dependency reasoning |
| Frequent range queries/reports | DB indexes, prefix sums, materialized summaries | Avoid repeated full scans |
| Complex filtering over many records | Database query with filters/indexes | DB should reduce data before Python sees it |
Frappe/ERPNext Rules
1. Do not fetch all records and loop unless data is truly small
Bad:
orders = frappe.get_all("Sales Order", fields=["name", "customer", "status"])
for order in orders:
if order.customer == customer:
return orderBetter:
orders = frappe.get_all(
"Sales Order",
filters={"customer": customer},
fields=["name", "customer", "status"],
)Why:
- Bad code moves filtering into Python.
- Better code lets the database filter and use indexes.
2. Use frappe.db.get_value for exact document lookup
Good:
status = frappe.db.get_value("Sales Order", sales_order_name, "status")This is like exact-key lookup. Do not load unnecessary fields or scan lists.
3. Add indexes when filters become common
If a report/API frequently filters by a field, consider indexing that field in the DocType or migration.
Common indexed fields:
nameownercreationmodified- status fields used in dashboards
- foreign keys / Link fields used in reports
Do not blindly index every field. Indexes speed reads but add write/storage cost.
4. Use background queues for slow work
If a request sends emails, generates PDFs, syncs APIs, or processes many records, use a background job.
frappe.enqueue(
"my_app.tasks.process_orders",
queue="long",
timeout=1500,
)Do not block the user request for long operations.
Big O Check Before Finalizing Code
For any loop, ask:
What is n?
How big can n become?
Is this loop inside another loop?
Can this be converted to dict/set/DB filter?Common Patterns
Bad nested lookup
for order in orders:
for customer in customers:
if order.customer == customer.name:
order.customer_name = customer.customer_nameThis is usually O(n * m).
Better:
customer_map = {c.name: c.customer_name for c in customers}
for order in orders:
order.customer_name = customer_map.get(order.customer)This becomes roughly O(n + m).
Bad repeated list membership
if user_email in email_list:
print("exists")If repeated many times, convert to set:
email_set = set(email_list)
if user_email in email_set:
print("exists")Bad sorting inside loop
for item in items:
scores.sort()Sorting repeatedly is expensive. Sort once outside the loop unless the data truly changes every time.
Practical Coding Workflow
- Understand access pattern
- Exact lookup?
- Prefix search?
- Sorted search?
- Priority processing?
- Relationship traversal?
- Choose the simplest fitting structure
listfor ordered small collections.dictfor key-value lookup.setfor membership/deduplication.dequefor FIFO queues.heapqfor priority queues.- DB filter/index for persistent large data.
- Write clear baseline code first
- Make it correct.
- Add tests.
- Only optimize where data size/access pattern needs it.
- Add Explain Mode when teaching or debugging
- Return steps checked.
- Return Big O label.
- Return trace messages.
- Verify with realistic data
- Test with 10 records and 500+ records.
- For production-like features, test with enough data to expose slow loops.
App Feature Checklist
Before marking a feature done, verify:
- No unnecessary
get_allwithout filters for large DocTypes. - No nested loops over large lists unless justified.
- Exact lookups use dict/set or DB indexed lookup.
- Prefix search has a proper strategy: Trie/search index/DB search.
- Priority work uses heap/priority queue thinking.
- Background work uses queue/worker pattern.
- Relationship traversal tracks
visitedto avoid cycles. - Sorting is not repeated unnecessarily.
- Tests cover small, empty, duplicate, and large-ish data cases.
- Code comments explain the DSA choice where it is not obvious.
DSA Is Not Always Manual DSA
In real apps, the best DSA choice is often:
Let the database do it.Examples:
- Use SQL filtering instead of Python filtering.
- Use DB indexes instead of building manual BSTs for persistent records.
- Use Redis/queue workers instead of custom in-memory queues for production jobs.
- Use full-text/search engines for serious search.
Manual DSA is useful for:
- In-memory transformations.
- Small local indexes.
- Algorithms inside one request/job.
- Learning, testing, and explaining performance.
- Cases where database/query tools are not enough.
Common Pitfalls
- Using lists for everything. Lists are simple, but repeated search by value is
O(n). Use dict/set when lookup matters. - Building clever DSA too early. If the dataset is tiny and will stay tiny, simple code is better.
- Ignoring database indexes. In Frappe apps, DB filtering and indexing are often more important than Python data structures.
- Nested loops hidden inside helpers. A helper function inside a loop may create accidental
O(n²)behavior. - Forgetting cycles in graphs. Always track
visitedin graph traversal unless the graph is guaranteed acyclic. - Using
list.pop(0)as a queue. Usecollections.dequefor FIFO queues. - Sorting repeatedly. Sorting inside loops can quietly become a performance killer.
- Optimizing without tests. Performance improvements are useless if behavior changes. Add tests first.
Verification Checklist
- Data access pattern is identified.
- Chosen structure/algorithm matches the access pattern.
- Big O is understood and documented when relevant.
- Frappe/database work is pushed into filters/indexes where possible.
- Code avoids unnecessary full scans and nested loops.
- Edge cases are tested: empty data, missing keys, duplicates, large-ish data.
- If performance matters, compare baseline vs optimized behavior.
- The final implementation remains readable and maintainable.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

