diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,5 @@
+# tdlib
+
+## 0.1.0
+
+Initial release
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,11 @@
+Copyright Poscat (c) 2020
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,9 @@
+# tdlib
+
+Low level Haskell bindings to the TDLib JSON interface.
+
+## Building
+
+1. build TDLib following these [instructions](https://github.com/tdlib/td#readme)
+2. run `cabal configure --extra-lib-dirs=<PATH_TO_TDLIB>` if TDLib was installed at non-standard locations
+3. run `cabal build`
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,3 @@
+import Distribution.Simple
+
+main = defaultMain
diff --git a/src/TDLib/TDJson.hs b/src/TDLib/TDJson.hs
new file mode 100644
--- /dev/null
+++ b/src/TDLib/TDJson.hs
@@ -0,0 +1,173 @@
+{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+
+-- | Bindings to TDLib Json interface
+module TDLib.TDJson
+  ( Verbosity (..),
+    Client,
+
+    -- * Creating, Destroying and Interacting with clients
+    newClient,
+    destroyClient,
+    clientReceive,
+    clientSend,
+    clientExecute,
+
+    -- * Managing the internal logging of TDLib
+    setLogFilePath,
+    setLogMaxFileSize,
+    setLogVerbosityLevel,
+    setLogFatalErrorCallback,
+  )
+where
+
+import Data.ByteString
+  ( ByteString,
+    packCString,
+    useAsCString,
+  )
+import Data.Int
+import Foreign.C
+import Foreign.ForeignPtr
+import Foreign.Ptr
+
+-- | TDLib client, will be automacially destroyed as soon as there are no references pointing to it (backed by 'ForeignPtr')
+newtype Client = Client (ForeignPtr ())
+  deriving newtype (Eq, Ord, Show)
+
+type ClientPtr = Ptr ()
+
+-- | Logging verbosity
+data Verbosity
+  = Fatal
+  | Error
+  | Warning
+  | Info
+  | Debug
+  | Verbose
+  deriving (Show, Eq, Enum)
+
+foreign import ccall "td_json_client_create"
+  tdJsonClientCreate :: IO ClientPtr
+
+foreign import ccall "td_json_client_send"
+  tdJsonClientSend :: ClientPtr -> CString -> IO ()
+
+foreign import ccall "td_json_client_receive"
+  tdJsonClientReceive :: ClientPtr -> CDouble -> IO CString
+
+foreign import ccall "Td_json_client_execute"
+  tdJsonClientExecute :: ClientPtr -> CString -> IO ()
+
+foreign import ccall "td_json_client_destroy"
+  tdJsonClientDestroy :: ClientPtr -> IO ()
+
+foreign import ccall "&td_json_client_destroy"
+  p_clientDestory :: FunPtr (ClientPtr -> IO ())
+
+foreign import ccall "td_set_log_file_path"
+  tdSetLogFilePath :: CString -> IO CInt
+
+foreign import ccall "td_set_log_max_file_size"
+  tdSetLogMaxFileSize :: CLLong -> IO ()
+
+foreign import ccall "td_set_log_verbosity_level"
+  tdSetLogVerbosityLevel :: CInt -> IO ()
+
+type CallbackPtr = FunPtr (CString -> IO ())
+
+foreign import ccall "td_set_log_fatal_error_callback"
+  tdSetLogFatalErrorCallback :: CallbackPtr -> IO ()
+
+foreign import ccall "wrapper"
+  mkCallbackPtr_ :: (CString -> IO ()) -> IO CallbackPtr
+
+mkCallbackPtr :: (ByteString -> IO ()) -> IO CallbackPtr
+mkCallbackPtr cont =
+  mkCallbackPtr_ cont'
+  where
+    cont' cs = do
+      bs <- packCString cs
+      cont bs
+
+-- | Creates a new instance of TDLib.
+newClient :: IO Client
+newClient = do
+  cptr <- tdJsonClientCreate
+  fptr <- newForeignPtr p_clientDestory cptr
+  pure $ Client fptr
+
+-- | Sends request to the TDLib client. May be called from any thread.
+clientSend ::
+  -- | The client.
+  Client ->
+  -- | JSON-serialized null-terminated request to TDLib.
+  ByteString ->
+  IO ()
+clientSend (Client fptr) msg =
+  useAsCString msg $ \cstr ->
+    withForeignPtr fptr $ \ptr -> do
+      tdJsonClientSend ptr cstr
+
+-- | Receives incoming updates and request responses from the TDLib client. May be called from any thread, but shouldn't be called simultaneously from two different threads. Returned pointer will be deallocated by TDLib during next call to 'clientReceive' or 'clientExecute' in the same thread, so it can't be used after that.
+clientReceive ::
+  -- | The client.
+  Client ->
+  -- | The maximum number of seconds allowed for this function to wait for new data.
+  Double ->
+  -- | JSON-serialized null-terminated incoming update or request response. May be NULL if the timeout expires.
+  IO ByteString
+clientReceive (Client fptr) t =
+  withForeignPtr fptr $ \ptr -> do
+    cs <- tdJsonClientReceive ptr (CDouble t)
+    packCString cs
+
+-- | Synchronously executes TDLib request. May be called from any thread. Only a few requests can be executed synchronously. Returned pointer will be deallocated by TDLib during next call to 'clientReceive' or 'clientExecute' in the same thread, so it can't be used after that.
+clientExecute ::
+  -- | The client. Currently ignored for all requests, so NULL can be passed.
+  Client ->
+  -- | JSON-serialized null-terminated request to TDLib.
+  ByteString ->
+  IO ()
+clientExecute (Client fptr) cmd =
+  useAsCString cmd $ \cstr ->
+    withForeignPtr fptr $ \ptr -> do
+      tdJsonClientExecute ptr cstr
+
+-- | Destroys the TDLib client instance. After this is called the client instance shouldn't be used anymore.
+destroyClient ::
+  -- | The client.
+  Client ->
+  IO ()
+destroyClient (Client fptr) = finalizeForeignPtr fptr
+
+-- | Sets the path to the file where the internal TDLib log will be written. By default TDLib writes logs to stderr or an OS specific log. Use this method to write the log to a file instead.
+setLogFilePath ::
+  -- | Null-terminated path to a file where the internal TDLib log will be written. Use an empty path to switch back to the default logging behaviour.
+  ByteString ->
+  -- | True on success, False otherwise.
+  IO Bool
+setLogFilePath fp =
+  useAsCString fp $ \cstr -> do
+    i <- tdSetLogFilePath cstr
+    if  | i == 1 -> pure True
+        | i == 0 -> pure False
+        | otherwise -> error $ "Unknown return code" <> show i
+
+-- | Sets the maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated. Unused if log is not written to a file. Defaults to 10 MB.
+setLogMaxFileSize ::
+  -- | The maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated. Should be positive.
+  Int64 ->
+  IO ()
+setLogMaxFileSize = tdSetLogMaxFileSize . CLLong
+
+-- | Sets the verbosity level of the internal logging of TDLib. By default the TDLib uses a log verbosity level of 'Verbose'.
+setLogVerbosityLevel :: Verbosity -> IO ()
+setLogVerbosityLevel = tdSetLogVerbosityLevel . toEnum . fromEnum
+
+-- | Sets the callback that will be called when a fatal error happens. None of the TDLib methods can be called from the callback. The TDLib will crash as soon as callback returns. By default the callback is not set.
+setLogFatalErrorCallback :: (ByteString -> IO ()) -> IO ()
+setLogFatalErrorCallback cont = do
+  cbptr <- mkCallbackPtr cont
+  tdSetLogFatalErrorCallback cbptr
diff --git a/tdlib.cabal b/tdlib.cabal
new file mode 100644
--- /dev/null
+++ b/tdlib.cabal
@@ -0,0 +1,60 @@
+cabal-version: 1.12
+
+-- This file has been generated from package.yaml by hpack version 0.33.0.
+--
+-- see: https://github.com/sol/hpack
+--
+-- hash: e454a6441e012c7cdf400ccf952fa4abd1464529b5cde885c6b80d7d0fde91b9
+
+name:           tdlib
+version:        0.1.0
+synopsis:       Bidings to the tdlib json interface
+description:    Please see the README on GitHub at <https://github.com/poscat0x04/tdlib#readme>
+category:       FFI
+homepage:       https://github.com/poscat0x04/tdlib#readme
+bug-reports:    https://github.com/poscat0x04/tdlib/issues
+author:         Poscat
+maintainer:     poscat@mail.poscat.moe
+copyright:      (c) 2020 Poscat
+license:        BSD3
+license-file:   LICENSE
+build-type:     Simple
+extra-source-files:
+    README.md
+    CHANGELOG.md
+
+source-repository head
+  type: git
+  location: https://github.com/poscat0x04/tdlib
+
+library
+  exposed-modules:
+      TDLib.TDJson
+  other-modules:
+      Paths_tdlib
+  hs-source-dirs:
+      src
+  default-extensions: OverloadedStrings FlexibleInstances FlexibleContexts FunctionalDependencies InstanceSigs ConstraintKinds DeriveGeneric DeriveFunctor DeriveFoldable DeriveTraversable TypeOperators TypeApplications TypeFamilies KindSignatures PartialTypeSignatures DataKinds StarIsType ScopedTypeVariables ExplicitForAll ViewPatterns BangPatterns LambdaCase TupleSections EmptyCase MultiWayIf UnicodeSyntax PatternSynonyms RecordWildCards
+  extra-libraries:
+      tdjson
+  build-depends:
+      base >=4.10 && <5
+    , bytestring >=0.10.10.0 && <0.11
+  default-language: Haskell2010
+
+test-suite tdlib-test
+  type: exitcode-stdio-1.0
+  main-is: Spec.hs
+  other-modules:
+      Paths_tdlib
+  hs-source-dirs:
+      test
+  default-extensions: OverloadedStrings FlexibleInstances FlexibleContexts FunctionalDependencies InstanceSigs ConstraintKinds DeriveGeneric DeriveFunctor DeriveFoldable DeriveTraversable TypeOperators TypeApplications TypeFamilies KindSignatures PartialTypeSignatures DataKinds StarIsType ScopedTypeVariables ExplicitForAll ViewPatterns BangPatterns LambdaCase TupleSections EmptyCase MultiWayIf UnicodeSyntax PatternSynonyms RecordWildCards
+  ghc-options: -threaded -rtsopts -with-rtsopts=-N
+  extra-libraries:
+      tdjson
+  build-depends:
+      base >=4.10 && <5
+    , bytestring >=0.10.10.0 && <0.11
+    , tdlib
+  default-language: Haskell2010
diff --git a/test/Spec.hs b/test/Spec.hs
new file mode 100644
--- /dev/null
+++ b/test/Spec.hs
@@ -0,0 +1,3 @@
+module Main where
+
+main = pure ()
