[Project] Tobid

부산 투어 서비스 백엔드 개발

Stack

  • FastAPI

    • 해커톤이라는 생산성과 속도가 중요한 상황을 고려하여, Python 기반의 프레임워크를 선택했다.

    • Python 기반에도 다양한 후보들이 있었지만, 익숙하고 이름 그대로 정말 빠르게 개발할 수 있는 FastAPI를 선택했다.

  • MySQL

    • 관계형 데이터 저장 및 관리를 위해서는 MySQL를 선택했다.

    • 마찬가지로 현업에서 많이 사용하고, 익숙한 엔진을 사용하였다.

  • Docker

    • 프론트 분들이 로컬에서 빠르게 실행시킬 수 있도록 Back-end server, DB를 컨테이너화 하여 docker-compose.yml 파일로 작성하였다.

    • 배포를 안 한 상황에서 개발 환경을 동일하게 실행하려는 목적도 있었다.

Dev

구상

  • 간단한 API 6개 만드는 작업이었다.

  • 피그마를 참고하여 노션으로 명세를 해보니 대략적으로 초안은 저렇게 나왔었다.

  • DB schema를 빠르게 짜보았다. 개발을 하면서 수정도 많이 되었다. (dbdiagram.io)

  • API test는 Postman으로 하고, 명세는 Notion으로 작성하였다.

  • 자동으로 문서화도 해준다. (빠르게 짜느라 RESTful 하지는 않다.)

Docker-compose.yml & Dockerfile

Dockerfile
FROM python:3.9-slim

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONBUFFERED 1

COPY ./requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt


COPY ./ ./

docker-compose.yml
version: '3.8'
services:
  api-server:
    build:
      context: .
      dockerfile: ./Dockerfile
    restart: always
    ports:
      - 8000:8000
    depends_on:
      - mysql
    env_file:
      - .env
    volumes:
      - ./:/app
    command: python -m uvicorn main:app --host 0.0.0.0 --port 8000
    networks:
      - tobid
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:3306" ]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s

  mysql:
    image: mysql:8.0
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    env_file:
      - .env
    ports:
      - 3306:3306
    volumes:
      - ./mysql_db:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    healthcheck:
      test: [ "CMD-SHELL", "mysqladmin ping -h localhost --silent" ]
      interval: 10s
      timeout: 5s
      retries: 3
    networks:
      - tobid

volumes:
  mysql_db:


networks:
  tobid:

📦 Docker builds and run

docker-compose up --build -d

Directory Structure

  • 급하게 짜서 네이밍도 구조도 엉망이었다 ㅋㅎㅋㅎ

.
├── Dockerfile
├── README.md
├── config
   └── database.py
├── docker-compose.yml
├── init.sql
├── main.py
├── models
   ├── attractions_model.py
   ├── courseAttraction_model.py
   ├── courseCosts_model.py
   ├── courses_mondel.py
   └── users_model.py
├── myenv
├── mysql_db
├── requirements.txt
├── routers
   └── attractions_routers.py
├── schemas
   └── courses_schemas.py
└── services
    ├── attractions_services.py
    └── courses_services.py

Last updated