DEV Community

Sarthak Rawat
Sarthak Rawat

Posted on

Stopping the Domino Effect: How I Built Resilico to Protect Community Lending

DEV Weekend Challenge: Community

This is a submission for the DEV Weekend Challenge: Community

The Community

Growing up, I watched my neighborhood operate on trust. When someone needed money for medical bills or to start a small business, they didn't go to a bankβ€”they went to their neighbors. These informal lending circles, common across India and many developing countries, are lifelines for families who fall outside the traditional banking system.

But here's the thing: these communities are fragile. When one person defaults, it doesn't just hurt the lender, it triggers a cascade. The lender can't pay their own obligations, so they default. Then their lenders default. Like dominoes falling, one financial shock can devastate an entire network of families who were just trying to help each other.

I built Resilico for these communities, the savings clubs, lending circles, cooperative societies, and neighborhood networks that keep people afloat but lack the tools to see danger coming.

What I Built

Resilico (Community Financial Stability Simulator) is a full-stack web application that brings institutional-grade financial risk assessment to grassroots communities. Think of it as stress-testing software that central banks use to evaluate systemic riskβ€”but designed for groups of 10-200 people who lend to each other informally.

Core Features:

🌐 Network Graph Visualization

See your community's lending relationships as an interactive graph. Nodes are sized by emergency reserves and color-coded by risk level (green = healthy, red = vulnerable). Instantly spot who's over-leveraged and where contagion could spread.

πŸ“Š Liquidity Simulation

Run week-by-week simulations tracking each member's cash flow. Watch as income arrives, expenses get paid, and loan obligations come due. The system calculates Liquidity Coverage Ratios (LCR) and flags members entering financial distress.

⚑ Default Cascade Engine

When someone defaults, see exactly how the shock propagates through your network. The cascade animation shows step-by-step contagion: who loses money, who gets pushed into default, and how deep the damage goes.

πŸ§ͺ Stress Testing

Run "what-if" scenarios with Monte Carlo simulation:

  • Income shock: What if everyone's income drops 30%?
  • Expense spike: What if medical emergencies hit?
  • Random defaults: What if 5 random members fail?
  • Targeted shock: What if your most central member defaults?

πŸ“ˆ Stability Index (0-100)

A composite score measuring your community's financial resilience, calculated from default rates, liquidity ratios, risk concentration, and network structure.

πŸ€– AI Powered Rules Based Policy Recommendations

Get actionable suggestions based on your data:

  • "Emergency Buffer Increase: Default rate is 23.5%, exceeding the 20% threshold. Recommend mandating minimum emergency reserves of 3x monthly expenses."
  • "Exposure Cap on Central Nodes: Member 42 has centrality 0.87, which is 4.2x the average. Cap single-node exposure to reduce single-point-of-failure risk."

πŸ“„ PDF Reports

Export professional stability reports with all metrics, stress test results, and recommendations for community leaders to review.

Demo

πŸ”— Try Resilico Live
🎬 Watch Demo Video

Quick Start:

  1. Click "Generate Demo Community" to create 50 members with realistic data
  2. Explore the Dashboard to see the stability score
  3. Visit Network to visualize lending relationships
  4. Run a Simulation to see liquidity over time
  5. Try Stress Testing with different scenarios
  6. Export a PDF report

Code

Resilico

Community Financial Stability Simulator (CFSS)

A full-stack web application that simulates and stress-tests the financial stability of small communities (10-200 members). Model systemic risk similar to how central banks stress-test financial institutions.

License Python Next.js FastAPI


🎯 Overview

Resilico helps community financial organizations, microfinance institutions, and researchers understand and mitigate systemic risk in lending networks. By modeling members as nodes and loans as edges in a directed graph, the platform simulates liquidity flows, detects cascade failures, and provides AI-powered policy recommendations.

Key Capabilities

  • Network Modeling - Build detailed financial networks with member profiles and lending relationships
  • Liquidity Simulation - Run week-by-week cash flow simulations tracking distress events
  • Cascade Detection - Model how one default can trigger chain reactions through the network
  • Stress Testing - Monte Carlo scenarios: income shocks, expense spikes, random/targeted defaults
  • Stability Scoring - Composite 0-100 index measuring community financial resilience
  • AI Recommendations - Intelligent policy suggestions powered by Groq AI
…

Project Structure

resilico/
β”œβ”€β”€ client/                 # Next.js frontend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ dashboard/     # Executive dashboard
β”‚   β”‚   β”œβ”€β”€ network/       # Graph visualization
β”‚   β”‚   β”œβ”€β”€ simulation/    # Liquidity simulation
β”‚   β”‚   β”œβ”€β”€ stress-test/   # Stress testing scenarios
β”‚   β”‚   β”œβ”€β”€ data/          # CRUD for members/loans
β”‚   β”‚   └── reports/       # Policy recommendations & PDF export
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ graph/         # NetworkGraph, StabilityGauge, SimulationChart
β”‚   β”‚   └── ui/            # Reusable UI components
β”‚   └── lib/
β”‚       └── api.ts         # API client with TypeScript types
β”‚
└── server/                # FastAPI backend
    β”œβ”€β”€ app/
    β”‚   β”œβ”€β”€ routers/       # API endpoints
    β”‚   β”œβ”€β”€ services/
    β”‚   β”‚   β”œβ”€β”€ engines/   # Simulation, cascade, graph logic
    β”‚   β”‚   └── analysis/  # Stability scoring, policy recommendations
    β”‚   β”œβ”€β”€ db/
    β”‚   β”‚   β”œβ”€β”€ models.py  # SQLAlchemy models
    β”‚   β”‚   └── seed.py    # Demo data generator
    β”‚   └── schemas/       # Pydantic validation models
    └── main.py
Enter fullscreen mode Exit fullscreen mode

Key Technical Highlights

Graph Analysis (NetworkX)

def compute_degree_centrality(G: nx.DiGraph) -> Dict[int, float]:
    return nx.degree_centrality(G)

def compute_trust_propagation(G: nx.DiGraph) -> Dict[int, float]:
    return nx.pagerank(G, weight='probability')
Enter fullscreen mode Exit fullscreen mode

Liquidity Coverage Ratio Calculation

lcr = liquid_assets / upcoming_obligations
if lcr < 1.0:
    state['is_distressed'] = True
Enter fullscreen mode Exit fullscreen mode

Cascade Propagation

def propagate_default(defaulting_members, G, current_state):
    queue = list(defaulting_members)
    cascade_depth = 0

    while queue:
        for borrower_id in queue:
            for lender_id in G.successors(borrower_id):
                exposure = G[borrower_id][lender_id]['amount']
                lender_state['liquid_assets'] -= exposure

                if lender_state['liquid_assets'] < 0:
                    queue.append(lender_id)
        cascade_depth += 1

    return cascade_depth
Enter fullscreen mode Exit fullscreen mode

Stability Index Formula

stability_index = (
    (1 - default_rate) * 0.4 +
    avg_liquidity_ratio * 0.3 +
    (1 - risk_concentration_index) * 0.2 +
    network_resilience_score * 0.1
) * 100
Enter fullscreen mode Exit fullscreen mode

How I Built It

Tech Stack

Frontend:

  • Next.js 16 with App Router for the React framework
  • TypeScript for type safety
  • Tailwind CSS for styling with custom design system
  • Cytoscape.js for interactive network graph visualization
  • Recharts for time-series charts
  • Framer Motion for smooth animations
  • Driver.js for interactive tutorials

Backend:

  • FastAPI for high-performance Python API
  • NetworkX for graph analysis algorithms
  • SQLAlchemy with SQLite (easily switchable to PostgreSQL)
  • Pydantic for request/response validation
  • ReportLab for PDF generation
  • SlowAPI for rate limiting
  • Celery + Redis (optional) for async stress testing

Development Process

Day 1: Core Architecture

  • Set up monorepo structure with client/server separation
  • Designed database schema (members, exposures, simulation_runs, results)
  • Implemented graph engine with NetworkX
  • Built basic API endpoints for CRUD operations

Day 2: Simulation Logic

  • Implemented liquidity simulation with weekly time steps
  • Built default cascade propagation algorithm
  • Added stress testing scenarios (income shock, expense spike, random defaults, targeted shock)
  • Implemented Monte Carlo iteration support

Day 3: Frontend & Visualization

  • Created dashboard with stability gauge and metrics
  • Integrated Cytoscape for network graph
  • Built simulation page with Recharts
  • Added cascade animation with step-through controls

Day 4: Polish & Features

  • Implemented policy recommendation engine
  • Added PDF report generation
  • Built data management CRUD interface
  • Added animations, tutorials, and responsive design
  • Deployed and tested

Challenges & Solutions

Challenge 1: Cascade Termination

Early versions had infinite loops when circular lending existed. Solution: Track processed nodes and implement max iteration limits.

Challenge 2: Graph Performance

Rendering 200+ nodes in Cytoscape was slow. Solution: Optimized layout algorithm parameters and added debouncing to interactions.

Challenge 3: Realistic Demo Data

Random data looked fake. Solution: Researched Indian income distributions and implemented weighted sampling from realistic brackets (β‚Ή8k-β‚Ή100k monthly).

Challenge 4: Making Complexity Accessible

Financial risk modeling is intimidating. Solution: Used color coding (green/yellow/red), animated cascades, and plain-language explanations in recommendations.

Why This Matters

In 2024, I read about a savings club in my city that collapsed when three members lost their jobs during an economic downturn. Thirty families lost their emergency funds. The tragedy wasn't the initial shockβ€”it was that nobody saw the cascade coming.

Resilico won't prevent job losses or medical emergencies. But it can help community leaders ask the right questions:

  • Are we too dependent on one or two wealthy members?
  • Do we have enough collective reserves to survive a shock?
  • What happens if our most central member defaults?

These are questions that banks and governments answer with sophisticated models. Now, communities can too.

What's Next

If this project gains traction, I'd love to:

  • Add mobile app for community leaders
  • Integrate real-time data feeds (if communities want to track actual transactions)
  • Build AI-powered recommendations using LLMs for more nuanced policy suggestions
  • Create educational content about financial resilience
  • Partner with microfinance organizations to pilot in real communities

Built with ❀️ for communities that help each other survive.

Top comments (0)