A FastAPI-based service for analyzing code patterns and detecting suspicious coding behaviors across multiple programming languages.
- Multi-language Support: Analyzes Python, Java, C++, and JavaScript code
- Behavioral Analysis: Detects copy, paste, keystroke, and tab patterns
- MongoDB Integration: Stores analysis results and responses
- Comprehensive Logging: Detailed logging for debugging and monitoring
- RESTful API: Clean API endpoints for integration
Execute code analysis scripts for different programming languages and behaviors.
Request Body:
{
"script_name": "cpp.py",
"object_id": "67f559c9dfb01510b8393ffd"
}
Supported Scripts:
paste.py
- Paste behavior analysiscopymain.py
- Copy behavior analysiskeymain.py
- Keystroke analysistab.py
- Tab usage analysiscpp.py
- C++ code analysispy.py
- Python code analysisjava.py
- Java code analysisjavascript.py
- JavaScript code analysis
Response:
{
"suspiciousness_percentage": 33.5,
"reasons": [
"Inconsistent spacing around operators found in ~100.0% of relevant lines.",
"Lack of TODO/FIXME markers, often present in human development cycles."
],
"factor_scores": {
"comment_density": {
"score": 0.8,
"details": "0.00 (0/1)"
}
}
}
-
Clone the repository
git clone <repository-url> cd py-api
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp env.example .env # Edit .env with your configuration
-
Run the application
uvicorn main:app --reload --host 0.0.0.0 --port 8000
-
Access the API
- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
-
Build and run with Docker Compose
docker-compose up --build
-
Or build and run manually
docker build -t syntax-sentry-api . docker run -p 8000:8000 syntax-sentry-api
-
Connect your GitHub repository to Render
-
Create a new Web Service
-
Configure the service:
- Build Command:
pip install -r requirements.txt
- Start Command:
uvicorn main:app --host 0.0.0.0 --port $PORT
- Environment:
Python 3
- Plan:
Free
orStarter
- Build Command:
-
Set environment variables in Render dashboard:
MONGODB_URL
: Your MongoDB connection stringMONGODB_DATABASE
: Database nameLOG_LEVEL
: INFOENVIRONMENT
: production
-
Deploy: Render will automatically deploy from your
render.yaml
configuration
-
Install Heroku CLI
-
Login and create app
heroku login heroku create your-app-name
-
Set environment variables
heroku config:set MONGODB_URL="your-mongodb-url" heroku config:set MONGODB_DATABASE="test" heroku config:set LOG_LEVEL="INFO" heroku config:set ENVIRONMENT="production"
-
Deploy
git push heroku main
-
Install Vercel CLI
npm i -g vercel
-
Deploy
vercel --prod
-
Set environment variables in Vercel dashboard
- Connect GitHub repository to Railway
- Configure environment variables
- Deploy automatically
- Create new app from GitHub
- Configure build settings:
- Build Command:
pip install -r requirements.txt
- Run Command:
uvicorn main:app --host 0.0.0.0 --port $PORT
- Build Command:
- Set environment variables
- Deploy
Variable | Description | Default | Required |
---|---|---|---|
MONGODB_URL |
MongoDB connection string | - | Yes |
MONGODB_DATABASE |
Database name | test |
No |
API_HOST |
API host | 0.0.0.0 |
No |
API_PORT |
API port | 8000 |
No |
LOG_LEVEL |
Logging level | INFO |
No |
LOG_DIRECTORY |
Log directory | logs |
No |
SECRET_KEY |
Secret key for security | - | Yes (production) |
ENVIRONMENT |
Environment type | development |
No |
py-api/
├── main.py # FastAPI application
├── requirements.txt # Python dependencies
├── checkcodetype.py # Language detection utilities
├── *.py # Analysis scripts for different languages
├── schema/ # JSON schema definitions
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
├── render.yaml # Render deployment config
├── vercel.json # Vercel deployment config
├── Procfile # Heroku deployment config
├── env.example # Environment variables template
└── README.md # This file
- FastAPI: Modern web framework for building APIs
- Uvicorn: ASGI server for running FastAPI
- PyMongo: MongoDB driver for Python
- Radon: Code complexity analysis
- PyCodeStyle: Python style checker
- Logs are stored in the
logs/
directory - Daily log rotation with timestamp-based filenames
- Console and file logging enabled
- Health check endpoint available at
/health
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For support and questions, please open an issue in the repository.