design database and refactor the whole framework