How robiul-hasan-jisan/cityguard-ai works
1. What this repository is
- CityGuard is a single-repo crime analytics dashboard for San Francisco crime data.
- The architecture is centered on offline analysis + generated visual artifacts + a lightweight Python web UI.
2. Primary data source
- The only raw input tracked in the repo is data/train.csv, which is the historical crime incident dataset.
- The README indicates this is sourced from Kaggle / SFPD crime data, so the app is fundamentally file-backed, not database-backed.
3. Analysis pipeline boundary
- The notebooks/crime-analysis.ipynb notebook is the main analytical workspace.
- It appears to perform the heavy lifting: cleaning, aggregation, anomaly detection, clustering, and chart/map generation.
- This is the repo’s offline compute layer; it likely produces the CSV summaries and HTML outputs consumed by the dashboard.
4. Generated analytics artifacts
- The notebooks/ folder contains multiple derived outputs:
- category_statistics.csv
- cluster_statistics.csv
- district_statistics.csv
- weekly_crime_summary.csv
- summary_report.txt
- sf_crime_map.html
- crime_insights_panel.html
- These files indicate a batch-processing workflow where the notebook materializes results for later viewing, rather than computing everything live.
5. Geospatial subsystem
- A major subsystem is map-based crime visualization.
- The repo uses Folium-style outputs (per README and generated .html files) to render:
- district overlays
- heatmaps
- hotspot/clustering views
- This suggests a clean boundary between spatial analytics and the web UI that displays the resulting map pages.
6. Statistical/ML subsystem
- The README describes weekly trend analysis, anomaly detection, and K-Means clustering.
- Those capabilities are likely implemented in the notebook and summarized into the CSV artifacts.
- In architectural terms, this is the analytics engine: it transforms raw incidents into features, clusters, alerts, and rankings.
7. Web application layer
- The top-level Python files app.py and flask.py represent the application entry points.
- The README describes both Flask and Streamlit variants, but the current tree only includes these top-level Python files, so the repo appears to be a Python-first dashboard UI with at least one Flask-oriented entry point.
- The UI likely reads the generated analytics artifacts and presents them as tabs/charts/maps.
8. Presentation/reporting outputs
- The repo includes demo.mp4 plus HTML panels/maps in notebooks/, which are effectively deliverables rather than core logic.
- These assets support sharing, demos, and static reporting outside the live app.
- The architecture therefore includes both a live dashboard and pre-rendered report artifacts.
9. Dependency stack that shapes the design
- requirements.txt (per README) points to a stack built on:
- pandas/numpy/scipy for data processing
- scikit-learn for clustering
- plotly/matplotlib/seaborn/folium for visualization
- Flask and Streamlit for the UI layer
- This is a local Python analytics app, not a microservice system.
10. Operational model
- There is no evidence of a separate database, message queue, or external API runtime.
- The app likely runs as a single-process local/server-side Python application that loads CSVs and generated artifacts from disk.
- That makes the main boundaries: raw data in data/ → analysis in notebooks → UI in top-level app files → rendered outputs in notebook-generated HTML/CSV.
11. Important repo note for diagram accuracy
- The README mentions files like app_flask.py, app_streamlit.py, templates/index.html, and outputs/, but those are not present in the provided tree.
- For an architecture diagram based on the actual repository contents, treat the notebooks and generated artifacts as the existing core, and treat the README’s extra paths as either planned structure or stale documentation.
Main entry points: crime-analysis.ipynb Analysis notebook · app.py App entry · requirements.txt Deps · README.md README
Components 16
Data
Raw crime data source
- Crime data · Historical San Francisco crime incidents used as the raw input dataset
data/train.csv
Analysis
Offline analytics pipeline
- Analysis notebook · Main notebook that cleans, aggregates, models, and produces derived artifacts
notebooks/crime-analysis.ipynb
UI
Python dashboard entry points
- App entry · Primary Python application entry point for the dashboard
app.py - Flask entry · Additional Flask-oriented application entry point
flask.py - Deps · Dependency specification shaping the analytics, visualization, and web stack
requirements.txt - README · Repository overview and usage notes, including the intended app structure
README.md - Git attrs · Version-control configuration for line ending and file handling
.gitattributes - Git ignore · Ignored files and local environment exclusions
.gitignore
Outputs
Generated artifacts and reports
- Category stats · Category-level aggregation output from the analysis pipeline
notebooks/category_statistics.csv - Cluster stats · Clustering summary output from the analysis pipeline
notebooks/cluster_statistics.csv - District stats · District-level aggregation output from the analysis pipeline
notebooks/district_statistics.csv - Weekly trends · Weekly crime summary used for trend reporting and dashboard views
notebooks/weekly_crime_summary.csv - Summary report · Narrative summary generated by the analysis notebook
notebooks/summary_report.txt - Crime map · Rendered geospatial visualization of crime patterns and hotspots
notebooks/sf_crime_map.html - Insights panel · Pre-rendered insights panel for sharing or embedding in the dashboard
notebooks/crime_insights_panel.html - Demo video · Recorded demonstration of the dashboard and visual outputs
demo.mp4
Connections 18
- Crime data → Analysis notebook: input · Raw incidents are loaded into the offline analysis notebook
- Analysis notebook → Category stats: derive · Notebook produces category-level summary data
- Analysis notebook → Cluster stats: derive · Notebook produces clustering statistics
- Analysis notebook → District stats: derive · Notebook produces district summaries
- Analysis notebook → Weekly trends: derive · Notebook produces weekly trend summaries
- Analysis notebook → Summary report: report · Notebook emits a narrative summary report
- Analysis notebook → Crime map: render · Notebook generates the interactive crime map artifact
- Analysis notebook → Insights panel: render · Notebook generates the insights panel artifact
- App entry → Category stats: read · Dashboard consumes generated analytics artifacts
- App entry → Cluster stats: read · Dashboard consumes generated analytics artifacts
- App entry → District stats: read · Dashboard consumes generated analytics artifacts
- App entry → Weekly trends: read · Dashboard consumes generated analytics artifacts
- App entry → Crime map: embed · Dashboard presents the generated map artifact
- Flask entry → Insights panel: serve · Flask entry point can serve the pre-rendered insights panel
- Deps → Analysis notebook: supports · Dependencies enable data processing, ML, and visualization
- Deps → App entry: supports · Dependencies enable the Python web UI
- README → App entry: documents · README describes the dashboard application entry points and workflow
- README → Analysis notebook: documents · README explains the notebook-driven analytics pipeline