Skip to content

Slightly-Techie/crm-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

566 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CRM API

Status GitHub issues GitHub pull requests License


Backend API for Slightly Techie CRM

πŸ“ Table of Contents

About

The Slightly Techie CRM API is a comprehensive backend service for managing customer relationships, user profiles, projects, skills, announcements, and more. It provides RESTful endpoints for all CRM operations. and includes features like:

Built with FastAPI for high performance and automatic API documentation.

Automatic Initialization on Startup

When the application starts, it automatically initializes essential seed data:

Roles

  • Admin
  • User
  • Guest

Stacks (Technical Specializations)

  • Backend
  • Frontend
  • Fullstack
  • Mobile
  • UI/UX
  • DevOps
  • Data Science

Signup Endpoint

  • Created automatically for user registration tracking

This ensures the application is ready to use without manual database setup for these core entities.

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • Poetry: Dependency manager for Python.
  • Postgres: A relational database.
  • Python 3.10^: The Python programming language.
  • AutoPEP8: An auto-formatter for Python code.

Setting up a development environment

Step 1: Clone the repository

https://github.com/Slightly-Techie/crm-api.git

or with GithubCLI

gh repo clone Slightly-Techie/crm-api

step 2: Install poetry if you don't have it already

# Linux, macOS, Windows (WSL)
curl -sSL https://install.python-poetry.org | python3 -
# Windows (PowerShell)
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

Note: If you have installed Python through the Microsoft Store, replace py with python in the command above.

Reference: Poetry Installation

step 3: Create a virtual environment

virtualenv crmenv

OR by using the virtualenvwrapper

  mkvirtualenv crmenv

Activate the virtual environment with

  source crmenv/bin/activate

Step 4: Install dependencies

pip install -r requirements.txt

Note to add a package to the project, run

pip install <package-name>

Step 5: Create a .env file in the project's root directory and add the following environment variables, replacing the placeholders with your specific values:

# Database Configuration
POSTGRES_USER=postgres              # e.g., postgres
POSTGRES_PASSWORD=password123       # e.g., your_secure_password
POSTGRES_SERVER=localhost           # e.g., localhost or your_db_host
POSTGRES_PORT=5432                 # Default PostgreSQL port
POSTGRES_DB=st_crm_db              # e.g., st_crm_db
POSTGRES_DB_TEST=st_crm_db_test    # Test database

# Security & Authentication
SECRET=your_secret_key_here         # JWT secret key (use a strong value)
REFRESH_SECRET=your_refresh_key     # JWT refresh secret key (use a strong value)

# Server Configuration
BASE_URL=http://localhost:3000      # Frontend URL for CORS and links
URL_PATH=/users/reset-password/new-password

# Email Configuration (Gmail SMTP)
EMAIL_SENDER=someawesomeemail@gmail.com
EMAIL_PASSWORD=your_app_password    # Use Gmail app-specific password
EMAIL_SERVER=smtp.gmail.com
EMAIL_PORT=587

# Cloudinary Configuration (Media Storage)
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

Step 6: Create a test.env file in the root directory and add the following environment variables

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_SERVER=localhost
POSTGRES_PORT=5432
POSTGRES_DB=st_crm_db_test

# Optional: Add these if running tests that involve media uploads
SECRET=test_secret_key
REFRESH_SECRET=test_refresh_secret
CLOUDINARY_CLOUD_NAME=your_test_cloud_name
CLOUDINARY_API_KEY=your_test_api_key
CLOUDINARY_API_SECRET=your_test_api_secret

Step 7: Start the uvicorn server

uvicorn app:app --reload

⚠️ Important - First Time Setup: On the first startup, the application automatically initializes seed data:

  • Roles: Admin, User, Guest
  • Stacks: Backend, Frontend, Fullstack, Mobile, UI/UX, DevOps, Data Science
  • Signup Endpoint: Required for user registration

This is handled by the startup_event() in app.py which is enabled via:

app.add_event_handler("startup", startup_event)

If this event handler is commented out and you need to re-initialize the database, you can:

  • Uncomment app.add_event_handler("startup", startup_event) in app.py, OR
  • Run manually in Python:
    from db.database import create_roles, create_stacks
    create_roles()
    create_stacks()

Step 8: (Optional) Populate Test Data and Update Users

To create 20 dummy users for testing:

python create_dummy_users.py

This creates test users with credentials:

  • Email: user1@slightlytechie.com β†’ user20@slightlytechie.com
  • Password: TestPassword123! (for all)
  • Users are distributed across different stacks

Additional user management scripts (if needed):

# Update all users' status from TO_CONTACT to ACCEPTED
python update_users_status.py

# Update all users' role_id to 2 (User role)
python update_users_role.py

Step 9: Interact with the Database

To interact with the database, you can use tools like psql, pgAdmin or any database client that supports PostgreSQL. Here are some basic commands:

  • Connect to the database:
psql -U postgres -d st_crm_db
  • List all tables:
\d
  • Execute SQL queries:
SELECT * FROM table_name;

πŸ”§ Running the tests

To ensure the code is functioning correctly, you can run tests by executing the following command:

pytest

Make sure your test.env file is correctly configured with test-specific environment variables.

Running the project in Docker-Compose

  • Clone the project and from the main, create your feature branch if you are about to make changes. Else stay on the main branch
  • From the .env.sample create a .env file with the correct credentials
  • Ensure you have docker and docker compose installed on your local system
  • To build the docker image use
  docker-compose -f docker-compose.dev.yml build
  • To start the services
  doker-compose -f docker-compose.dev.yml up
  • A combination of build and start command is
  docker-compose -f docker-compose.dev.yml up --build
  • To run tests
  docker-compose -f docker-compose.dev.yml run --rm app sh -c "python -m pytest test"

βš™οΈ Project Structure

β”‚   app.py
β”‚   Dockerfile
β”‚   fly.toml
β”‚   poetry.lock
β”‚   pyproject.toml
β”‚   README.md
β”‚   test_app.py
β”‚   __init__.py
β”‚
β”œβ”€β”€β”€.github
β”‚   └───workflows
β”‚           build.yml
β”‚           fly.yml
β”‚
β”œβ”€β”€β”€Alembic
β”‚   β”‚   env.py
β”‚   β”‚   README
β”‚   β”‚   script.py.mako
β”‚
β”œβ”€β”€β”€api
β”‚   β”‚   __init__.py
β”‚   β”‚
β”‚   β”œβ”€β”€β”€api_models
β”‚   β”‚   β”‚   announcements.py
β”‚   β”‚   β”‚   skills.py
β”‚   β”‚   β”‚   stacks.py
β”‚   β”‚   β”‚   tags.py
β”‚   β”‚   β”‚   user.py
β”‚   β”‚
β”‚   β”œβ”€β”€β”€routes
β”‚   β”‚   β”‚   announcements.py
β”‚   β”‚   β”‚   auth.py
β”‚   β”‚   β”‚   feeds.py
β”‚   β”‚   β”‚   profile_page.py
β”‚   β”‚   β”‚   skills.py
β”‚   β”‚   β”‚   stacks.py
β”‚   β”‚   β”‚   tags.py
β”‚   β”‚   β”‚   techieotm.py
β”‚   β”‚   β”‚   __init__.py
β”‚
β”œβ”€β”€β”€core
β”‚   β”‚   config.py
β”‚   β”‚   exceptions.py
β”‚
β”œβ”€β”€β”€db
β”‚   β”‚   database.py
β”‚   β”‚   __init__.py
β”‚   β”œβ”€β”€β”€models
β”‚   β”‚    users.py
β”‚   └───repository
β”‚        users.py
β”œβ”€β”€β”€test
β”‚   β”‚   conftest.py
β”‚   β”‚   test_announcements.py
β”‚   β”‚   test_auth.py
β”‚   β”‚   test_feeds.py
β”‚   β”‚   test_profile_page.py
β”‚   β”‚   test_skills.py
β”‚   β”‚   test_stacks.py
β”‚   β”‚   test_tags.py
β”‚   β”‚   test_techieotm.py
β”‚   β”‚   test_users.py
β”‚   β”‚   utils_test.py
β”‚   β”‚   __init__.py
β”‚
└───utils
    β”‚   oauth2.py
    β”‚   permissions.py
    β”‚   utils.py
    β”‚   __init__.py

✏️ Contributing

We welcome contributions from the community. To contribute to the CRM API project, follow these guidelines:

Coding Standards

  • Follow the PEP 8 coding style for Python.
  • Ensure your code is well-documented with clear comments and docstrings.
  • Use meaningful variable and function names.

Branch Naming Conventions

Create a new branch for your feature or bug fix using the format below.

git checkout -b <initials/issue_no/feature> eg. # RG/121/Fixed-login-page

Pull Requests

  • Commit your changes to your branch with a clear and descriptive commit message:
git add .
git commit -m "Made this in this file"
  • Push your branch to the repository on GitHub:
git push -u origin <name-of-branch>
  • Open a pull request in the original repository, providing a detailed description of your changes and any relevant information.

please try building the project on your local machine to confirm everything works before pushing...Thanks

🎈 Usage

visit the API Documentation at https://crm-api.fly.dev/docs

⛏️ Built Using

✍️ Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages