From 39d79950a3b15d507dd05afa11ce24b05c291170 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Oct 2026 17:12:35 +0000 Subject: [PATCH 1/3] Add contributor docs, templates, CI, and env scaffolding Co-authored-by: Harshall25 <191145090+Harshall25@users.noreply.github.com> --- .env.example | 10 ++ .github/ISSUE_TEMPLATE/bug_report.md | 33 +++++ .github/ISSUE_TEMPLATE/config.yml | 5 + .../documentation_improvement.md | 22 +++ .github/ISSUE_TEMPLATE/feature_request.md | 26 ++++ .github/PULL_REQUEST_TEMPLATE.md | 21 +++ .github/workflows/ci.yml | 43 ++++++ .gitignore | 4 +- CODE_OF_CONDUCT.md | 127 ++++++++++++++++++ CONTRIBUTING.md | 94 +++++++++++++ README.md | 100 ++++++++++---- application.py | 17 ++- database.py | 2 +- 13 files changed, 466 insertions(+), 38 deletions(-) create mode 100644 .env.example create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/documentation_improvement.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/ci.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..3418ebf --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +# Flask runtime +FLASK_ENV=development +PORT=5000 + +# Use a strong random value in real deployments +SECRET_KEY=change-this-in-production + +# Optional overrides +DATABASE_PATH=chat_app.db +SOCKETIO_CORS_ALLOWED_ORIGINS=* diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..9a604e1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,33 @@ +--- +name: Bug report +about: Report a reproducible problem in ChatPulse +title: "[Bug]: " +labels: [bug, needs-triage] +assignees: [] +--- + +## Description +A clear and concise description of the bug. + +## Steps to reproduce +1. +2. +3. + +## Expected behavior +What should happen instead? + +## Actual behavior +What happened? + +## Environment +- OS: +- Python version: +- Browser (if UI-related): +- Deployment mode (local/Docker/Render): + +## Logs / screenshots +Add relevant logs, tracebacks, or screenshots. + +## Additional context +Anything else that helps reproduce or diagnose the issue. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..90f57c7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Security vulnerability report + url: https://github.com/Harshall25 + about: Please report sensitive security issues privately to the maintainer. diff --git a/.github/ISSUE_TEMPLATE/documentation_improvement.md b/.github/ISSUE_TEMPLATE/documentation_improvement.md new file mode 100644 index 0000000..e06860b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation_improvement.md @@ -0,0 +1,22 @@ +--- +name: Documentation improvement +about: Suggest fixes or additions to docs +title: "[Docs]: " +labels: [documentation, needs-triage] +assignees: [] +--- + +## Documentation area +Which file/section needs updates? + +## Current gap +What is unclear, incorrect, or missing? + +## Proposed improvement +What should be added or changed? + +## Why this matters +How this helps users or contributors. + +## References +Related issues/PRs/links. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..c3ec044 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,26 @@ +--- +name: Feature request +about: Suggest an improvement for ChatPulse +title: "[Feature]: " +labels: [enhancement, needs-triage] +assignees: [] +--- + +## Summary +Describe the feature idea. + +## Problem statement +What user/developer problem does this solve? + +## Proposed solution +Describe your preferred solution. + +## Alternatives considered +List any alternatives you've considered. + +## Acceptance criteria +- [ ] +- [ ] + +## Additional context +Links, examples, mockups, or related issues. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..229c0e3 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,21 @@ +## Linked issue(s) +- Closes # + +## Summary of changes +- + +## Implementation notes +- + +## Testing evidence +Commands run and outcomes: +- [ ] `python -m unittest discover -v` +- [ ] `python -m compileall application.py database.py helpers.py` +- [ ] Not applicable (explain why) + +## Checklist +- [ ] I read `CONTRIBUTING.md` +- [ ] I kept changes focused and minimal +- [ ] I added/updated tests where appropriate +- [ ] I updated documentation where appropriate +- [ ] I did not commit secrets or private data diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..58a365d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.11"] + + env: + FLASK_ENV: production + SECRET_KEY: test-secret-key + DATABASE_PATH: /tmp/chatpulse-test.db + PYTHONUNBUFFERED: "1" + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run unit tests + run: python -m unittest discover -v + + - name: Run syntax check + run: python -m compileall application.py database.py helpers.py diff --git a/.gitignore b/.gitignore index bdae662..386dd54 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,6 @@ Thumbs.db *.log # Database (optional - you might want to keep chat_app.db for initial data) -# chat_app.db \ No newline at end of file +# chat_app.db +*.db +data/ \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..bbeb0b8 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,127 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, +and learning from the experience +- Focusing on what is best not just for us as individuals, but for the +overall community + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery, and sexual attention or +advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email +address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a +professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the project maintainer by contacting @Harshall25 via GitHub: +https://github.com/Harshall25 + +When reporting, include links, screenshots, and any context needed to +investigate. Reports will be reviewed and investigated promptly and fairly. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..991d754 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,94 @@ +# Contributing to ChatPulse + +Thanks for your interest in contributing to ChatPulse. + +## Project overview +ChatPulse is a real-time team chat app built with Flask, Flask-SocketIO, SQLite, HTML, CSS, and JavaScript. + +## Prerequisites +- Python 3.9+ +- pip +- virtual environment tooling (`python -m venv`) +- Git +- Docker (optional, for containerized runs) + +## Local development setup (fresh clone) +```bash +git clone https://github.com/Harshall25/ChatPulse.git +cd ChatPulse +python -m venv .venv +source .venv/bin/activate # Windows (PowerShell): .venv\\Scripts\\Activate.ps1 +pip install --upgrade pip +pip install -r requirements.txt +``` + +## Environment variables and secrets +Create a local environment file (do not commit it): + +```bash +cp .env.example .env +``` + +Supported variables: +- `SECRET_KEY` (required for production; recommended for local development) +- `FLASK_ENV` (`development` or `production`) +- `PORT` (default `5000`) +- `DATABASE_PATH` (default `chat_app.db`) +- `SOCKETIO_CORS_ALLOWED_ORIGINS` (default `*`) + +### Security requirement +Never commit API keys, passwords, private tokens, real-user database files, `.env` files, or any other secrets. + +## Database initialization and migrations +- The app initializes SQLite tables automatically at startup via `database.init_database()`. +- There is no migration framework yet; schema changes should be proposed in PRs with clear upgrade notes. + +## Run the application +```bash +python application.py +``` +Then open `http://127.0.0.1:5000`. + +## Run tests and checks +Current automated checks in this repository: + +```bash +python -m unittest discover -v +python -m compileall application.py database.py helpers.py +``` + +## Branch naming convention +Use short, descriptive branches, for example: +- `feat/room-search-a11y` +- `fix/session-secret-config` +- `docs/contributing-guide` + +## Commit message convention +Use conventional-style prefixes when possible: +- `feat: add input validation for room names` +- `fix: prevent empty chat messages` +- `docs: expand deployment prerequisites` +- `test: add regression test for room deletion` + +## Pull request workflow +1. Fork and create a branch from `main`. +2. Make focused changes. +3. Run checks/tests locally. +4. Open a PR using the repository PR template. +5. Link related issues (for example, `Closes #123`). +6. Respond to review feedback and keep the branch up to date. + +## Review expectations +- Keep PRs scoped and readable. +- Include test evidence (command output or explanation when no tests exist). +- Update docs when behavior or setup changes. + +## Coding style and testing +- Follow existing Python and frontend style patterns in this repository. +- Prefer small, isolated changes. +- Add or update tests when touching logic-heavy code. +- Avoid breaking existing chat, auth, and room flows. + +## Reporting bugs and security issues +- For general bugs, open a GitHub issue using the bug-report template. +- For sensitive security concerns, avoid posting secrets publicly; contact the maintainer privately first via GitHub profile: https://github.com/Harshall25 diff --git a/README.md b/README.md index f5f54f0..0ae2cfe 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,85 @@ # ChatPulse -a simple-chat-app -ChatPulse | a chat app made for teams using socketio and flask -image +ChatPulse is a real-time team chat application built with Flask and Socket.IO. It supports lightweight authentication, chat rooms, room search, and file sharing. +## Features +- Real-time messaging with Socket.IO +- Username/password sign-in flow +- Room creation and room search +- File and image sharing in rooms +- SQLite-backed message persistence +- Docker and Render deployment support -## installation +## Tech stack +- **Backend:** Python, Flask, Flask-SocketIO, SQLite +- **Frontend:** HTML, CSS, JavaScript +- **Runtime/Deploy:** Gunicorn, Docker, Render, Procfile -install virtualenv +## Screenshots +Current screenshot: -### 1 create environment - - virtualenv [name] - -### 2 activate - - source [name]/bin/activate - -### 3 install dependencies +ChatPulse screenshot - pip install -r requirements.txt - -## Run +You can add more screenshots later under this section as the UI evolves. - flask run +## Installation and local setup +```bash +git clone https://github.com/Harshall25/ChatPulse.git +cd ChatPulse +python -m venv .venv +source .venv/bin/activate # Windows (PowerShell): .venv\\Scripts\\Activate.ps1 +pip install --upgrade pip +pip install -r requirements.txt +cp .env.example .env +``` + +## Environment configuration +Set these values in `.env` or your shell: +- `SECRET_KEY` (required in production) +- `FLASK_ENV` (`development` or `production`) +- `PORT` (default `5000`) +- `DATABASE_PATH` (default `chat_app.db`) +- `SOCKETIO_CORS_ALLOWED_ORIGINS` (default `*`) + +> Never commit `.env` files, API keys, passwords, or real-user data. + +## Run the app +```bash +python application.py +``` +Open `http://127.0.0.1:5000`. + +## Run tests/checks +```bash +python -m unittest discover -v +python -m compileall application.py database.py helpers.py +``` ## Docker +Build and run locally: +```bash +docker build -t chatpulse . +docker run --rm -p 5000:5000 --env-file .env chatpulse +``` + +Or use Compose: +```bash +docker compose up --build +``` + +## Deployment +See [`DEPLOYMENT.md`](./DEPLOYMENT.md) and [`render.yaml`](./render.yaml) for Render deployment guidance. + +## Contributing +Please read [CONTRIBUTING.md](./CONTRIBUTING.md) before opening issues or pull requests. -To run with Docker: +- Open issues: https://github.com/Harshall25/ChatPulse/issues +- New issue: https://github.com/Harshall25/ChatPulse/issues/new/choose -1. Pull the image: - ``` - docker pull harshal825/flask-chat-app - ``` +## Code of Conduct +Contributors are expected to follow [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md). -2. Run the container: - ``` - docker run -p 5000:5000 harshal825/flask-chat-app - ``` +## License +No license file is currently present in this repository. -Access the app at http://localhost:5000 - +Without an explicit license, others generally cannot legally reuse, modify, or distribute this code beyond rights granted by the platform terms. Choose and add a license before accepting broad external contributions. diff --git a/application.py b/application.py index 10f14c2..66c017e 100644 --- a/application.py +++ b/application.py @@ -1,9 +1,4 @@ import os -import requests - -import datetime - -from collections import deque from flask import Flask, jsonify, session , render_template, request , redirect , flash from flask_socketio import SocketIO, emit , leave_room , join_room @@ -15,12 +10,20 @@ app = Flask(__name__) app.config['SESSION_TYPE'] = 'filesystem' -app.config["SECRET_KEY"] = "my secret key" +app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "dev-only-secret-key") +app.config["SESSION_COOKIE_HTTPONLY"] = True +app.config["SESSION_COOKIE_SAMESITE"] = "Lax" +app.config["SESSION_COOKIE_SECURE"] = os.environ.get("FLASK_ENV") == "production" +app.config["MAX_CONTENT_LENGTH"] = 10 * 1024 * 1024 # Initialize Flask-Session Session(app) -socketio = SocketIO(app, cors_allowed_origins="*", async_mode='threading') +socketio = SocketIO( + app, + cors_allowed_origins=os.environ.get("SOCKETIO_CORS_ALLOWED_ORIGINS", "*"), + async_mode='threading' +) # Initialize database on startup database.init_database() diff --git a/database.py b/database.py index 3e19701..b81a1d9 100644 --- a/database.py +++ b/database.py @@ -3,7 +3,7 @@ from datetime import datetime import os -DATABASE_PATH = 'chat_app.db' +DATABASE_PATH = os.environ.get("DATABASE_PATH", "chat_app.db") def get_db_connection(): """Get database connection with row factory for dict-like access""" From 3b9f654ca070f2bdf8814d061fd49be457bee19b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Oct 2026 17:13:15 +0000 Subject: [PATCH 2/3] Align test commands with reliable unittest discovery runner Co-authored-by: Harshall25 <191145090+Harshall25@users.noreply.github.com> --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/workflows/ci.yml | 9 ++++++++- CONTRIBUTING.md | 8 +++++++- README.md | 8 +++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 229c0e3..7c79def 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,7 +9,7 @@ ## Testing evidence Commands run and outcomes: -- [ ] `python -m unittest discover -v` +- [ ] `python - <<'PY'` (unittest discovery snippet from CONTRIBUTING.md) - [ ] `python -m compileall application.py database.py helpers.py` - [ ] Not applicable (explain why) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58a365d..5729b2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,14 @@ jobs: pip install -r requirements.txt - name: Run unit tests - run: python -m unittest discover -v + run: | + python - <<'PY' + import unittest + suite = unittest.defaultTestLoader.discover('.') + print(f"Discovered {suite.countTestCases()} test(s)") + result = unittest.TextTestRunner(verbosity=2).run(suite) + raise SystemExit(0 if result.wasSuccessful() else 1) + PY - name: Run syntax check run: python -m compileall application.py database.py helpers.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 991d754..e0bd047 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,7 +53,13 @@ Then open `http://127.0.0.1:5000`. Current automated checks in this repository: ```bash -python -m unittest discover -v +python - <<'PY' +import unittest +suite = unittest.defaultTestLoader.discover('.') +print(f"Discovered {suite.countTestCases()} test(s)") +result = unittest.TextTestRunner(verbosity=2).run(suite) +raise SystemExit(0 if result.wasSuccessful() else 1) +PY python -m compileall application.py database.py helpers.py ``` diff --git a/README.md b/README.md index 0ae2cfe..dc8459a 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,13 @@ Open `http://127.0.0.1:5000`. ## Run tests/checks ```bash -python -m unittest discover -v +python - <<'PY' +import unittest +suite = unittest.defaultTestLoader.discover('.') +print(f"Discovered {suite.countTestCases()} test(s)") +result = unittest.TextTestRunner(verbosity=2).run(suite) +raise SystemExit(0 if result.wasSuccessful() else 1) +PY python -m compileall application.py database.py helpers.py ``` From 5aed6703c8db2e40d1460ab0c8206ff22cadceae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Oct 2026 17:15:30 +0000 Subject: [PATCH 3/3] Escape template variables safely in chat page script Co-authored-by: Harshall25 <191145090+Harshall25@users.noreply.github.com> --- templates/chat.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/chat.html b/templates/chat.html index 0bbec09..9cab16f 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -318,7 +318,7 @@ {%endblock%} \ No newline at end of file